mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Added initial members model and associated mirage setup
no issue - mirage is now enabled by default in development with logging (can be turned off once we're no longer relying on mocked members endpoints)
This commit is contained in:
parent
d6d98ba5ca
commit
1680508a0a
8 changed files with 55 additions and 2 deletions
8
ghost/admin/app/models/member.js
Normal file
8
ghost/admin/app/models/member.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import DS from 'ember-data';
|
||||||
|
import attr from 'ember-data/attr';
|
||||||
|
|
||||||
|
export default DS.Model.extend({
|
||||||
|
name: attr('string'),
|
||||||
|
email: attr('string'),
|
||||||
|
createdAt: attr('moment-utc')
|
||||||
|
});
|
|
@ -1,3 +1,7 @@
|
||||||
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
||||||
|
|
||||||
export default AuthenticatedRoute.extend({});
|
export default AuthenticatedRoute.extend({
|
||||||
|
model() {
|
||||||
|
return this.store.findAll('member');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -47,7 +47,7 @@ module.exports = function (environment) {
|
||||||
|
|
||||||
// Enable mirage here in order to mock API endpoints during development
|
// Enable mirage here in order to mock API endpoints during development
|
||||||
ENV['ember-cli-mirage'] = {
|
ENV['ember-cli-mirage'] = {
|
||||||
enabled: false
|
enabled: true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import mockAuthentication from './config/authentication';
|
||||||
import mockConfiguration from './config/configuration';
|
import mockConfiguration from './config/configuration';
|
||||||
import mockIntegrations from './config/integrations';
|
import mockIntegrations from './config/integrations';
|
||||||
import mockInvites from './config/invites';
|
import mockInvites from './config/invites';
|
||||||
|
import mockMembers from './config/members';
|
||||||
import mockPosts from './config/posts';
|
import mockPosts from './config/posts';
|
||||||
import mockRoles from './config/roles';
|
import mockRoles from './config/roles';
|
||||||
import mockSettings from './config/settings';
|
import mockSettings from './config/settings';
|
||||||
|
@ -20,12 +21,16 @@ export default function () {
|
||||||
// this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server
|
// this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server
|
||||||
this.namespace = '/ghost/api/v2/admin'; // make this `api`, for example, if your API is namespaced
|
this.namespace = '/ghost/api/v2/admin'; // make this `api`, for example, if your API is namespaced
|
||||||
this.timing = 400; // delay for each request, automatically set to 0 during testing
|
this.timing = 400; // delay for each request, automatically set to 0 during testing
|
||||||
|
this.logging = true;
|
||||||
|
|
||||||
// Mock endpoints here to override real API requests during development, eg...
|
// Mock endpoints here to override real API requests during development, eg...
|
||||||
// this.put('/posts/:id/', versionMismatchResponse);
|
// this.put('/posts/:id/', versionMismatchResponse);
|
||||||
// mockTags(this);
|
// mockTags(this);
|
||||||
// this.loadFixtures('settings');
|
// this.loadFixtures('settings');
|
||||||
|
|
||||||
|
this.createList('member', 200);
|
||||||
|
mockMembers(this);
|
||||||
|
|
||||||
// keep this line, it allows all other API requests to hit the real server
|
// keep this line, it allows all other API requests to hit the real server
|
||||||
this.passthrough();
|
this.passthrough();
|
||||||
|
|
||||||
|
@ -47,6 +52,7 @@ export function testConfig() {
|
||||||
mockConfiguration(this);
|
mockConfiguration(this);
|
||||||
mockIntegrations(this);
|
mockIntegrations(this);
|
||||||
mockInvites(this);
|
mockInvites(this);
|
||||||
|
mockMembers(this);
|
||||||
mockPosts(this);
|
mockPosts(this);
|
||||||
mockRoles(this);
|
mockRoles(this);
|
||||||
mockSettings(this);
|
mockSettings(this);
|
||||||
|
|
5
ghost/admin/mirage/config/members.js
Normal file
5
ghost/admin/mirage/config/members.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import {paginatedResponse} from '../utils';
|
||||||
|
|
||||||
|
export default function mockMembers(server) {
|
||||||
|
server.get('/members/', paginatedResponse('members'));
|
||||||
|
}
|
12
ghost/admin/mirage/factories/member.js
Normal file
12
ghost/admin/mirage/factories/member.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import moment from 'moment';
|
||||||
|
import {Factory, faker} from 'ember-cli-mirage';
|
||||||
|
|
||||||
|
let randomDate = function randomDate(start = moment().subtract(30, 'days').toDate(), end = new Date()) {
|
||||||
|
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Factory.extend({
|
||||||
|
name() { return `${faker.name.firstName()} ${faker.name.lastName()}`; },
|
||||||
|
email: faker.internet.email,
|
||||||
|
createdAt() { return randomDate(); }
|
||||||
|
});
|
4
ghost/admin/mirage/models/member.js
Normal file
4
ghost/admin/mirage/models/member.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import {Model} from 'ember-cli-mirage';
|
||||||
|
|
||||||
|
export default Model.extend({
|
||||||
|
});
|
14
ghost/admin/tests/unit/models/member-test.js
Normal file
14
ghost/admin/tests/unit/models/member-test.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import {describe, it} from 'mocha';
|
||||||
|
import {expect} from 'chai';
|
||||||
|
import {setupTest} from 'ember-mocha';
|
||||||
|
|
||||||
|
describe('Unit: Model: member', function () {
|
||||||
|
setupTest();
|
||||||
|
|
||||||
|
// Replace this with your real tests.
|
||||||
|
it('exists', function () {
|
||||||
|
let store = this.owner.lookup('service:store');
|
||||||
|
let model = store.createRecord('member', {});
|
||||||
|
expect(model).to.be.ok;
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue