1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const assert = require('assert');
|
14 | const winston = require('winston');
|
15 | const { pipe } = require('../src/defaults/html.pipe.js');
|
16 |
|
17 | const logger = winston.createLogger({
|
18 |
|
19 | level: 'debug',
|
20 |
|
21 | silent: true,
|
22 | format: winston.format.simple(),
|
23 | transports: [
|
24 | new winston.transports.Console(),
|
25 | ],
|
26 | });
|
27 |
|
28 | const params = {
|
29 | path: '/hello.md',
|
30 | __ow_method: 'get',
|
31 | owner: 'trieloff',
|
32 | __ow_headers: {
|
33 | 'X-Forwarded-Port': '443',
|
34 | 'X-CDN-Request-Id': '2a208a89-e071-44cf-aee9-220880da4c1e',
|
35 | 'Fastly-Client': '1',
|
36 | 'X-Forwarded-Host': 'runtime.adobe.io',
|
37 | 'Upgrade-Insecure-Requests': '1',
|
38 | Host: 'controller-a',
|
39 | Connection: 'close',
|
40 | 'Fastly-SSL': '1',
|
41 | 'X-Request-Id': 'RUss5tPdgOfw74a68aNc24FeTipGpVfW',
|
42 | 'X-Branch': 'master',
|
43 | 'Accept-Language': 'en-US, en;q=0.9, de;q=0.8',
|
44 | 'X-Forwarded-Proto': 'https',
|
45 | 'Fastly-Orig-Accept-Encoding': 'gzip',
|
46 | 'X-Varnish': '267021320',
|
47 | DNT: '1',
|
48 | 'X-Forwarded-For':
|
49 | '192.147.117.11, 157.52.92.27, 23.235.46.33, 10.64.221.107',
|
50 | 'X-Host': 'www.primordialsoup.life',
|
51 | Accept:
|
52 | 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, image/apng, */*;q=0.8',
|
53 | 'X-Real-IP': '10.64.221.107',
|
54 | 'X-Forwarded-Server': 'cache-lcy19249-LCY, cache-iad2127-IAD',
|
55 | 'Fastly-Client-IP': '192.147.117.11',
|
56 | 'Perf-Br-Req-In': '1529585370.116',
|
57 | 'X-Timer': 'S1529585370.068237,VS0,VS0',
|
58 | 'Fastly-FF':
|
59 | 'dc/x3e9z8KMmlHLQr8BEvVMmTcpl3y2YY5y6gjSJa3g=!LCY!cache-lcy19249-LCY, dc/x3e9z8KMmlHLQr8BEvVMmTcpl3y2YY5y6gjSJa3g=!LCY!cache-lcy19227-LCY, dc/x3e9z8KMmlHLQr8BEvVMmTcpl3y2YY5y6gjSJa3g=!IAD!cache-iad2127-IAD, dc/x3e9z8KMmlHLQr8BEvVMmTcpl3y2YY5y6gjSJa3g=!IAD!cache-iad2133-IAD',
|
60 | 'Accept-Encoding': 'gzip',
|
61 | 'User-Agent':
|
62 | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',
|
63 | },
|
64 | repo: 'soupdemo',
|
65 | ref: 'master',
|
66 | selector: 'md',
|
67 | branch: 'master',
|
68 | };
|
69 |
|
70 | const secrets = {
|
71 | REPO_RAW_ROOT: 'https://raw.githubusercontent.com/',
|
72 | };
|
73 |
|
74 | describe('Testing HTML Pipeline', () => {
|
75 | it('html.pipe is a function', () => {
|
76 | assert.ok(pipe);
|
77 | assert.strictEqual(typeof pipe, 'function');
|
78 | });
|
79 |
|
80 | it('html.pipe makes HTTP requests', (done) => {
|
81 | const result = pipe(
|
82 | ({ content }) => {
|
83 |
|
84 |
|
85 | assert.ok(content.body);
|
86 | assert.ok(content.mdast);
|
87 | assert.ok(content.meta);
|
88 | assert.equal('Medium', content.meta.template);
|
89 | assert.equal('Project Helix', content.intro);
|
90 | assert.equal('Bill, Welcome to the future', content.title);
|
91 |
|
92 | return { response: { status: 201, body: content.html } };
|
93 | },
|
94 | {},
|
95 | {
|
96 | request: { params },
|
97 | secrets,
|
98 | logger,
|
99 | },
|
100 | );
|
101 |
|
102 | result.then((res) => {
|
103 | assert.equal(201, res.statusCode);
|
104 | assert.equal('text/html', res.headers['Content-Type']);
|
105 | assert.equal('<', res.body[0]);
|
106 | assert.ok(res.body.match(/srcset/));
|
107 | done();
|
108 | });
|
109 | });
|
110 | });
|