-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
99 lines (95 loc) · 4.43 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import http from 'http';
import * as jsonld from 'jsonld';
import test from 'ava';
import parse from '.';
test('served xml is converted to json', async t => {
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('4002');
const json = JSON.stringify(await parse('http://localhost:4002'));
t.is(json, '{"@context":{"@vocab":"http://vocab.datex.org/terms#"},"@graph":{"string":{"attribute":"value","text":"content"}}}');
});
test('served xml converts id to @id', async t => {
const server = http.createServer((req, res) => {
res.end(`
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<d2LogicalModel xmlns="http://datex2.eu/schema/2/2_0" modelBaseVersion="2" id="azertyuiop">
</d2LogicalModel>`);
});
server.listen('4003');
const json = JSON.stringify(await parse('http://localhost:4003', 'http://test.dev/datex/'));
t.is(json, '{"@context":{"@vocab":"http://vocab.datex.org/terms#"},"@graph":{"d2LogicalModel":{"xmlns":"//datex2.eu/schema/2/2_0","modelBaseVersion":"2","@id":"http://test.dev/datex/#azertyuiop"}}}');
});
test('it\'s possible to flatten the served json', async t => {
const server = http.createServer((req, res) => {
res.end(`
<?xml version="1.0" encoding="UTF-8"?>
<d2LogicaModel xmlns="http://datex2.eu/schema/2/2_0">
<exchange>
<supplierIdentification>
<country>fi</country>
<nationalIdentifier>Finnpark</nationalIdentifier>
</supplierIdentification>
</exchange>
<payloadPublication xsi:type="GenericPublication" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<publicationTime>2016-07-19T18:51:12+03:00</publicationTime>
<publicationCreator>
<country>fi</country>
<nationalIdentifier>Finnpark</nationalIdentifier>
</publicationCreator>
<genericPublicationName>Finland Parking Facilities</genericPublicationName>
<genericPublicationExtension>
<parkingFacilityTablePublication>
<headerInformation>
<areaOfInterest>national</areaOfInterest>
<confidentiality>noRestriction</confidentiality>
<informationStatus>real</informationStatus>
</headerInformation>
<parkingFacilityTable>
<parkingFacilityTableName>Finnpark</parkingFacilityTableName>
<parkingFacilityTableVersionTime>2015-03-05</parkingFacilityTableVersionTime>
<parkingFacility id="FNPK.11" version="1.0">
<parkingFacilityName>P-Plevna</parkingFacilityName>
<parkingFacilityRecordVersionTime>2015-03-05</parkingFacilityRecordVersionTime>
<carParkDetails>
<tag>Address</tag>
<value>Polttimokatu 5, 33210, Tampere</value>
</carParkDetails>
<entranceLocation>
<pointByCoordinates>
<pointCoordinates>
<latitude>61.501653</latitude>
<longitude>23.757688</longitude>
</pointCoordinates>
</pointByCoordinates>
</entranceLocation>
</parkingFacility>
</parkingFacilityTable>
</parkingFacilityTablePublication>
<parkingFacilityTableStatusPublication>
<headerInformation>
<areaOfInterest>national</areaOfInterest>
<confidentiality>noRestriction</confidentiality>
<informationStatus>real</informationStatus>
</headerInformation>
<parkingFacilityStatus>
<parkingFacilityOccupancyTrend>stable</parkingFacilityOccupancyTrend>
<parkingFacilityReference id="FNPK.11" version="1.0" targetClass="ParkingFacility"/>
<parkingFacilityStatus>spacesAvailable</parkingFacilityStatus>
<parkingFacilityStatus>open</parkingFacilityStatus>
<parkingFacilityStatusTime>2016-07-19T18:51:11+03:00</parkingFacilityStatusTime>
</parkingFacilityStatus>
</parkingFacilityTableStatusPublication>
</genericPublicationExtension>
</payloadPublication>
</d2LogicaModel>`);
});
server.listen('4004');
const json = await parse('http://localhost:4004', 'http://test.dev/datex/');
await t.notThrows(jsonld.promises.flatten(json));
});