forked from Ealenn/Echo-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom.body.js
48 lines (46 loc) · 1.19 KB
/
custom.body.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const assert = require('assert');
const request = require('supertest');
process.env.LOGS__LEVEL = "error";
describe('Custom Body', function () {
var server;
beforeEach(function () {
server = require('../src/app');
});
afterEach(function () {
server.close();
});
it('Text with Header', (done) => {
request(server)
.get('/')
.set('X-ECHO-BODY', 'Example text')
.expect(function (res) {
assert.strictEqual(res.body, "Example text")
})
.expect(200, done);
});
it('Json with Header', (done) => {
request(server)
.get('/')
.set('X-ECHO-BODY', '{"example": "json"}')
.expect(function (res) {
assert.strictEqual(res.body.example, "json")
})
.expect(200, done);
});
it('Text with Query', (done) => {
request(server)
.get('/?echo_body=Example text')
.expect(function (res) {
assert.strictEqual(res.body, "Example text")
})
.expect(200, done);
});
it('Json with Query', (done) => {
request(server)
.get('/?echo_body={"example": "json"}')
.expect(function (res) {
assert.strictEqual(res.body.example, "json")
})
.expect(200, done);
});
});