-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
113 lines (98 loc) · 3.9 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* global describe, it */
const fs = require('fs')
const nock = require('nock')
const assert = require('chai').assert
const ADDS = require('./')
const fixtures = {
metar: fs.readFileSync('./fixtures/metar.xml').toString(),
taf: fs.readFileSync('./fixtures/taf.xml').toString(),
aircraftReport: fs.readFileSync('./fixtures/aircraft-report.xml').toString(),
airsigmet: fs.readFileSync('./fixtures/airsigmet.xml').toString(),
gairmet: fs.readFileSync('./fixtures/gairmet.xml').toString(),
station: fs.readFileSync('./fixtures/station.xml').toString()
}
describe('ADDS', () => {
it('should exist', done => {
assert(ADDS !== undefined)
done()
})
describe('Parsing', () => {
it('should parse metars correctly', async () => {
nock(ADDS.ADDS_BASE_URI)
.get('/adds/dataserver_current/httpparam')
.query({ requestType: 'retrieve', format: 'xml', dataSource: 'metars' })
.reply(200, fixtures.metar)
return ADDS('metars', {})
.then(results => {
assert.equal(results.length, 1)
assert.equal(results[0].station_id, 'KDEN')
assert.equal(results[0].sky_condition.sky_cover, 'OVC')
})
})
it('should parse tafs correctly', async () => {
nock(ADDS.ADDS_BASE_URI)
.get('/adds/dataserver_current/httpparam')
.query({ requestType: 'retrieve', format: 'xml', dataSource: 'tafs' })
.reply(200, fixtures.taf)
return ADDS('tafs', {})
.then(results => {
assert.equal(results.length, 1)
assert.equal(results[0].station_id, 'PHNL')
assert.equal(results[0].forecast.length, 3)
assert.equal(results[0].forecast[0].wind_speed_kt, 17)
})
})
it('should parse aircraft reports correctly', async () => {
nock(ADDS.ADDS_BASE_URI)
.get('/adds/dataserver_current/httpparam')
.query({ requestType: 'retrieve', format: 'xml', dataSource: 'aircraftreports' })
.reply(200, fixtures.aircraftReport)
return ADDS('aircraftreports', {})
.then(results => {
assert.equal(results.length, 1)
assert.equal(results[0].aircraft_ref, 'ETD76T')
assert.equal(results[0].wind_speed_kt, 126)
assert.equal(results[0].report_type, 'AIREP')
})
})
it('should parse airsigmets correctly', async () => {
nock(ADDS.ADDS_BASE_URI)
.get('/adds/dataserver_current/httpparam')
.query({ requestType: 'retrieve', format: 'xml', dataSource: 'airsigmets' })
.reply(200, fixtures.airsigmet)
return ADDS('airsigmets', {})
.then(results => {
assert.equal(results.length, 1)
assert.equal(results[0].airsigmet_type, 'AIRMET')
assert.equal(results[0].area.point.length, 8)
assert.equal(results[0].area.point[0].longitude, -108.93)
})
})
it('should parse gairmets correctly', async () => {
nock(ADDS.ADDS_BASE_URI)
.get('/adds/dataserver_current/httpparam')
.query({ requestType: 'retrieve', format: 'xml', dataSource: 'gairmets' })
.reply(200, fixtures.gairmet)
return ADDS('gairmets', {})
.then(results => {
assert.equal(results.length, 2)
assert.equal(results[0].status, 'NRML')
assert.equal(results[0].area.point.length, 17)
assert.equal(results[0].area.point[0].longitude, -125.55)
})
})
it('should parse stations correctly', async () => {
nock(ADDS.ADDS_BASE_URI)
.get('/adds/dataserver_current/httpparam')
.query({ requestType: 'retrieve', format: 'xml', dataSource: 'stations' })
.reply(200, fixtures.station)
return ADDS('stations', {})
.then(results => {
assert.equal(results.length, 3)
assert.equal(results[0].station_id, 'KDEN')
assert.equal(results[0].longitude, -104.65)
assert.deepEqual(results[0].site_type.METAR, {})
})
})
})
})