test(static) /cloudcmd.js

This commit is contained in:
coderaiser 2017-03-29 15:41:16 +03:00
parent 02bac76d1a
commit e2950fbdef
2 changed files with 59 additions and 0 deletions

View file

@ -8,6 +8,8 @@ const io = require('socket.io');
const writejson = require('writejson');
const readjson = require('readjson');
process.env.NODE_ENV = 'development';
const cloudcmd = require('../server/cloudcmd');
const {assign} = Object;

View file

@ -52,3 +52,60 @@ test('cloudcmd: static: not found', (t) => {
});
});
test('cloudcmd: prefix: wrong', (t) => {
const prefix = '/hello';
const config = {prefix};
before({config}, (port, after) => {
const name = Math.random();
get(`http://localhost:${port}/${name}`)
.then((res) => {
res.on('response', ({statusCode}) => {
t.equal(statusCode, 404, 'should return 404');
});
res.on('end', () => {
t.end();
after();
});
})
.catch(console.error);
});
});
test('cloudcmd: /cloudcmd.js', (t) => {
before({}, (port, after) => {
const name = 'cloudcmd.js';
get(`http://localhost:${port}/${name}`)
.then((res) => {
res.on('response', ({statusCode}) => {
t.equal(statusCode, 200, 'should return OK');
});
res.on('end', () => {
t.end();
after();
});
})
.catch(console.error);
});
});
test('cloudcmd: /logout', (t) => {
before({}, (port, after) => {
const name = 'logout';
get(`http://localhost:${port}/${name}`)
.then((res) => {
res.on('response', ({statusCode}) => {
t.equal(statusCode, 401, 'should return 401');
});
res.on('end', () => {
t.end();
after();
});
})
.catch(console.error);
});
});