Skip to content

Commit

Permalink
custom query tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Oct 26, 2017
1 parent be381a4 commit a4ad69a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions test/mem-server.fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ describe('MemServer fixture constraint feature', function() {
});

it('should throw error if any of the uuid fixtures have an incorrect type', function() {
this.timeout(5000);

fs.mkdirSync(`./memserver/fixtures`);
fs.writeFileSync(`${process.cwd()}/memserver/fixtures/photos.js`, `export default [
{
Expand Down
20 changes: 17 additions & 3 deletions test/mem-server.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ describe('MemServer.Model Interface', function() {
name() {
return faker.name.title();
}
},
publicPhotos() {
return this.findAll({ is_public: true });
}
});
`);
Expand All @@ -29,6 +32,9 @@ describe('MemServer.Model Interface', function() {
return moment().toJSON();
},
is_important: true
},
forPhoto(photo) {
return this.findAll({ photo_id: photo.id });
}
});
`);
Expand Down Expand Up @@ -184,8 +190,16 @@ describe('MemServer.Model Interface', function() {
assert.equal(PhotoComment.count(), 4);
});

// TODO: it('can have custom queries for a Model', function() {
//
// });
it('can have custom queries for a Model', function() {
const MemServer = require('../index.js');
const { Photo, PhotoComment } = MemServer.Models;

MemServer.start();

const photo = Photo.find(1);

assert.deepEqual(PhotoComment.forPhoto(photo), PhotoComent.findAll({ photo_id: photo.id }));
assert.deepEqual(Photo.publicPhotos(), Photo.findAll({ is_public: true }));
});
});
});

0 comments on commit a4ad69a

Please sign in to comment.