diff --git a/app/models/member.js b/app/models/member.js new file mode 100644 index 0000000000..6ba5795b0c --- /dev/null +++ b/app/models/member.js @@ -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') +}); diff --git a/app/routes/members/index.js b/app/routes/members/index.js index 7ff4a4b892..6e46c48630 100644 --- a/app/routes/members/index.js +++ b/app/routes/members/index.js @@ -1,3 +1,7 @@ import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; -export default AuthenticatedRoute.extend({}); +export default AuthenticatedRoute.extend({ + model() { + return this.store.findAll('member'); + } +}); diff --git a/config/environment.js b/config/environment.js index f6fb855e2f..9dcdd09293 100644 --- a/config/environment.js +++ b/config/environment.js @@ -47,7 +47,7 @@ module.exports = function (environment) { // Enable mirage here in order to mock API endpoints during development ENV['ember-cli-mirage'] = { - enabled: false + enabled: true }; } diff --git a/mirage/config.js b/mirage/config.js index 5a3cd54928..9781e11806 100644 --- a/mirage/config.js +++ b/mirage/config.js @@ -3,6 +3,7 @@ import mockAuthentication from './config/authentication'; import mockConfiguration from './config/configuration'; import mockIntegrations from './config/integrations'; import mockInvites from './config/invites'; +import mockMembers from './config/members'; import mockPosts from './config/posts'; import mockRoles from './config/roles'; 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.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.logging = true; // Mock endpoints here to override real API requests during development, eg... // this.put('/posts/:id/', versionMismatchResponse); // mockTags(this); // this.loadFixtures('settings'); + this.createList('member', 200); + mockMembers(this); + // keep this line, it allows all other API requests to hit the real server this.passthrough(); @@ -47,6 +52,7 @@ export function testConfig() { mockConfiguration(this); mockIntegrations(this); mockInvites(this); + mockMembers(this); mockPosts(this); mockRoles(this); mockSettings(this); diff --git a/mirage/config/members.js b/mirage/config/members.js new file mode 100644 index 0000000000..b2e849fb90 --- /dev/null +++ b/mirage/config/members.js @@ -0,0 +1,5 @@ +import {paginatedResponse} from '../utils'; + +export default function mockMembers(server) { + server.get('/members/', paginatedResponse('members')); +} diff --git a/mirage/factories/member.js b/mirage/factories/member.js new file mode 100644 index 0000000000..2e72264972 --- /dev/null +++ b/mirage/factories/member.js @@ -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(); } +}); diff --git a/mirage/models/member.js b/mirage/models/member.js new file mode 100644 index 0000000000..6bfe517e93 --- /dev/null +++ b/mirage/models/member.js @@ -0,0 +1,4 @@ +import {Model} from 'ember-cli-mirage'; + +export default Model.extend({ +}); diff --git a/tests/unit/models/member-test.js b/tests/unit/models/member-test.js new file mode 100644 index 0000000000..4d697af0bd --- /dev/null +++ b/tests/unit/models/member-test.js @@ -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; + }); +});