-
Notifications
You must be signed in to change notification settings - Fork 74
/
TranslationServer.js
1172 lines (1045 loc) · 56.6 KB
/
TranslationServer.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// See docs/developer/ElementTranslationService.asciidoc
var assert = require('assert'),
http = require('http'),
xml2js = require('xml2js'),
fs = require('fs'),
httpMocks = require('node-mocks-http'),
osmtogeojson = require('osmtogeojson'),
DOMParser = new require('@xmldom/xmldom').DOMParser
parser = new DOMParser(),
hashseedzero = true;
var server = require('../TranslationServer.js');
describe('TranslationServer', function () {
describe('fcodes', function() {
this.timeout(3000);
it('should return fcodes for MGCP Line', function(){
assert.equal(server.getFCodes({
method: 'GET',
translation: 'MGCP',
geometry: 'line'
}).length, 63);
});
it('should return fcodes for TDSv61 Point', function(){
assert.equal(server.getFCodes({
method: 'GET',
translation: 'TDSv61',
geometry: 'Point'
}).length, 193);
});
it('should return fcodes for GGDMv30 Area', function(){
assert.equal(server.getFCodes({
method: 'GET',
translation: 'GGDMv30',
geometry: 'Area'
}).length, 280);
});
it('should return fcodes for TDSv71 Area', function(){
assert.equal(server.getFCodes({
method: 'GET',
translation: 'TDSv71',
geometry: 'Area'
}).length, 204);
});
it('should return fcodes for TDSv40 Vertex', function(){
assert.equal(server.getFCodes({
method: 'GET',
translation: 'TDSv40',
geometry: 'vertex'
}).length, 190);
});
it('should return fcodes for MGCP with no geometry', function(){
var fcodes = server.getFCodes({
method: 'GET',
translation: 'MGCP'
});
assert.equal(fcodes.length, 206);
assert.equal(fcodes[0].geom[0], 'Area');
});
});
describe('handleInputs', function() {
it('should handle translateTo GET', function() {
// example url
// http://localhost:8094/translateTo?idval=AL015&geom=Point&translation=MGCP&idelem=fcode
var schema = server.handleInputs({
idval: 'AL015',
geom: 'Point',
translation: 'MGCP',
idelem: 'fcode',
method: 'GET',
path: '/translateTo'
});
assert.equal(schema.desc, 'General Building');
assert.equal(schema.columns[0].name, 'ACC');
assert.equal(schema.columns[0].enumerations[0].name, 'Accurate');
assert.equal(schema.columns[0].enumerations[0].value, '1');
});
it('should handle translateTo GET with key & value param', function() {
var schema = server.handleInputs({
value: 'AL015',
geom: 'Point',
translation: 'MGCP',
key: 'fcode',
method: 'GET',
path: '/translateTo'
});
assert.equal(schema.desc, 'General Building');
assert.equal(schema.columns[0].name, 'ACC');
assert.equal(schema.columns[0].enumerations[0].name, 'Accurate');
assert.equal(schema.columns[0].enumerations[0].value, '1');
});
it('should handle no matches translateTo GET for MGCP', function() {
assert.throws(function error() {
server.handleInputs({
idval: 'FB123',
geom: 'area',
translation: 'TDSv61',
idelem: 'fcode',
method: 'GET',
path: '/translateTo'
})
}, Error, 'TDSv61 for Area with fcode=FB123 not found');
});
it('builds intersection of between geometry schemas', function() {
var pointSchema = server.handleInputs({
idval: 'AL013',
geom: 'Point',
translation: 'TDSv61',
idelem: 'fcode',
method: 'GET',
path: '/translateTo'
});
var areaSchema = server.handleInputs({
idval: 'AL013',
geom: 'Area',
translation: 'TDSv61',
idelem: 'fcode',
method: 'GET',
path: '/translateTo'
});
var allSchema = server.handleInputs({
idval: 'AL013',
geom: 'Area,Point',
translation: 'TDSv61',
idelem: 'fcode',
method: 'GET',
path: '/translateTo'
});
var pointSchemaColumns = pointSchema.columns.map(function(col) { return col.name; });
var areaSchemaColumns = areaSchema.columns.map(function(col) { return col.name; } );
var allSchemaColumns = allSchema.columns.map(function(col) { return col.name; });
var intersection = pointSchemaColumns.filter(function(col) { return areaSchemaColumns.indexOf(col) !== -1 }).length > 0;
assert.equal(allSchemaColumns.length > 0, true);
assert.equal(intersection, true);
})
it('should handle translateFrom GET for TDSv71', function() {
var attrs = server.handleInputs({
fcode: 'AL013',
translation: 'TDSv71',
method: 'GET',
path: '/translateFrom'
});
assert.equal(attrs.building, 'yes')
})
it('should handle translateFrom GET for TDSv70', function() {
var attrs = server.handleInputs({
fcode: 'AL013',
translation: 'TDSv70',
method: 'GET',
path: '/translateFrom'
});
assert.equal(attrs.building, 'yes')
})
it('should handle translateFrom GET for TDSv71', function() {
//http://localhost:8094/translateFrom?fcode=AL013&translation=TDSv71
var attrs = server.handleInputs({
fcode: 'AL013',
translation: 'TDSv71',
method: 'GET',
path: '/translateFrom'
});
assert.equal(attrs.building, 'yes');
});
it('should handle translateFrom GET for TDSv70', function() {
//http://localhost:8094/translateFrom?fcode=AL013&translation=TDSv70
var attrs = server.handleInputs({
fcode: 'AL013',
translation: 'TDSv70',
method: 'GET',
path: '/translateFrom'
});
assert.equal(attrs.building, 'yes');
});
it('should handle translateFrom GET for TDSv61', function() {
//http://localhost:8094/translateFrom?fcode=AL013&translation=TDSv61
var attrs = server.handleInputs({
fcode: 'AL013',
translation: 'TDSv61',
method: 'GET',
path: '/translateFrom'
});
assert.equal(attrs.building, 'yes');
});
it('should handle translateFrom GET for TDSv40', function() {
//http://localhost:8094/tdstoosm?fcode=AL013&translation=TDSv40
var attrs = server.handleInputs({
fcode: 'AP030',
translation: 'TDSv40',
method: 'GET',
path: '/translateFrom'
});
assert.equal(attrs.highway, 'road');
});
it('should handle translateFrom GET for MGCP', function() {
//http://localhost:8094/translateFrom?fcode=AL013&translation=TDSv61
var attrs = server.handleInputs({
fcode: 'BH140',
translation: 'MGCP',
method: 'GET',
path: '/translateFrom'
});
assert.equal(attrs.waterway, 'river');
});
it('should handle translateFrom GET for GGDMv30', function() {
//http://localhost:8094/tdstoosm?fcode=AL013&translation=GGDMv30
var attrs = server.handleInputs({
fcode: 'BH140',
translation: 'GGDMv30',
method: 'GET',
path: '/translateFrom'
});
assert.equal(attrs.waterway, 'river');
});
it('should handle invalid F_CODE in translateFrom GET for MGCP', function() {
var attrs = server.handleInputs({
fcode: 'ZZTOP',
translation: 'MGCP',
method: 'GET',
path: '/translateFrom'
});
assert.equal(attrs.error, 'Feature Code ZZTOP is not valid for MGCP');
});
it('should handle translateTo TDSv61 POST', function() {
var output = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="JOSM"><node id="-1" lon="-105.21811763904256" lat="39.35643172777992" version="0"><tag k="building" v="yes"/><tag k="uuid" v="{bfd3f222-8e04-4ddc-b201-476099761302}"/></node></osm>',
method: 'POST',
translation: 'TDSv61',
path: '/translateTo'
});
var xml = parser.parseFromString(output);
var gj = osmtogeojson(xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "TDSv61");
var tags = gj.features[0].properties;
assert.equal(tags["F_CODE"], "AL013");
assert.equal(tags["UFI"], "bfd3f222-8e04-4ddc-b201-476099761302");
}).timeout(3000);
it('should handle translateTo TDSv71 POST', function() {
var output = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="JOSM"><node id="-1" lon="-105.21811763904256" lat="39.35643172777992" version="0"><tag k="building" v="yes"/><tag k="uuid" v="{bfd3f222-8e04-4ddc-b201-476099761302}"/></node></osm>',
method: 'POST',
translation: 'TDSv71',
path: '/translateTo'
});
var xml = parser.parseFromString(output);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "TDSv71");
var tags = osmtogeojson(xml).features[0].properties;
assert.equal(tags["F_CODE"], "AL013");
assert.equal(tags["UFI"], "bfd3f222-8e04-4ddc-b201-476099761302");
}).timeout(3000);
it('should handle traslateTo TDSv61 POST with OSM Json payload', function() {
var output = server.handleInputs({
osm: '{"version":"0.6","generator":"CGImap 0.8.6 (1471352 spike-06.openstreetmap.org)", "copyright":"OpenStreetMap and contributors","attribution":"http://www.openstreetmap.org/copyright", "license":"http://opendatacommons.org/licenses/odbl/1-0/", "elements":[ {"type":"node","id":1831881213,"lat":54.0900666,"lon":12.2539381,"version":1, "user":"lafkor", "uid":"75625", "visible":"true", "timestamp":"2012-07-20T09:43:19Z", "tags": {"building": "yes"}} ]}',
method: 'POST',
translation: 'TDSv70',
path: '/translateTo'
})
var xml = parser.parseFromString(output);
var gj = osmtogeojson(xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "TDSv70");
var tags = gj.features[0].properties;
assert.equal(tags["F_CODE"], "AL013");
})
it('should handle translateTo TDSv70 POST', function() {
var output = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="JOSM"><node id="-1" lon="-105.21811763904256" lat="39.35643172777992" version="0"><tag k="building" v="yes"/><tag k="uuid" v="{bfd3f222-8e04-4ddc-b201-476099761302}"/></node></osm>',
method: 'POST',
translation: 'TDSv70',
path: '/translateTo'
});
var xml = parser.parseFromString(output);
var gj = osmtogeojson(xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "TDSv70");
var tags = gj.features[0].properties;
assert.equal(tags["F_CODE"], "AL013");
assert.equal(tags["UFI"], "bfd3f222-8e04-4ddc-b201-476099761302");
}).timeout(3000);
it('should handle translateTo POST and preserve bounds tag and ids', function() {
//http://localhost:8094/osmtotds
var osm2trans = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="JOSM"><bounds minlat="39.35643172777992" minlon="-105.21811763904256" maxlat="39.35643172777992" maxlon="-105.21811763904256" origin="" /><node id="777" lon="-105.21811763904256" lat="39.35643172777992" version="0"><tag k="building" v="yes"/><tag k="uuid" v="{bfd3f222-8e04-4ddc-b201-476099761302}"/></node></osm>',
method: 'POST',
translation: 'TDSv61',
path: '/translateTo'
});
xml2js.parseString(osm2trans, function(err, result) {
if (err) console.error(err);
assert.equal(result.osm.node[0].$.id, "777");
assert.equal(parseFloat(result.osm.bounds[0].$.minlat).toFixed(6), 39.356432);
assert.equal(parseFloat(result.osm.bounds[0].$.minlon).toFixed(6), -105.218118);
assert.equal(parseFloat(result.osm.bounds[0].$.maxlat).toFixed(6), 39.356432);
assert.equal(parseFloat(result.osm.bounds[0].$.maxlon).toFixed(6), -105.218118);
});
});
it('should handle translating way or node w/osm amenity=ferry_terminal to AQ080 (now for tdsv61 only)', function() {
var ferryWay = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="hootenanny"><way id="-3" version="0"><nd ref="-7"/><nd ref="-8"/><nd ref="-9"/><nd ref="-7"/><tag k="amenity" v="ferry_terminal"/></way></osm>',
method: 'POST',
translation: 'TDSv61',
path: '/translateTo'
})
xml2js.parseString(ferryWay, function(err, result) {
if (err) console.error(err);
assert(result.osm.way[0].tag[0].$.k, 'F_CODE')
assert(result.osm.way[0].tag[0].$.v, 'AQ080')
})
var ferryNode = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="hootenanny"><node id="-1" lon="33.731597320098885" lat="-24.919578904988793" version="0"><tag k="amenity" v="ferry_terminal"/></node></osm>',
method: 'POST',
translation: 'TDSv61',
path: '/translateTo'
})
xml2js.parseString(ferryNode, function(err, result) {
if (err) console.error(err);
assert(result.osm.node[0].tag[0].$.k, 'F_CODE')
assert(result.osm.node[0].tag[0].$.v, 'AQ080')
})
})
it('should handle OSM to MGCP POST of building area feature', function() {
var osm2trans = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="hootenanny"><way id="-1" version="0"><nd ref="-1"/><nd ref="-4"/><nd ref="-7"/><nd ref="-10"/><nd ref="-1"/><tag k="building" v="yes"/><tag k="uuid" v="{d7cdbdfe-88c6-4d8a-979d-ad88cfc65ef1}"/></way></osm>',
method: 'POST',
translation: 'MGCP',
path: '/translateTo'
});
xml2js.parseString(osm2trans, function(err, result) {
if (err) console.error(err);
assert.equal(result.osm.$.schema, "MGCP");
assert.equal(result.osm.way[0].tag[0].$.k, "FCODE");
assert.equal(result.osm.way[0].tag[0].$.v, "AL015");
assert.equal(result.osm.way[0].tag[1].$.k, "UID");
assert.equal(result.osm.way[0].tag[1].$.v, "D7CDBDFE-88C6-4D8A-979D-AD88CFC65EF1");
});
});
it('should handle OSM to TDSv61 Raw POST of a complete osm file and preserve bounds tag and element ids', function() {
var data = fs.readFileSync('../test-files/ToyTestA.osm', 'utf8');//, function(err, data) {
var osm2trans = server.handleInputs({
osm: data,
method: 'POST',
translation: 'TDSv61',
path: '/translateTo'
});
xml2js.parseString(osm2trans, function(err, result) {
if (err) console.error(err);
assert.equal(result.osm.$.schema, "TDSv61");
assert.equal(result.osm.bounds[0].$.minlat, "38.85324242720166");
assert.equal(result.osm.bounds[0].$.minlon, "-104.9024316099691");
assert.equal(result.osm.bounds[0].$.maxlat, "38.85496143739888");
assert.equal(result.osm.bounds[0].$.maxlon, "-104.8961823052624");
assert.equal(result.osm.way[0].$.id, "-1669801");
assert.equal(result.osm.way[0].nd[0].$.ref, "-1669731");
assert.equal(result.osm.way[0].nd[1].$.ref, "-1669791");
assert.equal(result.osm.way[0].nd[2].$.ref, "-1669793");
});
});
it('should be lossy to go from osm -> mgcp -> osm', function() {
var data = '<osm version="0.6" upload="true" generator="JOSM"><node id="-4" lon="-105.24014094121263" lat="39.28928610944744" version="0"><tag k="poi" v="yes"/><tag k="amenity" v="cafe"/><tag k="uuid" v="{4632d15b-7c44-4ba1-a0c4-8cfbb30e39d4}"/></node></osm>';
var mgcp_xml = server.handleInputs({
osm: data,
method: 'POST',
translation: 'MGCP',
path: '/translateTo'
});
var xml = parser.parseFromString(mgcp_xml);
var gj = osmtogeojson(xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "MGCP");
var tags = gj.features[0].properties;
assert.equal(tags["FCODE"], "AL015");
assert.equal(tags["FFN"], "572");
assert.equal(tags["HWT"], "998");
assert.equal(tags["UID"], "4632D15B-7C44-4BA1-A0C4-8CFBB30E39D4");
var osm_xml = server.handleInputs({
osm: mgcp_xml,
method: 'POST',
translation: 'MGCP',
path: '/translateFrom'
});
xml = parser.parseFromString(osm_xml);
gj = osmtogeojson(xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "OSM");
var tags = gj.features[0].properties;
assert.equal(tags["building"], "yes");
assert.equal(tags["amenity"], "restaurant");
assert.equal(tags["uuid"], "{4632d15b-7c44-4ba1-a0c4-8cfbb30e39d4}");
});
it('should translate from osm -> mgcp', function() {
var data = '<osm version="0.6" upload="true" generator="JOSM"><node id="-4" lon="-105.24014094121263" lat="39.28928610944744" version="0"><tag k="poi" v="yes"/><tag k="place" v="town"/><tag k="name" v="Manitou Springs"/><tag k="uuid" v="{4632d15b-7c44-4ba1-a0c4-8cfbb30e39d4}"/></node></osm>';
var mgcp_xml = server.handleInputs({
osm: data,
method: 'POST',
translation: 'MGCP',
path: '/translateTo'
});
var xml = parser.parseFromString(mgcp_xml);
var gj = osmtogeojson(xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "MGCP");
var tags = gj.features[0].properties;
assert.equal(tags["FCODE"], "AL020");
assert.equal(tags["NAM"], "Manitou Springs");
assert.equal(tags["UID"], "4632D15B-7C44-4BA1-A0C4-8CFBB30E39D4");
});
it ('translates multiple features in an OSM dataset', function() {
var osm2trans = server.handleInputs({
osm: '<osm version="0.6" generator="JOSM"><node id="-41300" action="modify" lat="39.28775629713" lon="-74.55540463462"/><node id="-41301" action="modify" lat="39.28766391666" lon="-74.55532148615"/><node id="-41302" action="modify" lat="39.28770588277" lon="-74.55524365216"/><node id="-41303" action="modify" lat="39.28779826318" lon="-74.55532680064"/><node id="-41306" action="modify" lat="39.28768156238" lon="-74.55568894878"/><node id="-41307" action="modify" lat="39.28766910658" lon="-74.5555467917"/><node id="-41308" action="modify" lat="39.28757547786" lon="-74.55556048652"/><node id="-41309" action="modify" lat="39.28758793368" lon="-74.5557026436"/><node id="-41312" action="modify" lat="39.28771270187" lon="-74.55567687884"/><node id="-41313" action="modify" lat="39.28771581582" lon="-74.55556824937"/><node id="-41314" action="modify" lat="39.28779720499" lon="-74.55557214409"/><node id="-41315" action="modify" lat="39.28779409104" lon="-74.55568077355"/><node id="-41318" action="modify" lat="39.28815176719" lon="-74.55595985189"/><node id="-41319" action="modify" lat="39.28800541239" lon="-74.55586195126"/><node id="-41321" action="modify" lat="39.28771477783" lon="-74.55583378807"/><node id="-41323" action="modify" lat="39.28744490181" lon="-74.5558740212"/><node id="-41325" action="modify" lat="39.28738677453" lon="-74.5556956543"/><node id="-41327" action="modify" lat="39.28747085147" lon="-74.55527320638"/><node id="-41329" action="modify" lat="39.28775837309" lon="-74.55493256584"/><node id="-41331" action="modify" lat="39.28811647599" lon="-74.55479040876"/><node id="-41347" action="modify" lat="39.28804589353" lon="-74.55582037702"/><node id="-41348" action="modify" lat="39.28798659571" lon="-74.55573682457"/><node id="-41350" action="modify" lat="39.28800356093" lon="-74.55572434074"/><node id="-41351" action="modify" lat="39.2880230383" lon="-74.55572260378"/><node id="-41352" action="modify" lat="39.2880411701" lon="-74.55573195772"/><node id="-41353" action="modify" lat="39.2880543651" lon="-74.55575054989"/><node id="-41354" action="modify" lat="39.28806000988" lon="-74.55577469788"/><node id="-41355" action="modify" lat="39.28805698641" lon="-74.5557996189"/><node id="-41356" action="modify" lat="39.28802892832" lon="-74.55583286085"/><node id="-41357" action="modify" lat="39.28800945095" lon="-74.55583459781"/><node id="-41358" action="modify" lat="39.28799131914" lon="-74.55582524388"/><node id="-41359" action="modify" lat="39.28797812413" lon="-74.55580665171"/><node id="-41360" action="modify" lat="39.28797247935" lon="-74.55578250371"/><node id="-41361" action="modify" lat="39.28797550282" lon="-74.5557575827"/><way id="-41304" action="modify"><nd ref="-41300"/><nd ref="-41303"/><nd ref="-41302"/><nd ref="-41301"/><nd ref="-41300"/><tag k="building" v="yes"/></way><way id="-41310" action="modify"><nd ref="-41306"/><nd ref="-41307"/><nd ref="-41308"/><nd ref="-41309"/><nd ref="-41306"/><tag k="building" v="yes"/></way><way id="-41316" action="modify"><nd ref="-41312"/><nd ref="-41315"/><nd ref="-41314"/><nd ref="-41313"/><nd ref="-41312"/><tag k="building" v="yes"/></way><way id="-41320" action="modify"><nd ref="-41318"/><nd ref="-41319"/><nd ref="-41321"/><nd ref="-41323"/><nd ref="-41325"/><nd ref="-41327"/><nd ref="-41329"/><nd ref="-41331"/><tag k="highway" v="tertiary"/></way></osm>',
method: 'POST',
translation: 'TDSv61',
path: '/translateTo'
});
xml2js.parseString(osm2trans, function(err, result) {
if (err) console.log(err)
// road
assert.equal(result.osm.way[0].tag[0].$.k, 'RIN_ROI')
assert.equal(result.osm.way[0].tag[0].$.v, '5')
assert.equal(result.osm.way[0].tag[1].$.k, 'F_CODE')
assert.equal(result.osm.way[0].tag[1].$.v, 'AP030')
assert.equal(result.osm.way[0].tag[2].$.k, 'OSMTAGS')
assert.equal(result.osm.way[0].tag[2].$.v, '{"highway":"tertiary"}')
assert.equal(result.osm.way[0].tag[3].$.k, 'ZI016_WTC')
assert.equal(result.osm.way[0].tag[3].$.v, '1')
assert.equal(result.osm.way[0].tag[4].$.k, 'RTY')
assert.equal(result.osm.way[0].tag[4].$.v, '3')
// buildings
assert.equal(result.osm.way[1].tag[0].$.k, 'F_CODE')
assert.equal(result.osm.way[1].tag[0].$.v, 'AL013')
assert.equal(result.osm.way[2].tag[0].$.k, 'F_CODE')
assert.equal(result.osm.way[2].tag[0].$.v, 'AL013')
assert.equal(result.osm.way[3].tag[0].$.k, 'F_CODE')
assert.equal(result.osm.way[3].tag[0].$.v, 'AL013')
});
});
it('include a non-translated feature if feature cannot be translated from OSM to TDSv61', function() {
var osm2trans = server.handleInputs({
osm: '<osm version="0.6" generator="JOSM"><node id="-41300" action="modify" lat="39.28775629713" lon="-74.55540463462"/><node id="-41301" action="modify" lat="39.28766391666" lon="-74.55532148615"/><node id="-41302" action="modify" lat="39.28770588277" lon="-74.55524365216"/><node id="-41303" action="modify" lat="39.28779826318" lon="-74.55532680064"/><node id="-41306" action="modify" lat="39.28768156238" lon="-74.55568894878"/><node id="-41307" action="modify" lat="39.28766910658" lon="-74.5555467917"/><node id="-41308" action="modify" lat="39.28757547786" lon="-74.55556048652"/><node id="-41309" action="modify" lat="39.28758793368" lon="-74.5557026436"/><node id="-41312" action="modify" lat="39.28771270187" lon="-74.55567687884"/><node id="-41313" action="modify" lat="39.28771581582" lon="-74.55556824937"/><node id="-41314" action="modify" lat="39.28779720499" lon="-74.55557214409"/><node id="-41315" action="modify" lat="39.28779409104" lon="-74.55568077355"/><node id="-41318" action="modify" lat="39.28815176719" lon="-74.55595985189"/><node id="-41319" action="modify" lat="39.28800541239" lon="-74.55586195126"/><node id="-41321" action="modify" lat="39.28771477783" lon="-74.55583378807"/><node id="-41323" action="modify" lat="39.28744490181" lon="-74.5558740212"/><node id="-41325" action="modify" lat="39.28738677453" lon="-74.5556956543"/><node id="-41327" action="modify" lat="39.28747085147" lon="-74.55527320638"/><node id="-41329" action="modify" lat="39.28775837309" lon="-74.55493256584"/><node id="-41331" action="modify" lat="39.28811647599" lon="-74.55479040876"/><node id="-41347" action="modify" lat="39.28804589353" lon="-74.55582037702"/><node id="-41348" action="modify" lat="39.28798659571" lon="-74.55573682457"/><node id="-41350" action="modify" lat="39.28800356093" lon="-74.55572434074"/><node id="-41351" action="modify" lat="39.2880230383" lon="-74.55572260378"/><node id="-41352" action="modify" lat="39.2880411701" lon="-74.55573195772"/><node id="-41353" action="modify" lat="39.2880543651" lon="-74.55575054989"/><node id="-41354" action="modify" lat="39.28806000988" lon="-74.55577469788"/><node id="-41355" action="modify" lat="39.28805698641" lon="-74.5557996189"/><node id="-41356" action="modify" lat="39.28802892832" lon="-74.55583286085"/><node id="-41357" action="modify" lat="39.28800945095" lon="-74.55583459781"/><node id="-41358" action="modify" lat="39.28799131914" lon="-74.55582524388"/><node id="-41359" action="modify" lat="39.28797812413" lon="-74.55580665171"/><node id="-41360" action="modify" lat="39.28797247935" lon="-74.55578250371"/><node id="-41361" action="modify" lat="39.28797550282" lon="-74.5557575827"/><way id="-41304" action="modify"><nd ref="-41300"/><nd ref="-41303"/><nd ref="-41302"/><nd ref="-41301"/><nd ref="-41300"/><tag k="building" v="yes"/></way><way id="-41310" action="modify"><nd ref="-41306"/><nd ref="-41307"/><nd ref="-41308"/><nd ref="-41309"/><nd ref="-41306"/><tag k="building" v="yes"/></way><way id="-41316" action="modify"><nd ref="-41312"/><nd ref="-41315"/><nd ref="-41314"/><nd ref="-41313"/><nd ref="-41312"/><tag k="building" v="yes"/></way><way id="-41320" action="modify"><nd ref="-41318"/><nd ref="-41319"/><nd ref="-41321"/><nd ref="-41323"/><nd ref="-41325"/><nd ref="-41327"/><nd ref="-41329"/><nd ref="-41331"/><tag k="highway" v="tertiary"/></way><way id="-38983" visible="true"><nd ref="-38979" /><nd ref="-38982" /><nd ref="-38986" /><nd ref="-38979" /><tag k="natural" v="tree" /><tag k="security:classification" v="UNCLASSIFIED" /><tag k="source" v="Unknown" /></way></osm>',
method: 'POST',
translation: 'TDSv61',
path: '/translateTo'
});
xml2js.parseString(osm2trans, function(err, result) {
if (err) console.log(err)
// tree that cannot be translated...
assert.equal(result.osm.way[4].tag[0].$.k, 'error')
assert.equal(result.osm.way[4].tag[0].$.v, 'Line geometry is not valid for EC005 in TDSv61')
})
});
it('should handle tdstoosm POST of facility area feature', function() {
var trans2osm = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="hootenanny"><way id="-6" version="0"><nd ref="-13"/><nd ref="-14"/><nd ref="-15"/><nd ref="-16"/><nd ref="-13"/><tag k="UID" v="fee4529b-5ecc-4e5c-b06d-1b26a8e830e6"/><tag k="FCODE" v="AL010"/><tag k="SDP" v="D"/></way></osm>',
method: 'POST',
translation: 'MGCP',
path: '/translateFrom'
});
var output = xml2js.parseString(trans2osm, function(err, result) {
if (err) console.error(err);
assert.equal(result.osm.way[0].tag[0].$.k, "source");
assert.equal(result.osm.way[0].tag[0].$.v, "D");
assert.equal(result.osm.way[0].tag[2].$.k, "uuid");
assert.equal(result.osm.way[0].tag[2].$.v, "{fee4529b-5ecc-4e5c-b06d-1b26a8e830e6}");
assert.equal(result.osm.way[0].tag[3].$.k, "facility");
assert.equal(result.osm.way[0].tag[3].$.v, "yes");
assert.equal(result.osm.way[0].tag[1].$.k, "area");
assert.equal(result.osm.way[0].tag[1].$.v, "yes");
});
});
it('should return error message for invalid F_CODE/geom combination in translateTo POST', function() {
var output = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="hootenanny"><node id="-24" lon="9.305143094234467" lat="41.65140640721789" version="0"><tag k="leisure" v="park"/><tag k="source" v="DigitalGlobe"/><tag k="source:imagery:sensor" v="WV02"/><tag k="source:imagery:id" v="756b80e1f695fb591caca8e7ce0f9ef5"/><tag k="source:imagery:datetime" v="2017-11-11 10:45:15"/><tag k="security:classification" v="UNCLASSIFIED"/></node></osm>',
method: 'POST',
translation: 'MGCP',
path: '/translateTo'
});
var xml = parser.parseFromString(output);
var gj = osmtogeojson(xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "MGCP");
var tags = gj.features[0].properties;
assert.equal(tags["error"], 'Point geometry is not valid for AK120 in MGCP TRD4');
});
it('should handle bad translation schema value in translateTo POST', function() {
assert.throws(function error() {
var osm2trans = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="JOSM"><node id="-1" lon="-105.21811763904256" lat="39.35643172777992" version="0"><tag k="building" v="yes"/><tag k="uuid" v="{bfd3f222-8e04-4ddc-b201-476099761302}"/></node></osm>',
method: 'POST',
translation: 'TDv61',
path: '/translateTo'
});
}, Error, 'Unsupported translation schema');
});
it('should handle translateFrom POST', function() {
var trans2osm = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="JOSM"><node id="-9" lon="-104.907037158172" lat="38.8571566428667" version="0"><tag k="ACC" v="1"/><tag k="BAC" ve="0"/><tag k="CCN" v="UNK"/><tag k="FCODE" v="AL020"/><tag k="FUC" v="999"/><tag k="FUN" v="0"/><tag k="NAM" v="Manitou Springs"/><tag k="NFI" v="UNK"/><tag k="NFN" v="UNK"/><tag k="ORD" v="0"/><tag k="SDP" v="N_A"/><tag k="SDV" v="UNK"/><tag k="SRT" v="0"/><tag k="TXT" v="<OSM>{"poi":"yes"}</OSM>"/><tag k="UID" v="c6df0618-ce96-483c-8d6a-afa33541646c"/></node></osm>',
method: 'POST',
translation: 'MGCP',
path: '/translateFrom'
});
// NOTE: The translator now sends back unknown & N_A values
var output = xml2js.parseString(trans2osm, function(err, result) {
if (err) console.error(err);
assert.equal(result.osm.node[0].tag[4].$.k, "use");
assert.equal(result.osm.node[0].tag[4].$.v, "other");
assert.equal(result.osm.node[0].tag[6].$.k, "place");
assert.equal(result.osm.node[0].tag[6].$.v, "yes");
assert.equal(result.osm.node[0].tag[5].$.k, "poi");
assert.equal(result.osm.node[0].tag[5].$.v, "yes");
assert.equal(result.osm.node[0].tag[3].$.k, "uuid");
assert.equal(result.osm.node[0].tag[3].$.v, "{c6df0618-ce96-483c-8d6a-afa33541646c}");
assert.equal(result.osm.node[0].tag[2].$.k, "name");
assert.equal(result.osm.node[0].tag[2].$.v, "Manitou Springs");
assert.equal(result.osm.node[0].tag[1].$.k, "landuse");
assert.equal(result.osm.node[0].tag[1].$.v, "built_up_area");
assert.equal(result.osm.node[0].tag[0].$.k, "source:accuracy:horizontal:category");
assert.equal(result.osm.node[0].tag[0].$.v, "accurate");
});
});
it('should untangle MGCP tags', function() {
var trans2osm = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="hootenanny"><way id="-1" version="0"><nd ref="-1"/><nd ref="-4"/><nd ref="-7"/><nd ref="-10"/><nd ref="-1"/><tag k="FCODE" v="AL013"/><tag k="levels" v="3"/>/></way></osm>',
method: 'POST',
translation: 'MGCP',
path: '/translateFrom'
});
xml2js.parseString(trans2osm, function(err, result) {
if (err) console.error(err);
assert.equal(result.osm.way[0].tag[0].$.k, "levels");
assert.equal(result.osm.way[0].tag[0].$.v, "3");
assert.equal(result.osm.way[0].tag[1].$.k, "building");
assert.equal(result.osm.way[0].tag[1].$.v, "yes");
});
});
it('should untangle TDSv61 tags', function() {
var trans2osm = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="hootenanny"><way id="-1" version="0"><nd ref="-1"/><nd ref="-4"/><nd ref="-7"/><nd ref="-10"/><nd ref="-1"/><tag k="AL013" v="building"/><tag k="levels" v="3"/>/></way></osm>',
method: 'POST',
translation: 'TDSv61',
path: '/translateFrom'
});
xml2js.parseString(trans2osm, function(err, result) {
if (err) console.error(err);
assert.equal(result.osm.way[0].tag[0].$.k, "levels");
assert.equal(result.osm.way[0].tag[0].$.v, "3");
assert.equal(result.osm.way[0].tag[1].$.k, "building");
assert.equal(result.osm.way[0].tag[1].$.v, "yes");
});
});
it('should untangle TDSv40 tags', function() {
var trans2osm = server.handleInputs({
osm: '<osm version="0.6" upload="true" generator="hootenanny"><way id="-1" version="0"><nd ref="-1"/><nd ref="-4"/><nd ref="-7"/><nd ref="-10"/><nd ref="-1"/><tag k="AL013" v="building"/><tag k="levels" v="3"/>/></way></osm>',
method: 'POST',
translation: 'TDSv40',
path: '/translateFrom'
});
xml2js.parseString(trans2osm, function(err, result) {
if (err) console.error(err);
assert.equal(result.osm.way[0].tag[0].$.k, "levels");
assert.equal(result.osm.way[0].tag[0].$.v, "3");
assert.equal(result.osm.way[0].tag[1].$.k, "building");
assert.equal(result.osm.way[0].tag[1].$.v, "yes");
});
});
it('should handle /capabilities GET', function() {
var capas = server.handleInputs({
method: 'GET',
path: '/capabilities'
});
assert.equal(capas.TDSv71.isavailable, true);
assert.equal(capas.TDSv70.isavailable, true);
assert.equal(capas.TDSv61.isavailable, true);
assert.equal(capas.TDSv40.isavailable, true);
assert.equal(capas.MGCP.isavailable, true);
assert.equal(capas.GGDMv30.isavailable, true);
});
it('should handle /translations GET', function() {
var trans = server.handleInputs({
method: 'GET',
path: '/translations'
});
// NOTE: This allows the test to pass if/when translations from "translations-local" are added
// assert.equal(trans.length,5);
assert.ok(trans.length >= 5);
});
it('should handle /schema GET', function() {
//http://localhost:8094/schema?geometry=point&translation=MGCP&searchstr=Buil&maxlevdst=20&limit=12
var schm = server.handleInputs({
geometry: 'line',
translation: 'TDSv40',
searchstr: 'river',
maxLeinDistance: 20,
limit: 12,
method: 'GET',
path: '/schema'
});
assert.equal(schm[0].name, 'RIVER_C');
assert.equal(schm[0].fcode, 'BH140');
assert.equal(schm[0].desc, 'River');
});
it('should handle /schema GET', function() {
var schm = server.handleInputs({
geometry: 'line',
translation: 'TDSv71',
searchstr: 'river',
maxLeinDistance: 20,
limit: 12,
method: 'GET',
path: '/schema'
});
assert.equal(schm[0].name, 'RIVER_C');
assert.equal(schm[0].fcode, 'BH140');
assert.equal(schm[0].desc, 'River');
});
//Checking the use of limit param
it('should handle /schema GET', function() {
var schm = server.handleInputs({
geometry: 'line',
translation: 'TDSv40',
searchstr: 'river',
maxleindst: 10,
limit: 1,
method: 'GET',
path: '/schema'
});
assert.equal(schm.length, 1);
});
it('should handle /schema GET', function() {
var schm = server.handleInputs({
geometry: 'Line',
translation: 'TDSv40',
searchstr: 'ri',
maxleindst: 200,
limit: 33,
method: 'GET',
path: '/schema'
});
assert.equal(schm.length, 8);
});
it('should handle /schema GET', function() {
var schm = server.handleInputs({
geometry: 'line',
translation: 'TDSv40',
searchstr: 'ri',
maxleindst: 50,
limit: 100,
method: 'GET',
path: '/schema'
});
assert(schm.length <= 100, 'Schema search results greater than requested');
});
//Checking the use of limit param with no search string
it('should handle /schema GET', function() {
var schm = server.handleInputs({
geometry: 'line',
translation: 'TDSv40',
searchstr: '',
maxleindst: 10,
limit: 1,
method: 'GET',
path: '/schema'
});
assert.equal(schm.length, 1);
});
it('should handle /schema GET', function() {
var schm = server.handleInputs({
geometry: 'point',
translation: 'TDSv61',
searchstr: '',
limit: 33,
method: 'GET',
path: '/schema'
});
assert.equal(schm.length, 33);
});
it('should handle /schema GET', function() {
var schm = server.handleInputs({
geometry: 'line',
translation: 'MGCP',
searchstr: '',
maxlevdst: 0, //This shouldn't be used when searchstr is ''
limit: 100,
method: 'GET',
path: '/schema'
});
assert(schm.length <= 100, 'Schema search results greater than requested');
assert(schm.some(function(d) {
return d.desc === 'Railway';
}));
});
it('should handle /schema GET', function() {
var schm = server.handleInputs({
geometry: 'line',
translation: 'GGDMv30',
searchstr: '',
maxlevdst: 0, //This shouldn't be used when searchstr is ''
limit: 100,
method: 'GET',
path: '/schema'
});
assert(schm.length <= 100, 'Schema search results greater than requested');
assert(schm.some(function(d) {
return d.desc === 'Railway';
}));
});
it('throws error if url not found', function() {
assert.throws(function error() {
server.handleInputs({
idval: 'AL015',
geom: 'Point',
translation: 'TDSv40',
idelem: 'fcode',
method: 'GET',
path: '/foo'
})
}, Error, 'Not found');
});
it('throws error if unsupported method', function() {
assert.throws(function error() {
server.handleInputs({
method: 'POST',
path: '/schema'
})
}, Error, 'Unsupported method');
});
it('throws error if unsupported method', function() {
assert.throws(function error() {
server.handleInputs({
method: 'POST',
path: '/capabilities'
})
}, Error, 'Unsupported method');
});
});
describe('capabilities', function () {
it('should return 200', function (done) {
var request = httpMocks.createRequest({
method: 'GET',
url: '/capabilities'
});
var response = httpMocks.createResponse();
server.TranslationServer(request, response);
assert.equal(response.statusCode, '200');
done();
});
});
describe('schema', function () {
it('should return 200', function (done) {
var request = httpMocks.createRequest({
method: 'GET',
url: '/schema',
params: {
geometry: 'point',
translation: 'MGCP',
searchstr: 'Buil',
maxlevdst: 20,
limit: 12
}
});
var response = httpMocks.createResponse();
server.TranslationServer(request, response);
assert.equal(response.statusCode, '200');
done();
});
});
describe('translateTo', function () {
it('should return 200', function (done) {
var request = httpMocks.createRequest({
method: 'GET',
url: '/translateTo',
params: {
value: 'AP030',
translation: 'MGCP',
geom: 'Line',
key: 'fcode'
}
});
var response = httpMocks.createResponse();
server.TranslationServer(request, response);
assert.equal(response.statusCode, '200');
done();
});
});
describe('translateFrom', function () {
it('should return 200 with fcode and translation', function (done) {
var request = httpMocks.createRequest({
method: 'GET',
url: '/translateFrom',
params: {
fcode: 'AL013',
translation: 'TDSv61'
}
});
var response = httpMocks.createResponse();
server.TranslationServer(request, response);
assert.equal(response.statusCode, '200');
done();
});
it('should return 200 with fcode, geom and translation', function (done) {
var request = httpMocks.createRequest({
method: 'GET',
url: '/translateFrom',
params: {
fcode: 'AL013',
geom: 'Area',
translation: 'MGCP'
}
});
var response = httpMocks.createResponse();
server.TranslationServer(request, response);
assert.equal(response.statusCode, '200');
done();
});
it('drop default tags by default', function(done) {
var osm = server.handleInputs({
translation: 'MGCP',
method: 'POST',
path: '/translateFrom',
osm: "<osm version='0.6' generator='JOSM'><node id='-161534' lat='38.9078407955' lon='-77.03267545044'><tag k='FCODE' v='AL015' /> <tag k='CCN' v='UNK' /></node></osm>"
});
xml2js.parseString(osm, function(err, result) {
assert.equal(result.osm.node[0].tag[0].$.k, 'building')
assert.equal(result.osm.node[0].tag[0].$.v, 'yes')
assert.equal(result.osm.node[0].tag.length, 1)
})
var osm = server.handleInputs({
translation: 'MGCP',
method: 'POST',
path: '/translateFrom',
dropDefaults: 'false',
osm: "<osm version='0.6' generator='JOSM'><node id='-161533' lat='38.9078407955' lon='-77.03267545044'><tag k='FCODE' v='AL015' /> <tag k='CCN' v='UNK' /></node></osm>"
});
xml2js.parseString(osm, function(err, result) {
assert.equal(result.osm.node[0].tag[0].$.k, 'source:copyright')
assert.equal(result.osm.node[0].tag[0].$.v, 'UNK')
assert.equal(result.osm.node[0].tag[1].$.k, 'building')
assert.equal(result.osm.node[0].tag[1].$.v, 'yes')
assert.equal(result.osm.node[0].tag.length, 2)
})
var osm = server.handleInputs({
translation: 'MGCP',
method: 'POST',
path: '/translateFrom',
dropDefaults: 'true',
osm: "<osm version='0.6' generator='JOSM'><node id='-161534' lat='38.9078407955' lon='-77.03267545044'><tag k='FCODE' v='AL015' /> <tag k='CCN' v='UNK' /></node></osm>"
});
xml2js.parseString(osm, function(err, result) {
assert.equal(result.osm.node[0].tag[0].$.k, 'building')
assert.equal(result.osm.node[0].tag[0].$.v, 'yes')
assert.equal(result.osm.node[0].tag.length, 1)
done()
})
})
});
describe('supportedGeometries', function() {
it ('replies supported geometries for provided feature code', function() {
var baseParams = {
method: 'GET',
path: '/supportedGeometries',
}
var tds61Building = Object.assign(baseParams, { translation: 'TDSv61', fcode: 'AL013' });
assert.deepEqual(server.handleInputs(tds61Building), ['Point', 'Area']);
var tds40Wall = Object.assign(baseParams, { translation: 'TDSv40', fcode: 'AL260' })
assert.deepEqual(server.handleInputs(tds40Wall), [ 'Line' ]);
var mgcpFord = Object.assign(baseParams, { translation: 'MGCP', fcode: 'BH070' });
assert.deepEqual(server.handleInputs(mgcpFord), [ 'Line', 'Point' ]);
var ggdm30Tower = Object.assign(baseParams, { translation: 'GGDMv30' , fcode: 'AL241'})
assert.deepEqual(server.handleInputs(ggdm30Tower), [ 'Point', 'Area' ]);
})
});
describe('not found', function () {
it('should return 404', function (done) {
var request = httpMocks.createRequest({
method: 'GET',
url: '/foo',
params: {
fcode: 'AL013',
translation: 'TDSv61'
}
});
var response = httpMocks.createResponse();
server.TranslationServer(request, response);
assert.equal(response.statusCode, '404');
done();
});
});
describe('getLein', function() {
it('should return I251 for installation, I213 for intall, M313 for military',
function() {
var leinIntall = server.getLein('intall'),
leinInstallation = server.getLein('installation'),
leinMilitary = server.getLein('military');
assert.equal(leinIntall.toLowerCase(), 'i213');
assert.equal(leinInstallation.toLowerCase(), 'i251');
assert.equal(leinMilitary.toLowerCase(), 'm313');
}
)
})
describe('getIntendedKeys', function() {
it('should return ["a", "x", "s"] when provided "z"', function() {
var intendedKeys = server.getIntendedKeys('z');
assert.equal(intendedKeys[0], 'a')
assert.equal(intendedKeys[1], 'x')
assert.equal(intendedKeys[2], 's')
});