UNPKG

2.48 kBJavaScriptView Raw
1/*
2 * Copyright 2018 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12/* eslint-env mocha */
13
14const assert = require('assert');
15
16const {
17 pipe,
18 pre,
19 adaptOWRequest,
20 adaptOWResponse,
21 log,
22} = require('../index.js').defaults;
23
24describe('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});