tests: Use the supertest agent from common.js
for api.js
This commit is contained in:
parent
08124ba733
commit
e0f499cf5a
1 changed files with 6 additions and 6 deletions
|
@ -9,11 +9,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const common = require('../../common');
|
const common = require('../../common');
|
||||||
const settings = require('../../../../node/utils/Settings');
|
|
||||||
const supertest = require('supertest');
|
|
||||||
const validateOpenAPI = require('openapi-schema-validation').validate;
|
const validateOpenAPI = require('openapi-schema-validation').validate;
|
||||||
|
|
||||||
const api = supertest(`http://${settings.ip}:${settings.port}`);
|
let agent;
|
||||||
const apiKey = common.apiKey;
|
const apiKey = common.apiKey;
|
||||||
let apiVersion = 1;
|
let apiVersion = 1;
|
||||||
|
|
||||||
|
@ -32,8 +30,10 @@ const testPadId = makeid();
|
||||||
const endPoint = (point) => `/api/${apiVersion}/${point}?apikey=${apiKey}`;
|
const endPoint = (point) => `/api/${apiVersion}/${point}?apikey=${apiKey}`;
|
||||||
|
|
||||||
describe(__filename, function () {
|
describe(__filename, function () {
|
||||||
|
before(async function () { agent = await common.init(); });
|
||||||
|
|
||||||
it('can obtain API version', function (done) {
|
it('can obtain API version', function (done) {
|
||||||
api
|
agent
|
||||||
.get('/api/')
|
.get('/api/')
|
||||||
.expect((res) => {
|
.expect((res) => {
|
||||||
apiVersion = res.body.currentVersion;
|
apiVersion = res.body.currentVersion;
|
||||||
|
@ -44,7 +44,7 @@ describe(__filename, function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can obtain valid openapi definition document', function (done) {
|
it('can obtain valid openapi definition document', function (done) {
|
||||||
api
|
agent
|
||||||
.get('/api/openapi.json')
|
.get('/api/openapi.json')
|
||||||
.expect((res) => {
|
.expect((res) => {
|
||||||
const {valid, errors} = validateOpenAPI(res.body, 3);
|
const {valid, errors} = validateOpenAPI(res.body, 3);
|
||||||
|
@ -59,7 +59,7 @@ describe(__filename, function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports jsonp calls', function (done) {
|
it('supports jsonp calls', function (done) {
|
||||||
api
|
agent
|
||||||
.get(`${endPoint('createPad')}&jsonp=jsonp_1&padID=${testPadId}`)
|
.get(`${endPoint('createPad')}&jsonp=jsonp_1&padID=${testPadId}`)
|
||||||
.expect((res) => {
|
.expect((res) => {
|
||||||
if (!res.text.match('jsonp_1')) throw new Error('no jsonp call seen');
|
if (!res.text.match('jsonp_1')) throw new Error('no jsonp call seen');
|
||||||
|
|
Loading…
Reference in a new issue