it("Should have all provided methods", function(){ expect(flexsearch_default).to.respondTo("search"); expect(flexsearch_default).to.respondTo("add"); expect(flexsearch_default).to.respondTo("update"); expect(flexsearch_default).to.respondTo("remove"); expect(flexsearch_default).to.respondTo("clear"); expect(flexsearch_default).to.respondTo("init"); expect(flexsearch_default).to.respondTo("destroy"); expect(flexsearch_default).to.hasOwnProperty("length"); expect(flexsearch_default).to.hasOwnProperty("index"); if(env !== "light"){ expect(flexsearch_default).to.respondTo("where"); expect(flexsearch_default).to.respondTo("find"); } if(env !== "light" && env !== "min"){ expect(flexsearch_default).to.respondTo("info"); } });
describe("generate-layouts", () => { it("should validate default layout", () => { expect(generateLayouts("lib/default-layout-config.js")).to.be.an("array"); }); it("should fail on bad layouts", () => { expect(() => { generateLayouts("fake/layout-not-found"); }).to.throw(/Cannot find module/); expect(() => { mock("fake/invalid-config-layout", { invalid: "config" }); generateLayouts("fake/invalid-config-layout"); }).to.throw(/instance is not of a type\(s\) array/); }); it("should generate empty layout", () => { mock("fake/empty-layout", []); expect(generateLayouts("fake/empty-layout")).to.be.empty; }); it("should include a getPosition method", () => { const layout = generateLayouts("lib/default-layout-config.js"); const fake = { fake: "result" }; expect(layout[0]).to.respondTo("getPosition"); expect(layout[0].getPosition(fake)).to.eql(fake); }); });
describe('#findNearestCity()', () => { it('should be a method', () => { expect(geoData).to.respondTo('findNearestCity'); }); it('should return an object near Tehran coordinates', () => { expect(geoData.findNearestCity(tehran)).to.be.an('object'); }); });
it('should be able to execute jobs every after specific time interval', function (done) { expect(Queue).to.respondTo('every'); done(); });
describe('takeSnapshot()', () => { it('exists', () => { expect(agg).to.respondTo('takeSnapshot'); }); it('adds aggregate state snapshot to the changes queue', async () => { await agg.handle({ type: 'doSomething' }); agg.takeSnapshot(); const { changes } = agg; expect(changes).to.have.length(2); expect(changes[0]).to.have.property('type', 'somethingDone'); expect(changes[1]).to.have.property('type', 'snapshot'); expect(changes[1]).to.have.property('payload').that.deep.equals(agg.state); }); });
/** * Get feed */ describe('Method feed', function() { it('should be able to get feed of user logged in', function(done) { expect(posts).respondTo('feed'); var sampleRequest = { query: {}, user: user }; posts.feed(sampleRequest, { send: function(output) { expect(output.success).to.equal(1); expect(output.res.records).to.be.instanceof(Array); expect(output.res.records).to.have.length(1); //not yet following anyone, so only self posts expect(output.res.records[0]._id.toString()).to.equal(post._id.toString()); done(); } }); }); });
describe('#getCities()', () => { it('should be a method', () => { expect(geoData).to.respondTo('getCities'); }); it('should return an array', () => { const lastProvinceId = geoData.getProvinces().pop().id; const cities = geoData.getCities(lastProvinceId); expect(cities).to.be.an('array'); }); it('should return an array of objects with "id" when fields is ["id"]', () => { const firstProvinceId = geoData.getProvinces().shift().id; const cities = geoData.getCities(firstProvinceId); cities.forEach(c => expect(c).to.have.own.property('id')); }); });
describe('#findCitiesAround()', () => { it('should be a method', () => { expect(geoData).to.respondTo('findCitiesAround'); }); it('should return an non-empty array near Tehran (radius: 100Km)', () => { const aroundTehran = geoData.findCitiesAround(tehran, { radius: 100, unit: 'km' }); expect(aroundTehran).to.be.an('array').that.is.not.empty; }); });
describe('handle(command)', () => { it('exists', () => expect(agg).to.respondTo('handle'));
it('should be able to restore previous schedules', function () { expect(Queue).to.respondTo('restore'); });
describe('#getProvinces()', () => { it('should be a method', () => { expect(geoData).to.respondTo('getProvinces'); }); it('should return an array', () => { expect(geoData.getProvinces()).to.be.an('array'); }); it('should return an array of objects with `id` when fields is ["id"]', () => { geoData.getProvinces({ fields: ['id'] }) .forEach(p => expect(p).to.have.own.property('id')); }); });
describe('#findProvincesAround()', () => { it('should be a method', () => { expect(geoData).to.respondTo('findProvincesAround'); }); it('should return an non-empty array near Tehran (radius: 100Km)', () => { const aroundTehran = geoData.findProvincesAround(tehran, { radius: 100, unit: 'km' }); expect(aroundTehran).to.be.an('array').that.is.not.empty; }); });
describe('#findNearestProvince()', () => { it('should be a method', () => { expect(geoData).to.respondTo('findNearestProvince'); }); it('should return an object near Tehran coordinates', () => { expect(geoData.findNearestProvince(tehran)).to.be.an('object'); }); });
it('should be able to execute a job now', function (done) { expect(Queue).to.respondTo('now'); done(); });
it('should be able to shedule job in later time', function (done) { expect(Queue).to.respondTo('schedule'); done(); });