const cache = new Cache(); cache.should.be.instanceof(Cache); cache.should.be.an('object').with.property('options'); cache.options.should.have.property('stdTTL', 0); cache.options.should.have.property('checkperiod', 600); cache.options.should.have.property('errorOnMissing', false); cache.options.should.have.property('useClones', true); cache.options.should.have.property('deleteOnExpire', true); }); const log = sinon.spy(); const cache = new Cache({log: log}); cache.should.have.deep.property('log', log); }); cache.should.have.property('cacheDir', '/tmp/cache'); cache.should.have.property('cacheDir', '/tmp/cache'); fs.existsSync('/tmp/cache').should.be.true;
it('should call `touch` method for every ref docs if `options.expiry` option is set', function() { const self = this; const opt = { expiry: 3600 }; const promise = this.model.getByIdOrFail('3e5d622e-5786-4d79-9062-b4e2b48ce541', opt); return promise.should.be.fulfilled.then(function(doc){ self.getStub.should.have.callCount(0); self.touchStub.should.have.been.calledOnce; expect(self.touchStub.args[0]).to.have.deep.property('[1]', opt.expiry); }); });
it('setParameters function', function(){ var serverVersion = '1201000000'; var serverType = 'ORACLE'; var qb = new QueryBuilder(serverType, serverVersion); qb.setParameters({ busId : 101, companyId : 1 }); expect(qb.queryParameters).to.be.an('object'); expect(qb.queryParameters).to.have.own.property('busId'); expect(qb.queryParameters).to.have.own.property('companyId'); expect(qb.queryParameters).to.have.deep.property('busId', 101); expect(qb.queryParameters).to.have.deep.property('companyId', 1); expect(Object.keys(qb.queryParameters).length).to.equal(2); });
it('from function overrides the object', function(){ var serverVersion = '1201000000'; var serverType = 'ORACLE'; var qb = new QueryBuilder(serverType, serverVersion); qb.from("HQB_TEST_BUS", "a"); qb.from("HQB_TEST_COMPANY", "a"); expect(qb.queryObject.from).to.be.an('object'); expect(qb.queryObject.from).to.have.deep.property('tableName', 'HQB_TEST_COMPANY'); expect(qb.queryObject.from).to.have.deep.property('alias', 'a'); });
describe('POST /api/tigers', function() { it('returns list of two tigers', function(done) { request(app) .post('/api/tigers') .send({ name: 'Panthera' }) .expect('content-type', /json/) .expect(200) .end(function(err, data) { expect(err).to.be.not.ok; expect(data.body).to.have.length(3); expect(data.body).to.have.deep.property('[2].name', 'Panthera'); expect(data.body).to.have.deep.property('[2].id', 3); done(); }); }); });
describe('Upload', () => { const client = new apiVideo.Client({ apiKey: 'test' }); const source = path.join(__dirname, 'data/small.webm'); const videoId = 'vix1x1x1x1x1x1x1x1x1x'; it('Does not throw', async () => { await client.videos.upload(source, {}, videoId); }); it('Sends good request', () => { client.videos.upload(source, {}, videoId).catch(() => {}); expect(client.videos.browser.lastRequest).to.deep.property('url', 'https://ws.api.video/videos/vix1x1x1x1x1x1x1x1x1x/source'); expect(client.videos.browser.lastRequest).to.deep.property('method', 'POST'); expect(client.videos.browser.lastRequest).to.deep.property('headers', {}); expect(client.videos.browser.lastRequest.formData).to.be.an('object'); }); });
describe('Upload logo', () => { const source = path.join(__dirname, 'data/test.png'); const playerId = 'plx1x1x1x1x1x1x1x1x1x'; const link = 'https://api.video'; it('Does not throw', async () => { await client.players.uploadLogo(source, playerId, link); }); it('Sends good request', () => { client.players.uploadLogo(source, playerId, link).catch(() => {}); expect(client.players.browser.lastRequest).to.deep.property('url', 'https://ws.api.video/players/plx1x1x1x1x1x1x1x1x1x/logo'); expect(client.players.browser.lastRequest).to.deep.property('method', 'POST'); expect(client.players.browser.lastRequest).to.deep.property('headers', {}); expect(client.players.browser.lastRequest.formData).to.be.an('object'); }); });
describe('Upload thumbnail', () => { it('Does not throw', async () => { const client = new apiVideo.Client({ apiKey: 'test' }); const source = path.join(__dirname, 'data/test.png'); const liveId = 'lix1x1x1x1x1x1x1x1x1x'; await client.lives.uploadThumbnail(source, liveId); }); it('Sends good request', () => { const client = new apiVideo.Client({ apiKey: 'test' }); const source = path.join(__dirname, 'data/test.png'); const liveId = 'lix1x1x1x1x1x1x1x1x1x'; client.lives.uploadThumbnail(source, liveId).catch(() => {}); expect(client.lives.browser.lastRequest).to.deep.property('url', 'https://ws.api.video/live-streams/lix1x1x1x1x1x1x1x1x1x/thumbnail'); expect(client.lives.browser.lastRequest).to.deep.property('method', 'POST'); expect(client.lives.browser.lastRequest).to.deep.property('headers', {}); expect(client.lives.browser.lastRequest.formData).to.be.an('object'); }); });
it('from function', function(){ var serverVersion = '1201000000'; var serverType = 'ORACLE'; var qb = new QueryBuilder(serverType, serverVersion); qb.from("HQB_TEST_BUS", "a"); expect(qb.queryObject.from).to.be.an('object'); expect(qb.queryObject.from).to.have.deep.property('tableName', 'HQB_TEST_BUS'); expect(qb.queryObject.from).to.have.deep.property('alias', 'a'); });
describe('Upload', () => { it('Does not throw', async () => { const client = new apiVideo.Client({ apiKey: 'test' }); const source = path.join(__dirname, 'data/en.vtt'); const properties = { videoId: 'vix1x1x1x1x1x1x1x1x1x', language: 'en', }; await client.chapters.upload(source, properties).catch(() => {}); }); it('Sends good request', () => { const client = new apiVideo.Client({ apiKey: 'test' }); const source = path.join(__dirname, 'data/en.vtt'); const properties = { videoId: 'vix1x1x1x1x1x1x1x1x1x', language: 'en', }; client.chapters.upload(source, properties).catch(() => {}); expect(client.chapters.browser.lastRequest).to.deep.property('url', 'https://ws.api.video/videos/vix1x1x1x1x1x1x1x1x1x/chapters/en'); expect(client.chapters.browser.lastRequest).to.deep.property('method', 'POST'); expect(client.chapters.browser.lastRequest).to.deep.property('headers', {}); expect(client.chapters.browser.lastRequest.formData).to.be.an('object'); }); });
it('can be serialized into json', () => { // prettier-ignore let variations = [ { object: 1 }, { object: 2 }, { object: 3 } ] let targeting = '_.geo === "US"' let experiment = Experiment.create({ id: 'foo-id', targeting, variations, name: 'test' }) let json = experiment.toJSON(experiment) expect(json).to.have.deep.property('variations', [ { object: 1, weight: 1 }, { object: 2, weight: 1 }, { object: 3, weight: 1 } ]) expect(json).to.have.deep.property('targeting', '_.geo === "US"') expect(json).to.have.property('name', 'test') expect(JSON.stringify(experiment)).to.equal(JSON.stringify(json)) })
describe('#constructor', () => { it('should create a new PSCommand', () => { const psCommand = new PSCommand(COMMAND); expect(psCommand).to.be.an.instanceof(PSCommand); expect(psCommand).to.have.deep.property('command', COMMAND); [ 'addArgument', 'addParameter', 'clone', ].forEach(method => { expect(psCommand).to.respondTo(method); }); }); it('should fail creating a new PSCommand', () => { try { new PSCommand(); } catch (error) { expect(error).to.be.an.instanceof(PS_ARG_MISS_ERROR); } try { new PSCommand({}); } catch (error) { expect(error).to.be.an.instanceof(PS_ARG_TYPE_ERROR); } }); });
it('setParameter function', function(){ var serverVersion = '1201000000'; var serverType = 'ORACLE'; var qb = new QueryBuilder(serverType, serverVersion); qb.setParameter({ busId : 101 }); expect(qb.queryParameters).to.be.an('object'); expect(qb.queryParameters).to.have.own.property('busId'); expect(qb.queryParameters).to.have.deep.property('busId', 101); expect(Object.keys(qb.queryParameters).length).to.equal(1); });
describe('Upload', () => { it('Does not throw', async () => { const client = new apiVideo.Client({ apiKey: 'test' }); const source = path.join(__dirname, 'data/en.vtt'); const properties = { videoId: 'vix1x1x1x1x1x1x1x1x1x', language: 'en', }; await client.captions.upload(source, properties); }); it('Sends good request', () => { const client = new apiVideo.Client({ apiKey: 'test' }); const source = path.join(__dirname, 'data/en.vtt'); const properties = { videoId: 'vix1x1x1x1x1x1x1x1x1x', language: 'en', }; client.captions.upload(source, properties).catch(() => {}); expect(client.captions.browser.lastRequest).to.deep.property('url', 'https://ws.api.video/videos/vix1x1x1x1x1x1x1x1x1x/captions/en'); expect(client.captions.browser.lastRequest).to.deep.property('method', 'POST'); expect(client.captions.browser.lastRequest).to.deep.property('headers', {}); expect(client.captions.browser.lastRequest.formData).to.be.an('object'); }); });
describe('Upload thumbnail', () => { const client = new apiVideo.Client({ apiKey: 'test' }); const source = path.join(__dirname, 'data/test.png'); const videoId = 'vix1x1x1x1x1x1x1x1x1x'; it('Does not throw', async () => { await client.videos.uploadThumbnail(source, videoId); }); it('Sends good request', () => { client.videos.uploadThumbnail(source, videoId).catch(() => {}); expect(client.videos.browser.lastRequest).to.deep.property('url', 'https://ws.api.video/videos/vix1x1x1x1x1x1x1x1x1x/thumbnail'); expect(client.videos.browser.lastRequest).to.deep.property('method', 'POST'); expect(client.videos.browser.lastRequest).to.deep.property('headers', {}); expect(client.videos.browser.lastRequest.formData).to.be.an('object'); }); });