describe('no-op server events', function() { tests.forEach(function(test) { it(`treat "${test}" as a no-op`, function() { var stopTest = function() { 'Should not call this'.should.not.be.ok(); }; var client = new tmi.client({ logger: { trace: stopTest, debug: stopTest, info: stopTest, warn: stopTest, error: stopTest, fatal: stopTest } }); client._onMessage({data: test}); }); }); });
describe('server crashed, with reconnect: false (default)', function() { before(function() { // Initialize websocket server this.server = new WebSocketServer({port: 7000}); this.client = new tmi.client({ connection: { server: 'localhost', port: 7000 } }); }); it('gracefully handle the error', function(cb) { this.timeout(15000); var client = this.client; var server = this.server; server.on('connection', function(ws) { // Uh-oh, the server dies server.close(); }); client.on('disconnected', function() { 'Test that we reached this point'.should.be.ok(); cb(); }); client.connect().catch(catchConnectError); }); });
'Reach this callback'.should.be.ok(); expected && expected.forEach(function(data, index) { if(data === null) {
'Test that we reached this point'.should.be.ok(); cb(); }, client.reconnectTimer);
it('it should fail if ttl is missing or 0', () => { let result = runCli(['-l', 'debug', 'b1,1']); result.stderr.should.be.ok(); result.stderr.should.match(/Error: Could not parse bucket b1,1 name:b1 size:1 ttl:undefined/); result = runCli(['-l', 'debug', 'b1,1,']); result.stderr.should.be.ok(); result.stderr.should.match(/Error: Could not parse bucket b1,1, name:b1 size:1 ttl:/); result = runCli(['-l', 'debug', 'b1,1,0']); result.stderr.should.be.ok(); result.stderr.should.match(/Error: ttl must be a positive integer for bucket b1,1,0/); });
it('should set default options if not available in the config file', () => { const bucket = ['b1', 1, 2]; const confFile = getAssetPath('conf-missing-buckets.json'); const result = runCli(['--config', confFile, '-l', 'debug', bucket.join(',')]); result.stdout.should.be.ok(); result.stderr.should.not.be.ok(); const confLog = JSON.parse(result.stdout.split('\n')[1]); confLog.should.have.property('config'); confLog.should.have.property('buckets', { [bucket[0]]: {size: bucket[1], ttl: bucket[2] * 1000} }); confLog.config.should.have.property('port', 8910); });
it('$scope.info should be an object', function(){ scope.$apply(); //we mast call $scope.$apply() to resolve all promises in the controller $http is a promise should(scope.info).be.ok(); scope.info.should.be.an.Object(); scope.info.cpu.should.be.equal("a nice cpu"); scope.info.uptime.should.be.equal(123123); });
it('should move property claims from one property to another', async () => { const { id } = await createItem() const { guid, property: currentPropertyId } = await addClaim({ id, datatype: 'string', value: randomString() }) const { id: otherStringPropertyId } = await getProperty({ datatype: 'string', reserved: true }) const propertyClaimsId = `${id}#${currentPropertyId}` const res = await movePropertyClaims({ propertyClaimsId, id, property: otherStringPropertyId }) const { entity } = res[0] entity.id.should.equal(id) should(entity.claims[currentPropertyId]).not.be.ok() const movedClaim = entity.claims[otherStringPropertyId][0] movedClaim.id.should.not.equal(guid) })
it('should fail if config does not exist', () => { const confFile = getAssetPath('no-file.json'); const result = runCli(['--config', confFile, '-l', 'error']); result.stdout.should.not.be.ok(); result.stderr.should.be.ok(); result.stderr.should.match(new RegExp(`Could not find file ${confFile}`)); });
it('should load config from config file absolute path', () => { const confFile = getAssetPath('conf.json'); const conf = require(confFile); const result = runCli(['--config', confFile, '-l', 'debug']); result.stdout.should.be.ok(); result.stderr.should.not.be.ok(); const confLog = JSON.parse(result.stdout.split('\n')[1]); confLog.config.should.be.eql(conf); });
it('it should fail if size is missing or 0', () => { let result = runCli(['-l', 'debug', 'b1,,1']); result.stderr.should.be.ok(); result.stderr.should.match(/Error: Could not parse bucket b1,,1 name:b1 size: ttl:1000/); result = runCli(['-l', 'debug', 'b1,0,1']); result.stderr.should.be.ok(); result.stderr.should.match(/bucket size "value" must be larger than or equal to 1/); });