-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestHelperCapture.test.ts
More file actions
45 lines (42 loc) · 1.54 KB
/
testHelperCapture.test.ts
File metadata and controls
45 lines (42 loc) · 1.54 KB
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
/**
* When testing the test suite starts ;)
* Do not go in infinite loop!
*/
import assert from 'node:assert/strict';
import { init as initTestServer } from './helpers/testServer.ts';
import { startHttpServerCapture } from './helpers/testWebServerCapture.ts';
describe('[TESX] Testing mockup server for webhooks', () => {
let webServerCapture: Awaited<ReturnType<typeof startHttpServerCapture>>;
const port = 8365;
before(async () => {
await initTestServer();
webServerCapture = await startHttpServerCapture({ port });
});
after(async () => {
await webServerCapture.close();
});
it(`[TESW] POST http://localhost:${port}/test`, async () => {
const responseNextCall = {
code: 201,
headers: { hello: 'bob' },
body: 'This is Bob'
};
webServerCapture.nextCalls.push(responseNextCall);
const url = '/test?params=1';
const fetchParams = {
method: 'POST',
headers: { hello: 'tom' },
body: 'This is Tom'
};
const result = await fetch(`http://127.0.0.1:${port}${url}`, fetchParams);
const resultBody = await result.text();
const captured = webServerCapture.captured.pop();
assert.equal(captured!.method, fetchParams.method);
assert.equal(captured!.url, url);
assert.equal(captured!.headers.hello, fetchParams.headers.hello);
assert.equal(captured!.body, fetchParams.body);
assert.equal(resultBody, responseNextCall.body);
assert.equal(result.status, responseNextCall.code);
assert.equal(result.headers.get('hello'), responseNextCall.headers.hello);
});
});