2018-11-30 16:12:48 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
2018-12-03 17:35:30 +00:00
|
|
|
import * as webrequest from '../ts/index';
|
2018-12-04 16:35:40 +00:00
|
|
|
import * as fetch from 'node-fetch';
|
|
|
|
|
|
|
|
declare global {
|
|
|
|
namespace NodeJS {
|
|
|
|
interface Global {
|
|
|
|
fetch: any;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
global.fetch = fetch;
|
|
|
|
|
2018-11-30 16:12:48 +00:00
|
|
|
|
2018-12-03 17:35:30 +00:00
|
|
|
// test dependencies
|
|
|
|
import * as smartexpress from '@pushrocks/smartexpress';
|
|
|
|
|
|
|
|
let testServer: smartexpress.Server;
|
|
|
|
|
|
|
|
tap.test('setup test server', async () => {
|
|
|
|
testServer = new smartexpress.Server({
|
|
|
|
cors: false,
|
|
|
|
forceSsl: false,
|
2018-12-04 16:35:40 +00:00
|
|
|
port: 2345
|
2018-12-03 17:35:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testServer.addRoute('/apiroute1', new smartexpress.Handler("GET", (req, res) => {
|
|
|
|
res.status(429);
|
|
|
|
res.end();
|
|
|
|
}));
|
|
|
|
|
2018-12-04 16:35:40 +00:00
|
|
|
testServer.addRoute('/apiroute2', new smartexpress.Handler("GET", (req, res) => {
|
|
|
|
res.status(500);
|
|
|
|
res.end();
|
|
|
|
}));
|
|
|
|
|
|
|
|
testServer.addRoute('/apiroute3', new smartexpress.Handler("GET", (req, res) => {
|
|
|
|
res.status(200);
|
|
|
|
res.send({
|
|
|
|
hithere: 'hi'
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
await testServer.start()
|
2018-12-03 17:35:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
tap.test('first test', async (tools) => {
|
2018-12-04 16:35:40 +00:00
|
|
|
const response = await (new webrequest.WebRequest()).request([
|
|
|
|
'http://localhost:2345/apiroute1',
|
|
|
|
'http://localhost:2345/apiroute2',
|
|
|
|
'http://localhost:2345/apiroute4',
|
|
|
|
'http://localhost:2345/apiroute3'
|
|
|
|
], {
|
|
|
|
method: 'GET'
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log(response);
|
|
|
|
|
|
|
|
expect(response).property('hithere').to.equal('hi');
|
|
|
|
})
|
|
|
|
|
|
|
|
tap.test('tear down server', async () => {
|
|
|
|
testServer.stop();
|
2018-11-30 16:12:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
tap.start()
|