it('can be trained', () => { const recognizer = createFaceRecognizer() const trainFaces = loadTrainFaces() recognizer.addFaces(trainFaces.sheldon, 'sheldon') recognizer.addFaces(trainFaces.raj, 'raj') const modelState = recognizer.getDescriptorState() expect(modelState).to.be.an('array').lengthOf(2) expect(modelState).to.deep.have.members([ { className: 'sheldon', numFaces: 2 }, { className: 'raj', numFaces: 2 } ]) })
describe('session.createApiKey', () => { it('should create an api key', async () => { const session = new Session('secret'); const res = await session.createApiKey('0cd30aef-9c4e-4a23-88e3-3547971296e5', ['dashboard:read']); expect(res).to.have.property('api_key'); expect(res).to.have.property('session_id'); expect(res.api_key).to.have.lengthOf(32); }); });
it('should get 0 rooms (take = 0)', async () => { const rooms = await room.get({ expand: ['devices'], take: 0, }); expect(rooms).to.be.instanceOf(Array); expect(rooms).to.have.lengthOf(0); });
describe('generateJwtSecret', () => { it('should generate a jwtSecret with the right length', async () => { const jwtSecret = generateJwtSecret(); expect(jwtSecret).to.have.lengthOf(500); }); });
it("Should have been imported properly", function(){ var index = new FlexSearch("match"); index.import(data); expect(index.length).to.equal(3); expect(index.search("foo")).to.have.lengthOf(2); expect(index.search("bar")).to.have.lengthOf(2); expect(index.search("foobar")).to.have.lengthOf(1); expect(index.search("foobar")[0]).to.equal(2); });
describe("Remove (Sync)", function(){ it("Should have been removed from the index", function(){ flexsearch_sync.remove(0); flexsearch_sync.remove(2); flexsearch_sync.remove(1); expect(flexsearch_sync.length).to.equal(0); expect(flexsearch_sync.search("foo")).to.have.lengthOf(0); expect(flexsearch_sync.search("bar")).to.have.lengthOf(0); expect(flexsearch_sync.search("foobar")).to.have.lengthOf(0); }); });
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('#getAll', () => { beforeEach(() => { return factory.createMany('user', 2, [ { name: 'User 1' }, { name: 'User 2' } ]); }); it('returns all users from the database', async () => { const users = await repository.getAll(); expect(users).to.have.lengthOf(2); expect(users[0]).to.be.instanceOf(User); expect(users[0].name).to.equal('User 1'); expect(users[1]).to.be.instanceOf(User); expect(users[1].name).to.equal('User 2'); }); });
// ------------------------------------------------------------------------ // Presets // ------------------------------------------------------------------------ describe("Presets", function(){ it("Should have been properly initialized", function(){ expect(FlexSearch.create("memory").length).to.equal(0); expect(FlexSearch.create("speed").length).to.equal(0); expect(FlexSearch.create("match").length).to.equal(0); expect(FlexSearch.create("score").length).to.equal(0); expect(FlexSearch.create("balance").length).to.equal(0); expect(FlexSearch.create("fast").length).to.equal(0); }); it("Should have been properly extended", function(){ var index = FlexSearch.create("fast"); index.add(0, "foobar"); expect(index.search("bar")).to.have.lengthOf(0); index = FlexSearch.create("fast", {id: "test", tokenize: "reverse"}); expect(index.id).to.equal("test"); index.add(0, "foobar"); expect(index.search("bar")).to.have.lengthOf(1); expect(index.search("bar")).to.have.members([0]) }); });
it("Should have been imported properly (documents)", function(){ var index = new FlexSearch({ encode: "icase", tokenize: "strict", threshold: 1, resolution: 3, depth: 1, doc: { id: "id", field: ["title", "content"] } }); index.import(data); if(env === ""){ expect(index.doc.index["title"].length).to.equal(3); expect(index.doc.index["content"].length).to.equal(3); } expect(index.search("foo")).to.have.lengthOf(1); expect(index.search("bar")).to.have.lengthOf(1); expect(index.search("foobar")).to.have.lengthOf(1); expect(index.search("foobar")[0].id).to.equal(1); });
it('can be trained', (done) => { const recognizer = createFaceRecognizer() const trainFaces = loadTrainFaces() Promise.all([ recognizer.addFaces(trainFaces.sheldon, 'sheldon'), recognizer.addFaces(trainFaces.raj, 'raj') ]) .then(() => { const modelState = recognizer.getDescriptorState() expect(modelState).to.be.an('array').lengthOf(2) expect(modelState).to.deep.have.members([ { className: 'sheldon', numFaces: 2 }, { className: 'raj', numFaces: 2 } ]) done() }) .catch(err => done(err)) })
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); }); }); });
it("Should have been unique results", function(){ var index = new FlexSearch({ doc: { id: "id", field: ["field1", "field2"] } }); var docs = [{ id: 1, field1: "phrase", field2: "phrase" }]; index.add(docs); expect(index.search("phrase")).to.have.lengthOf(1); expect(index.search("phrase")).to.have.members(docs); });
it('can be trained with jittering', () => { const recognizer = createFaceRecognizer() const numJitters = 1; const trainFaces = loadTrainFaces() recognizer.addFaces(trainFaces.sheldon, 'sheldon', numJitters) recognizer.addFaces(trainFaces.raj, 'raj', numJitters) const modelState = recognizer.getDescriptorState() expect(modelState).to.be.an('array').lengthOf(2) expect(modelState).to.deep.have.members([ { className: 'sheldon', numFaces: 4 }, { className: 'raj', numFaces: 4 } ]) })
it('can be trained with jittering', (done) => { const recognizer = createFaceRecognizer() const numJitters = 1; const trainFaces = loadTrainFaces() Promise.all([ recognizer.addFaces(trainFaces.sheldon, 'sheldon', numJitters), recognizer.addFaces(trainFaces.raj, 'raj', numJitters) ]) .then(() => { const modelState = recognizer.getDescriptorState() expect(modelState).to.be.an('array').lengthOf(2) expect(modelState).to.deep.have.members([ { className: 'sheldon', numFaces: 4 }, { className: 'raj', numFaces: 4 } ]) done() }) .catch(err => done(err)) })