-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
38 lines (33 loc) · 7.58 KB
/
test.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
import url from 'url';
import http from 'http';
import test from 'ava';
import got from 'got';
import serve from './lib/serve.js';
const server = http.createServer((req, res) => {
res.end(`
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<string someremovednamespace:attribute="value">
<text>content</text>
</string>`);
});
server.listen('8000');
test('starts serving', () => {
return serve('http://localhost:8000/', url.parse('http://localhost:4002'), 'title', true);
});
test('serves an index', async t => {
await serve('http://localhost:8000/', url.parse('http://localhost:4003'), 'title', true);
const res = await got('http://localhost:4003');
// todo: change this when the index changes looks
t.is(res.body,
'<!DOCTYPE html><html lang="en"><head><title>title</title><meta name="viewport" content="width=device-width, initial-scale=1"><style>body,h1{text-align:center}body{font-family:-apple-system,sans-serif;color:#002e93;padding:2em}code{font-family:Menlo,monospace}a{text-decoration:none;font-weight:bold;color:inherit;word-wrap:break-word;-webkit-hyphens:auto;-moz-hyphens:auto;-ms-hyphens:auto;hyphens:auto}main{position:relative;padding:2em;margin:3em auto;max-width:40em;text-align:initial;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center}.links{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;padding:0;margin:0;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap}.button{margin:1em;padding:.75em;list-style-type:none;background-color:#002e93;color:#efce2b}.back{background-color:#efce2b;position:absolute;width:100%;height:120%;left:0;top:0;-webkit-transform:rotate(3deg);transform:rotate(3deg);z-index:-1}#logo img{height:3rem}.center{text-align:center;}</style></head><body><a href="https://github.com/oSoc16/datex2-linker" id="logo"><img src="data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 544.8 216.06"><defs><style>.cls-1 { fill: #efce2b; } .cls-2 { fill: #002e93; }</style></defs><title>Datex II linker</title><path d="M141.03 31.42L416.57 67.2 400.4 191.72l-275.54-35.8zM46 0a46 46 0 1 0 46 46A46 46 0 0 0 46 0zm0 78.58A32.55 32.55 0 1 1 78.58 46 32.55 32.55 0 0 1 46 78.58zM498.77 113a46 46 0 1 0 46 46 46 46 0 0 0-46-46zm0 78.58a32.55 32.55 0 1 1 32.55-32.55 32.55 32.55 0 0 1-32.55 32.6z" class="cls-1"/><path d="M458.73 158.08L77.75 66.04l8-16.4 377.93 92.04-4.95 16.4" class="cls-1"/><path d="M140.14 177.32a4.4 4.4 0 0 1-4.6-4.23l-2.1-47.4a4.4 4.4 0 0 1 4.23-4.7 4.4 4.4 0 0 1 3.23 1.1 4.2 4.2 0 0 1 1.46 3.1l1.88 42.9 21.77-1a4.46 4.46 0 0 1 .4 8.9zm39.1-53.64a4.4 4.4 0 0 1 4.24-4.6 4.4 4.4 0 0 1 3.23 1.14 4.2 4.2 0 0 1 1.5 3.08l2.1 47.4a4.2 4.2 0 0 1-1.2 3.2 4.4 4.4 0 0 1-3.1 1.42 4.4 4.4 0 0 1-4.6-4.23zm33.4 12.62l1.46 33.34a4.3 4.3 0 0 1-1.15 3.15 4.16 4.16 0 0 1-3 1.4 4.22 4.22 0 0 1-3.15-1.2 4.27 4.27 0 0 1-1.42-3.1l-2.05-46.8a3.7 3.7 0 0 1 1.4-3.6 4.7 4.7 0 0 1 3.47-1.1 4.15 4.15 0 0 1 2.9 1.6l27.47 34.9-1.45-33.1a4.4 4.4 0 0 1 4.15-4.6 4.3 4.3 0 0 1 3.15 1.1 4.1 4.1 0 0 1 1.46 3l2 46.7a4.2 4.2 0 0 1-1.2 3.2 4.4 4.4 0 0 1-3.12 1.4 4.1 4.1 0 0 1-3.28-1.5 2.22 2.22 0 0 1-.42-.5zm62.27 33.82a4.42 4.42 0 0 1-7.6-2.8l-2-47a4.3 4.3 0 0 1 1.2-3.15 4.37 4.37 0 0 1 6.3-.28 4.32 4.32 0 0 1 1.5 3l1 23.1 24.9-27.3a4.44 4.44 0 0 1 6.6 6l-17 18.3 18.85 22.6a3.9 3.9 0 0 1 .74 4.7 4 4 0 0 1-3.5 2.6 4.56 4.56 0 0 1-3.7-1.5l-18.37-22-8 8.8.5 11.4a4.27 4.27 0 0 1-1.12 3.2zm54.4-1.12a4.4 4.4 0 0 1-4.6-4.23l-2.1-47.4a4.4 4.4 0 0 1 4.3-4.6l26.3-1.16a4.3 4.3 0 0 1 3.2 1.2 4.2 4.2 0 0 1 1.5 3.1 4.34 4.34 0 0 1-1.2 3.3 4.25 4.25 0 0 1-3 1.5l-21.7 1 .7 14.7 18.77-.8a4.53 4.53 0 0 1 4.6 4.3 4.36 4.36 0 0 1-1.15 3.2 4.2 4.2 0 0 1-3.04 1.5l-18.73.8.67 14.8 21.8-1a4.46 4.46 0 0 1 .4 8.9l-26 1.2h-.16zm70.7-28.92q5.7 3.94 6 11.4a21.66 21.66 0 0 0 .6 4.74 4.35 4.35 0 0 1 2.5 6.65 4.6 4.6 0 0 1-3.8 2h-.2q-3.6.16-5.8-3.45a22.73 22.73 0 0 1-2.1-9.57 7 7 0 0 0-3.6-5.64 14 14 0 0 0-4.6-1.7l-9.5.4.8 17.5a4.2 4.2 0 0 1-1.2 3.2 4.4 4.4 0 0 1-3.1 1.5 4.4 4.4 0 0 1-4.6-4.2l-2.1-47.4a4.4 4.4 0 0 1 4.24-4.6l14.4-.6a16.53 16.53 0 0 1 12.4 4.6 17.2 17.2 0 0 1 5.57 12.4 16.05 16.05 0 0 1-5.7 13.1zm-11.1-4.5a8.24 8.24 0 0 0 7.9-8.6 8.08 8.08 0 0 0-2.6-5.76 7.93 7.93 0 0 0-6-2.2l-9.9.44.7 16.54zM112.8 99.75l-2.24-47.4a4.4 4.4 0 0 1 4.2-4.63l9.5-.44a28.08 28.08 0 0 1 29.34 26.8 28.08 28.08 0 0 1-26.73 29.43l-9.48.5a4.4 4.4 0 0 1-4.7-4.2zm6.9-43.32l1.8 38.4 5-.23a18.74 18.74 0 0 0 13.26-6.3 19.27 19.27 0 0 0-1.27-27.1 18.4 18.4 0 0 0-13.8-5zm83.53 40.7l-4.43-10.27-19.53.92-3.45 10.63a4 4 0 0 1-3.78 3 4.3 4.3 0 0 1-4.04-1.7 4.57 4.57 0 0 1-.68-4l15.54-48.1a4.85 4.85 0 0 1 1.63-2.1 4 4 0 0 1 2.5-.8 4 4 0 0 1 4.3 2.5l20 46.5a4.58 4.58 0 0 1-.4 4.1 4.3 4.3 0 0 1-3.9 2.2 3.83 3.83 0 0 1-3.9-2.6zM182 78.78l13-.62-7.32-17zm75.55-36.48a4.27 4.27 0 0 1 1.45 3.1 4.34 4.34 0 0 1-1.18 3.24 4.24 4.24 0 0 1-3 1.47l-12.82.6 2 42.9a4.42 4.42 0 1 1-8.84.4l-2-42.9-12.7.6a4.2 4.2 0 0 1-3.2-1.1 4.4 4.4 0 0 1-1.42-3.1 4.4 4.4 0 0 1 4.16-4.7l34.3-1.6a4.28 4.28 0 0 1 3.25 1.2zm21.53 54.06a4.4 4.4 0 0 1-4.62-4.2l-2.22-47.4a4.4 4.4 0 0 1 4.2-4.64l26.28-1.23a4.32 4.32 0 0 1 3.15 1.1 4.2 4.2 0 0 1 1.47 3 4.33 4.33 0 0 1-1.18 3.2 4.24 4.24 0 0 1-3 1.4l-21.77 1 .6 14.7 18.7-.9a4.25 4.25 0 0 1 3.1 1.1 4.3 4.3 0 0 1 1.4 3.1 4.36 4.36 0 0 1-1.2 3.2 4.2 4.2 0 0 1-3.1 1.4l-18.7.86.7 14.8 21.7-1a4.46 4.46 0 0 1 .4 8.95l-26 1.24-.15-.1zm76.6-59.26a4.45 4.45 0 0 1 5.2 3.42 4.42 4.42 0 0 1-.6 3.33L346 65.3l16.24 20.18a4.13 4.13 0 0 1 .5 4.56 3.92 3.92 0 0 1-3.5 2.58 4.62 4.62 0 0 1-3.9-1.67L340.94 73l-12.7 19.23a4.62 4.62 0 0 1-3.73 2 3.92 3.92 0 0 1-3.7-2.23 4.14 4.14 0 0 1 .1-4.6l14.3-21.6-16.2-20a4.4 4.4 0 0 1-.9-3.25 4.46 4.46 0 0 1 4.9-3.9 4.1 4.1 0 0 1 3 1.68l14.5 17.84 12.6-19.1a4.35 4.35 0 0 1 2.8-1.95zm46.86 1.55a4.4 4.4 0 0 1 4.2-4.67 4.4 4.4 0 0 1 3.26 1.18 4.2 4.2 0 0 1 1.47 3.07l2.22 47.4a4.2 4.2 0 0 1-1.2 3.2 4.4 4.4 0 0 1-3.1 1.43 4.4 4.4 0 0 1-4.7-4.2zM427 37.52a4.4 4.4 0 0 1 4.2-4.63 4.4 4.4 0 0 1 3.28 1.1 4.2 4.2 0 0 1 1.52 3.1l2.22 47.4a4.2 4.2 0 0 1-1.22 3.2 4.4 4.4 0 0 1-3.1 1.4 4.4 4.4 0 0 1-4.64-4.2z" class="cls-2"/></svg>" alt="Datex 2 linker"></a><h1>title</h1><main><div class="content"><p>This is a <code>json-ld</code> version of the data available at <a href="http://localhost:8000/">http://localhost:8000/</a>.</p><ul class="links"><li class="button"><a href="data.json">/data.json</a></li><li class="button"><a href="data.jsonld">/data.jsonld</a></li></ul><p style="font-size: .8em; text-align: center">Generated with <a href="https://github.com/osoc16/datex2-linker">datex2-linker</a></p></div><div class="back"></div></main><div class="links" style="margin-top: -2em"><a class="button" href="http://vocab.datex.org">more info</a></div></body></html>');
});
test('content type of data.json is application/json', async t => {
await serve('http://localhost:8000/', url.parse('http://localhost:4004'), 'title', true);
const res = await got('http://localhost:4004/data.json');
t.is(res.headers['content-type'], 'application/json');
});
test('content type of data.jsonld is application/ld+json', async t => {
await serve('http://localhost:8000/', url.parse('http://localhost:4005'), 'title', true);
const res = await got('http://localhost:4005/data.jsonld');
t.is(res.headers['content-type'], 'application/ld+json');
});