UNPKG

3.16 kBJavaScriptView Raw
1
2var extractor = require('../extractor/mget');
3var fixtures = require('./fixtures/_index');
4
5module.exports.extractor = {};
6
7module.exports.extractor.invalidMget = function(test, common) {
8 test('constructor: invalidCallback', function(t) {
9 var proxy = extractor();
10 t.equal(typeof proxy, 'function', 'function returned');
11 try { proxy(); }
12 catch (e){
13 t.equal(e.message, 'undefined is not a function', 'exception thrown');
14 t.end();
15 }
16 });
17}
18
19module.exports.extractor.respEmitsError = function(test, common) {
20 test('resp: emitsError', function(t) {
21 var proxy = extractor( function( err, resp ){
22 t.equal(typeof err, 'string', 'error emitted');
23 t.equal(err, 'an upstream error', err);
24 t.end();
25 });
26 t.equal(typeof proxy, 'function', 'function returned');
27 proxy( 'an upstream error' ); // upstream error
28 });
29}
30
31module.exports.extractor.respNoHits = function(test, common) {
32 test('resp: respNoHits', function(t) {
33 var proxy = extractor( function( err, resp ){
34 t.equal(err, undefined, 'no error emitted');
35 t.equal(resp, undefined, 'no result returned');
36 t.end();
37 });
38 t.equal(typeof proxy, 'function', 'function returned');
39 proxy(); // no hits
40 });
41}
42
43module.exports.extractor.respContainedSomeMissedGets = function(test, common) {
44 test('resp: respGotHits', function(t) {
45 var proxy = extractor( function( err, resp ){
46 t.equal(err, 'one or more node ids not found', 'no error emitted');
47 t.end();
48 });
49 t.equal(typeof proxy, 'function', 'function returned');
50 proxy( null, fixtures.failedmget );
51 });
52}
53
54// Matched all mget
55module.exports.extractor.respCompletedSuccessfully = function(test, common) {
56 test('resp: respGotHits', function(t) {
57 var proxy = extractor( function( err, resp ){
58 t.equal(err, undefined, 'no error emitted');
59 t.equal(Array.isArray(resp), true, 'array returned');
60 t.equal(resp.length, 19, 'array contains 1 record');
61 t.equal(resp[0]._id, '34034714', 'field returned');
62 t.equal(resp[0]._index, 'pelias', 'field returned');
63 t.equal(resp[0]._type, 'osmnode', 'field returned');
64 t.equal(resp[0].type, 'node', 'field returned');
65 t.equal(resp[0].center_point.lat, 33.5060419, 'field returned');
66 t.equal(resp[0].center_point.lon, 36.2884532, 'field returned');
67 t.end();
68 });
69 t.equal(typeof proxy, 'function', 'function returned');
70 proxy( null, fixtures.mget );
71 });
72}
73
74module.exports.extractor.genericFailure = function(test, common) {
75 test('resp: genericFailure', function(t) {
76 var proxy = extractor( function( err, resp ){
77 t.equal(err, fixtures.genericfail.error, 'error emitted');
78 t.equal(resp, undefined, 'no results returned');
79 t.end();
80 });
81 t.equal(typeof proxy, 'function', 'function returned');
82 proxy( null, fixtures.genericfail );
83 });
84}
85
86module.exports.all = function (tape, common) {
87
88 function test(name, testFunction) {
89 return tape('mget extractor: ' + name, testFunction)
90 }
91
92 for( var testCase in module.exports.extractor ){
93 module.exports.extractor[testCase](test, common);
94 }
95}
\No newline at end of file