1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const assert = require('assert');
|
15 |
|
16 | const {
|
17 | pipe,
|
18 | pre,
|
19 | adaptOWRequest,
|
20 | adaptOWResponse,
|
21 | log,
|
22 | } = require('../index.js').defaults;
|
23 |
|
24 | describe('Testing Default Pipeline', () => {
|
25 | it('Default Pipeline can be loaded', () => {
|
26 | assert.ok(pipe, 'no default pipeline found');
|
27 | assert.ok(pre, 'no default pre.js found');
|
28 | assert.ok(adaptOWRequest, 'no request wrapper found');
|
29 | assert.ok(adaptOWResponse, 'no response wrapper found');
|
30 | assert.ok(log, 'no logger found');
|
31 | });
|
32 |
|
33 | it('creates a runs the default pipeline', async () => {
|
34 | const out = await pipe((payload, action) => ({
|
35 | body: `test. payload: ${payload.title} action: ${action.title}`,
|
36 | }), {
|
37 | title: 'my payload',
|
38 | }, {
|
39 | title: 'my action',
|
40 | });
|
41 | assert.deepStrictEqual(out, {
|
42 | body: 'test. payload: my payload action: my action',
|
43 | title: 'my payload',
|
44 | });
|
45 | });
|
46 |
|
47 | it('adaptOWRequest needs to parse req parameter', () => {
|
48 | const testObject = {
|
49 | url: 'url',
|
50 | headers: {
|
51 | h1: '1',
|
52 | h2: '2',
|
53 | },
|
54 | params: {
|
55 | p1: '1',
|
56 | p2: true,
|
57 | p3: ['a', 'b', 'c'],
|
58 | p4: {
|
59 | p41: '1',
|
60 | },
|
61 | },
|
62 | };
|
63 | const out = adaptOWRequest({}, { request: { params: { req: JSON.stringify(testObject) } } });
|
64 | assert.ok(out.request, 'missing request object');
|
65 | assert.deepEqual(testObject, out.request, 'request object does not match incoming req');
|
66 | });
|
67 |
|
68 | it('adaptOWRequest acts reasonably on wrong req parameter', () => {
|
69 | const out = adaptOWRequest({}, { request: { params: { req: 'this is not json' } } });
|
70 | assert.ok(out.request, 'missing request object');
|
71 | });
|
72 |
|
73 | it('adaptOWRequest acts reasonably with no request object', () => {
|
74 | const out = adaptOWRequest({}, {});
|
75 | assert.ok(out.request, 'missing request object');
|
76 | });
|
77 | });
|