it('can be created', () => { expect( createFaceRecognizer ).to.not.throw() })
describe('session.get', () => { it('should get sessions', async () => { const session = new Session('secret'); const sessions = await session.get('0cd30aef-9c4e-4a23-88e3-3547971296e5'); expect(sessions).to.be.instanceOf(Array); sessions.forEach((oneSession) => { expect(oneSession).to.have.property('token_type'); expect(oneSession).to.have.property('scope'); expect(oneSession.scope).to.be.instanceOf(Array); expect(oneSession).not.to.have.property('token_hash'); }); }); });
describe("_createGraph", () => { it("should create a blessed-contrib line graph", () => { sandbox.spy(testContainer, "append"); options.layoutConfig.view.limit = 8; sandbox.stub(BaseLineGraph.prototype, "_createGraph"); const baseGraph = new BaseLineGraph(options); BaseLineGraph.prototype._createGraph.restore(); expect(baseGraph).to.not.have.property("node"); baseGraph._createGraph(options); expect(baseGraph).to.have.property("node").that.is.an.instanceof(contrib.line); expect(baseGraph.node).to.have.nested.property("options.label", " graph A "); expect(baseGraph.node).to.have.nested.property("options.maxY", undefined); expect(baseGraph.node).to.have.property("position") .that.deep.equals(options.layoutConfig.getPosition(options.parent)); expect(testContainer.append).to.have.been.calledOnce.and.calledWithExactly(baseGraph.node); }); });
it('predict', () => { const recognizer = createFaceRecognizer() const trainFaces = loadTrainFaces() recognizer.addFaces(trainFaces.sheldon, 'sheldon') recognizer.addFaces(trainFaces.raj, 'raj') const testFaces = loadTestFaces() function getPrediction(predictions, className) { const prediction = predictions.find(p => p.className === className) expect(prediction).to.not.be.undefined return prediction } const p1 = recognizer.predict(testFaces.sheldon) expect(p1).to.be.an('array').lengthOf(2) expect(p1.map(p => p.className)).to.contain('sheldon') expect(p1.map(p => p.className)).to.contain('raj') expect(getPrediction(p1, 'sheldon').distance).to.be.lessThan(getPrediction(p1, 'raj').distance) const p2 = recognizer.predict(testFaces.raj) expect(p2).to.be.an('array').lengthOf(2) expect(p2.map(p => p.className)).to.contain('sheldon') expect(p2.map(p => p.className)).to.contain('raj') expect(getPrediction(p2, 'raj').distance).to.be.lessThan(getPrediction(p2, 'sheldon').distance) })
describe('#parseCommand', () => { it('should return an object with run and opts keys', () => { const command = util.parseCommand('thing stuff'); command.run[0].should.equal('thing'); command.run[1].should.equal('stuff'); command.opts.cwd.should.equal(path.resolve('.')); }); it('should have collect mode on posix', () => { setPlatform('linux'); const command = util.parseCommand('thing stuff'); command.opts.mode.should.equal('collect'); resetPlatform(); }); it('should have no mode on win32', () => { setPlatform('win32'); const command = util.parseCommand('thing stuff'); command.should.not.have.property('mode'); resetPlatform(); }); });
describe('#Cli', () => { it('should return a Cli instance with correct default options', () => { const cli = new Cli(); cli.should.be.instanceof(Cli); cli.should.have.property('prefix', 'LANDO'); cli.should.have.property('logLevel', 'warn'); cli.should.have.property('userConfRoot').and.not.be.empty; }); it('should return a Cli instance with custom options', () => { const prefix = '16309'; const logLevel = 'allthelogz'; const userConfRoot = '/tmp'; const cli = new Cli(prefix, logLevel, userConfRoot); cli.should.be.instanceof(Cli); cli.should.have.property('prefix', prefix); cli.should.have.property('logLevel', logLevel); cli.should.have.property('userConfRoot', userConfRoot); }); });
describe('service', () => { const stateManager = new StateManager(); const service = new Service(services, stateManager); it('should start a service', async () => { await service.load(gladys); await service.start('example'); }); it('should return the example service', async () => { expect(service.getService('example')).to.be.instanceOf(Object).and.to.be.not.null; // eslint-disable-line }); it('should return null a service', async () => { expect(service.getService('DONOTEXIST')).to.be.null; // eslint-disable-line }); it('should return service with message capabilities', async () => { const messageServices = await service.getMessageServices(); expect(messageServices).to.be.instanceOf(Array); }); it('should return service by name', async () => { const testService = await service.getByName('test-service'); expect(testService).to.have.property('name', 'test-service'); }); it('should throw service not found', async () => { const promise = service.getByName('not-found'); return assert.isRejected(promise, 'SERVICE_NOT_FOUND'); }); });
describe("recalculatePosition", () => { it("should set new position and recreate node", () => { const baseGraph = new BaseLineGraph(options); sandbox.spy(testContainer, "remove"); sandbox.spy(testContainer, "append"); sandbox.stub(baseGraph, "_getPosition").returns({ top: "20%" }); baseGraph.recalculatePosition(); expect(baseGraph.node).to.have.property("position").that.deep.equals({ top: "20%" }); expect(testContainer.remove).to.have.been.calledOnce; expect(testContainer.append).to.have.been.calledOnce; }); it("should do nothing if position is unchanged", () => { options.layoutConfig.getPosition = function () { return { top: "10%" }; }; const baseGraph = new BaseLineGraph(options); const originalPosition = baseGraph.node.position; sandbox.spy(testContainer, "remove"); sandbox.stub(baseGraph, "_getPosition").returns({ top: "10%" }); baseGraph.recalculatePosition(); expect(baseGraph.node).to.have.property("position", originalPosition); expect(testContainer.remove).to.have.not.been.called; }); });
describe('#Metrics', () => { it('should return a Metrics instance with correct default options', () => { const metrics = new Metrics(); metrics.should.be.instanceof(Metrics); metrics.should.have.property('id', 'unknown'); metrics.endpoints.should.be.instanceof(Array); metrics.endpoints.should.be.empty; metrics.data.should.be.instanceof(Object); metrics.data.should.be.empty; metrics.log.should.be.instanceof(EventEmitter); }); it('should return a Metrics instance with user options', () => { const metrics = new Metrics({id: '24601', endpoints: [1, 2], data: {prisoner: 'valjean'}}); metrics.should.be.instanceof(Metrics); metrics.should.have.property('id', '24601'); metrics.data.prisoner.should.equal('valjean'); metrics.endpoints.should.have.length(2); metrics.endpoints.should.be.not.empty; metrics.data.should.be.not.empty; metrics.log.should.be.instanceof(EventEmitter); }); });
describe('#stripEnvs', () => { it('should return process.env stripped of all keys that start with prefix', () => { process.env.DANCE_NOW = 'everybody'; const result = config.stripEnv('DANCE'); expect(result).to.be.an('object'); expect(result).to.not.have.key('DANCE_NOW'); expect(process.env).to.not.have.key('DANCE_NOW'); }); });
describe('GET /api/v1/session', () => { it('should get api key list', async () => { await authenticatedRequest .get('/api/v1/session') .expect('Content-Type', /json/) .expect(200) .then((res) => { expect(res.body).to.be.instanceOf(Array); res.body.forEach((oneSession) => { expect(oneSession).to.have.property('token_type'); expect(oneSession).not.to.have.property('token_hash'); }); }); }); it('should return empty array', async () => { await authenticatedRequest .get('/api/v1/session?skip=10000') .expect('Content-Type', /json/) .expect(200) .then((res) => { expect(res.body).to.be.instanceOf(Array); expect(res.body).to.have.lengthOf(0); }); }); });
expect( () => fr.FaceDetector() ).to.not.throw() })
it('can be created', () => { expect( createFaceRecognizer ).to.not.throw() })