UNPKG

2.7 kBJavaScriptView Raw
1
2var extractor = require('../extractor/get');
3var fixtures = require('./fixtures/_index');
4
5module.exports.extractor = {};
6
7module.exports.extractor.invalidSearch = 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
43// Returned single result
44module.exports.extractor.respGotHit = function(test, common) {
45 test('resp: respGotHits', function(t) {
46 var proxy = extractor( function( err, resp ){
47 t.equal(err, undefined, 'no error emitted');
48 t.equal(typeof resp, 'object', 'object returned');
49 t.equal(resp._id, '551215562', 'field returned');
50 t.equal(resp._index, 'pelias', 'field returned');
51 t.equal(resp._type, 'osmnode', 'field returned');
52 t.equal(resp.type, 'node', 'field returned');
53 t.equal(resp.center_point.lat, 33.5169579, 'field returned');
54 t.equal(resp.center_point.lon, 36.2217176, 'field returned');
55 t.end();
56 });
57 t.equal(typeof proxy, 'function', 'function returned');
58 proxy( null, fixtures.get );
59 });
60}
61
62module.exports.extractor.genericFailure = function(test, common) {
63 test('resp: genericFailure', function(t) {
64 var proxy = extractor( function( err, resp ){
65 t.equal(err, fixtures.genericfail.error, 'error emitted');
66 t.equal(resp, undefined, 'no results returned');
67 t.end();
68 });
69 t.equal(typeof proxy, 'function', 'function returned');
70 proxy( null, fixtures.genericfail );
71 });
72}
73
74module.exports.all = function (tape, common) {
75
76 function test(name, testFunction) {
77 return tape('search extractor: ' + name, testFunction)
78 }
79
80 for( var testCase in module.exports.extractor ){
81 module.exports.extractor[testCase](test, common);
82 }
83}
\No newline at end of file