Skip to content

Commit

Permalink
Added initial members model and associated mirage setup
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
kevinansfield committed Jan 22, 2019
1 parent 21d811b commit 8e734d3
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/models/member.js
Original file line number Diff line number Diff line change
@@ -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')
});
6 changes: 5 additions & 1 deletion app/routes/members/index.js
Original file line number Diff line number Diff line change
@@ -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');
}
});
2 changes: 1 addition & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand Down
6 changes: 6 additions & 0 deletions mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();

Expand All @@ -47,6 +52,7 @@ export function testConfig() {
mockConfiguration(this);
mockIntegrations(this);
mockInvites(this);
mockMembers(this);
mockPosts(this);
mockRoles(this);
mockSettings(this);
Expand Down
5 changes: 5 additions & 0 deletions mirage/config/members.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {paginatedResponse} from '../utils';

export default function mockMembers(server) {
server.get('/members/', paginatedResponse('members'));
}
12 changes: 12 additions & 0 deletions mirage/factories/member.js
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions mirage/models/member.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {Model} from 'ember-cli-mirage';

export default Model.extend({
});
14 changes: 14 additions & 0 deletions tests/unit/models/member-test.js
Original file line number Diff line number Diff line change
@@ -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;
});
});

0 comments on commit 8e734d3

Please sign in to comment.