diff --git a/test/before.js b/test/before.js index 211b82eb..b254b43d 100644 --- a/test/before.js +++ b/test/before.js @@ -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; diff --git a/test/static.js b/test/static.js index 76e903bf..b012cd46 100644 --- a/test/static.js +++ b/test/static.js @@ -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); + }); +}); +