From a4ad69a3824280cc5079486dd8dc5d9f9f35ea3d Mon Sep 17 00:00:00 2001 From: Izel Nakri Date: Thu, 26 Oct 2017 19:34:44 +0200 Subject: [PATCH] custom query tests added --- test/mem-server.fixtures.js | 2 ++ test/mem-server.model.js | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/test/mem-server.fixtures.js b/test/mem-server.fixtures.js index a3f0cd2..4675d76 100644 --- a/test/mem-server.fixtures.js +++ b/test/mem-server.fixtures.js @@ -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 [ { diff --git a/test/mem-server.model.js b/test/mem-server.model.js index 649d0ca..b6f4f54 100644 --- a/test/mem-server.model.js +++ b/test/mem-server.model.js @@ -16,6 +16,9 @@ describe('MemServer.Model Interface', function() { name() { return faker.name.title(); } + }, + publicPhotos() { + return this.findAll({ is_public: true }); } }); `); @@ -29,6 +32,9 @@ describe('MemServer.Model Interface', function() { return moment().toJSON(); }, is_important: true + }, + forPhoto(photo) { + return this.findAll({ photo_id: photo.id }); } }); `); @@ -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 })); + }); }); });