40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
|
|
/* jslint node:true */
|
||
|
|
/* global it:false */
|
||
|
|
/* global describe:false */
|
||
|
|
/* global before:false */
|
||
|
|
/* global after:false */
|
||
|
|
|
||
|
|
'use strict';
|
||
|
|
|
||
|
|
const common = require('./common.js'),
|
||
|
|
expect = require('expect.js'),
|
||
|
|
superagent = require('superagent');
|
||
|
|
|
||
|
|
describe('REST API', function () {
|
||
|
|
const { setup, cleanup, serverUrl, owner } = common;
|
||
|
|
|
||
|
|
before(setup);
|
||
|
|
after(cleanup);
|
||
|
|
|
||
|
|
it('does not crash with invalid JSON', async function () {
|
||
|
|
const response = await superagent.post(`${serverUrl}/api/v1/users`)
|
||
|
|
.query({ access_token: owner.token })
|
||
|
|
.set('content-type', 'application/json')
|
||
|
|
.send('some invalid non-strict json')
|
||
|
|
.ok(() => true);
|
||
|
|
|
||
|
|
expect(response.statusCode).to.equal(400);
|
||
|
|
expect(response.body.message).to.be('Failed to parse body');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('does not crash with invalid string', async function () {
|
||
|
|
const response = await superagent.post(`${serverUrl}/api/v1/users`)
|
||
|
|
.query({ access_token: owner.token })
|
||
|
|
.set('content-type', 'application/x-www-form-urlencoded')
|
||
|
|
.send('some string')
|
||
|
|
.ok(() => true);
|
||
|
|
|
||
|
|
expect(response.statusCode).to.equal(400);
|
||
|
|
});
|
||
|
|
});
|