it('Start (with callback)', (done) => { const httpServer = server.start((info) => { should(info.port).be.a.Number(); should(info.port).be.equal(5050); }); setTimeout(() => { test(server); should(httpServer).be.an.Object(); httpServer.close(); done(); }, 25); });
it('step (with stack)', (done) => { server.post('/', () => {}); setTimeout(() => { test(server); const nextStackFunction = server.step(fake.req, fake.res, [ () => 'Returned stack function.' ]); should(nextStackFunction).be.a.String(); should(nextStackFunction).be.equal('Returned stack function.'); done(); }, 25); });
const test = (server) => { should(server).be.an.Object(); should(server).have.properties('server', 'dispatch', 'start', 'step'); if (server.server) { should(server.server).be.an.Object(); } should(server.dispatch).be.an.Function(); should(server.start).be.an.Function(); should(server.step).be.an.Function(); METHODS.forEach((method) => { should(server[method.toLowerCase()]).be.a.Function(); }); }
it('send', (done) => { should(send()).be.a.Function(); done(); });
const test = (options = {}, headers, status, body) => { options.statusCode = options.statusCode || 200; options.headers = options.headers || 'text/plain'; if (headers['content-type']) { should(headers['content-type']).be.a.String(); should(headers['content-type']).be.equal(options.headers); } should(parseInt(headers['content-length'], 10)).be.equal(options.contentLength); should(status).be.a.Number(); should(status).be.equal(options.statusCode); should(body.toString()).be.equal(options.body); }
describe('Nice Names', () => { it('should change attribute name in message', async () => { const v = new Validator( { status: 'draft' }, { status: 'status:pending,published|required' }, { status: 'The :attribute value is invalid.' }, ); v.niceNames({ status: 'queue status', }); const matched = await v.check(); assert.equal(matched, false); v.errors.should.have.property('status').and.be.a.Object(); v.errors.status.should.have.property('message', 'The queue status value is invalid.'); }); });
describe('Configuration', function() { describe('leds information', function() { it('should have the success port configured', function(){ CONFIG.LED.should.have.property('SUCCESS').which.is.a.Number() }); it('should have the error port configured', function(){ CONFIG.LED.should.have.property('ERROR').which.is.a.Number() }); }); it('should have the cctray url added', function(){ CONFIG.should.have.property('CI_CCTRACKER_URL').which.is.a.String() CONFIG.CI_CCTRACKER_URL.should.be }); it('should have the interval polling information', function(){ CONFIG.should.have.property('INTERVAL').which.is.a.Number() }); });
it('step (with error)', (done) => { sandbox.stub(fake.res, 'writeHead').callsFake((status, headers) => { should(status).be.a.Number(); should(status).be.equal(400); should(headers).be.an.Object(); should(headers).have.property('Content-Type'); should(headers['Content-Type']).be.a.String(); should(headers['Content-Type']).be.equal('text/plain'); }); sandbox.stub(fake.res, 'write').callsFake((response) => { should(response).be.a.String(); should(response).be.equal('The error.'); }); server.post('/', () => {}); setTimeout(() => { test(server); server.step(fake.req, fake.res, [], 'The error.'); done(); }, 25); });
/** * Launch test */ describe("APP - Functions", () => { it('./modules/logger should have a all logger functions', (done) => { log.trace.should.be.an.Function(); log.debug.should.be.an.Function(); log.info.should.be.an.Function(); log.warn.should.be.an.Function(); log.error.should.be.an.Function(); log.fatal.should.be.an.Function(); done(); }); it('./modules/database should have an init function', (done) => { database.init.should.be.a.Function(); done(); }); it('./modules/csgoConfig should have an init function', (done) => { csgoConfig.init.should.be.a.Function(); done(); }); it('./modules/challonge should have an init function', (done) => { challonge.init.should.be.a.Function(); done(); }); });
it('step (with error and custom onError)', (done) => { server = rayo({ port: 5050, onError: (error) => { should(error).be.a.String(); should(error).be.equal('The error.'); } }).post('/', () => {}); setTimeout(() => { test(server); server.step(fake.req, fake.res, [], 'The error.'); done(); }, 25); });
it('Message between processes, valid command', async () => { const res = await exec('fixtures/command', { command: 'health' }); const json = extractJSON(res).pop(); should(json) .be.an.Object() .and.have.properties('pid', 'ppid', 'platform', 'upTime', 'cpuTime', 'memory'); should(json.cpuTime) .be.a.Number() .and.greaterThan(0); should(json.memory) .be.an.Object() .and.have.properties('rss', 'heapTotal', 'heapUsed', 'external'); filter(res, 'Master process: \\d+'); return filter(res, 'Hello from the worker!'); });
const test = (bridge, path = null) => { should(bridge).be.an.Object(); should(bridge).have.properties( 'id', 'bridgedPath', 'routes', 'through', 'route', 'fetch' ); should(bridge.id).be.a.String(); should(bridge.bridgedPath).be.equal(path); should(bridge.routes).be.an.Object(); should(bridge.through).be.a.Function(); should(bridge.route).be.a.Function(); should(bridge.fetch).be.a.Function(); METHODS.forEach((method) => { should(bridge).have.property(method.toLowerCase()); }); if (path) { should(bridge.bridgedPath).be.a.String(); } }
it('step (without stack)', (done) => { server.post('/', () => {}); setTimeout(() => { test(server); try { server.step(fake.req, fake.res, []); } catch (error) { should(error).be.an.Object(); should(error.message).be.a.String(); should(error.message).be.equal('No handler to move to, the stack is empty.'); done(); } }, 25); });
it('Dispatch (custom notFound function)', (done) => { server = rayo({ port: 5050, notFound: (req) => { should(req.method).be.a.String(); should(req.method).be.equal('GET'); } }).post('/', () => {}); server.dispatch(fake.req, fake.res); setTimeout(() => { test(server); done(); }, 25); });
it('Dispatch (undefined verb)', (done) => { sandbox.stub(fake.res, 'writeHead').callsFake((status, headers) => { should(status).be.a.Number(); should(status).be.equal(404); should(headers).be.an.Object(); should(headers).have.property('Content-Type'); should(headers['Content-Type']).be.a.String(); should(headers['Content-Type']).be.equal('text/plain'); }); sandbox.stub(fake.res, 'write').callsFake((response) => { should(response).be.a.String(); should(response).be.equal('Page not found.'); }); server.post('/', () => {}); const stack = server.dispatch(fake.req, fake.res); setTimeout(() => { test(server); should(stack).equal(undefined); done(); }, 25); });