@tak-ps/node-cot 2.7.0 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -7
- package/lib/util.js +12 -11
- package/lib/xml.js +7 -8
- package/package-lock.json +134 -1833
- package/package.json +1 -1
- package/test/from_geojson.test.js +57 -0
- package/test/util.test.js +34 -0
- package/test/styles.test.js +0 -33
package/package.json
CHANGED
|
@@ -123,3 +123,60 @@ test('XML.from_geojson - LineString', (t) => {
|
|
|
123
123
|
|
|
124
124
|
t.end();
|
|
125
125
|
});
|
|
126
|
+
|
|
127
|
+
test('XML.from_geojson - Start', (t) => {
|
|
128
|
+
const geo = XML.from_geojson({
|
|
129
|
+
type: 'Feature',
|
|
130
|
+
properties: {
|
|
131
|
+
// 1hr in the future
|
|
132
|
+
start: new Date(+new Date() + 60 * 60 * 1000)
|
|
133
|
+
},
|
|
134
|
+
geometry: {
|
|
135
|
+
type: 'Point',
|
|
136
|
+
coordinates: [1.1, 2.2]
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Approx +/- 100ms + 1hr ahead of Now
|
|
141
|
+
t.ok(+new Date(geo.raw.event._attributes.start) > +new Date() + 60 * 60 * 1000 - 100);
|
|
142
|
+
t.ok(+new Date(geo.raw.event._attributes.start) < +new Date() + 60 * 60 * 1000 + 100);
|
|
143
|
+
|
|
144
|
+
// Approx +/- 100ms ahead of Now
|
|
145
|
+
t.ok(+new Date(geo.raw.event._attributes.time) > +new Date() - 100);
|
|
146
|
+
t.ok(+new Date(geo.raw.event._attributes.time) < +new Date() + 100);
|
|
147
|
+
|
|
148
|
+
// Approx +/- 100ms +1hr20s ahead of now
|
|
149
|
+
t.ok(+new Date(geo.raw.event._attributes.stale) > +new Date(geo.raw.event._attributes.start) - 100 + 20 * 1000);
|
|
150
|
+
t.ok(+new Date(geo.raw.event._attributes.stale) < +new Date(geo.raw.event._attributes.start) + 100 + 20 * 1000);
|
|
151
|
+
|
|
152
|
+
t.end();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('XML.from_geojson - Start/Stale', (t) => {
|
|
156
|
+
const geo = XML.from_geojson({
|
|
157
|
+
type: 'Feature',
|
|
158
|
+
properties: {
|
|
159
|
+
// 1hr in the future
|
|
160
|
+
start: new Date(+new Date() + 60 * 60 * 1000),
|
|
161
|
+
stale: 60 * 1000
|
|
162
|
+
},
|
|
163
|
+
geometry: {
|
|
164
|
+
type: 'Point',
|
|
165
|
+
coordinates: [1.1, 2.2]
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Approx +/- 100ms + 1hr ahead of Now
|
|
170
|
+
t.ok(+new Date(geo.raw.event._attributes.start) > +new Date() + 60 * 60 * 1000 - 100);
|
|
171
|
+
t.ok(+new Date(geo.raw.event._attributes.start) < +new Date() + 60 * 60 * 1000 + 100);
|
|
172
|
+
|
|
173
|
+
// Approx +/- 100ms ahead of Now
|
|
174
|
+
t.ok(+new Date(geo.raw.event._attributes.time) > +new Date() - 100);
|
|
175
|
+
t.ok(+new Date(geo.raw.event._attributes.time) < +new Date() + 100);
|
|
176
|
+
|
|
177
|
+
// Approx +/- 100ms +1hr60s ahead of now
|
|
178
|
+
t.ok(+new Date(geo.raw.event._attributes.stale) > +new Date(geo.raw.event._attributes.start) - 100 + 60 * 1000);
|
|
179
|
+
t.ok(+new Date(geo.raw.event._attributes.stale) < +new Date(geo.raw.event._attributes.start) + 100 + 60 * 1000);
|
|
180
|
+
|
|
181
|
+
t.end();
|
|
182
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import test from 'tape';
|
|
2
|
+
import Util from '../lib/util.js';
|
|
3
|
+
|
|
4
|
+
test('Util.cot_date - default', (t) => {
|
|
5
|
+
const res = Util.cot_date();
|
|
6
|
+
|
|
7
|
+
// Within 100ms of current time
|
|
8
|
+
t.ok(+new Date(res.time) > +new Date() - 100, 'res.time within 100ms of current time');
|
|
9
|
+
|
|
10
|
+
// res.start is the same as res.time
|
|
11
|
+
t.equals(+new Date(res.start), +new Date(res.time), 'by default res.start === res.time');
|
|
12
|
+
|
|
13
|
+
// Approx 20s ahead of start
|
|
14
|
+
t.ok(+new Date(res.stale) > +new Date(res.start) + 20 * 1000 - 100);
|
|
15
|
+
t.ok(+new Date(res.stale) < +new Date(res.start) + 20 * 1000 + 100);
|
|
16
|
+
|
|
17
|
+
t.end();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('Util.cot_date - stale', (t) => {
|
|
21
|
+
const res = Util.cot_date(null, null, 1000);
|
|
22
|
+
|
|
23
|
+
// Within 100ms of current time
|
|
24
|
+
t.ok(+new Date(res.time) > +new Date() - 100, 'res.time within 100ms of current time');
|
|
25
|
+
|
|
26
|
+
// res.start is the same as res.time
|
|
27
|
+
t.equals(+new Date(res.start), +new Date(res.time), 'by default res.start === res.time');
|
|
28
|
+
|
|
29
|
+
// Approx 1s ahead of start
|
|
30
|
+
t.ok(+new Date(res.stale) > +new Date(res.start) + 1 * 1000 - 100);
|
|
31
|
+
t.ok(+new Date(res.stale) < +new Date(res.start) + 1 * 1000 + 100);
|
|
32
|
+
|
|
33
|
+
t.end();
|
|
34
|
+
});
|
package/test/styles.test.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import test from 'tape';
|
|
2
|
-
import { XML } from '../index.js';
|
|
3
|
-
|
|
4
|
-
test('XML.from_geojson - Polygon Style', (t) => {
|
|
5
|
-
const geo = XML.from_geojson({
|
|
6
|
-
type: 'Feature',
|
|
7
|
-
properties: {
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
geometry: {
|
|
11
|
-
type: 'Point',
|
|
12
|
-
coordinates: [1.1, 2.2]
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
t.equals(geo.raw.event._attributes.version, '2.0');
|
|
17
|
-
t.equals(geo.raw.event._attributes.type, 'a-f-G');
|
|
18
|
-
t.equals(geo.raw.event._attributes.how, 'm-g');
|
|
19
|
-
t.equals(geo.raw.event._attributes.uid.length, 36);
|
|
20
|
-
t.equals(geo.raw.event._attributes.time.length, 24);
|
|
21
|
-
t.equals(geo.raw.event._attributes.start.length, 24);
|
|
22
|
-
t.equals(geo.raw.event._attributes.stale.length, 24);
|
|
23
|
-
|
|
24
|
-
t.deepEquals(geo.raw.event.point, {
|
|
25
|
-
_attributes: { lat: 2.2, lon: 1.1, hae: 0, ce: 9999999, le: 9999999 }
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
t.deepEquals(geo.raw.event.detail, {
|
|
29
|
-
contact: { _attributes: { callsign: 'UNKNOWN' } }
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
t.end();
|
|
33
|
-
});
|