UNPKG

2.8 kBJavaScriptView Raw
1
2var extractor = require('../extractor/put');
3var fixtures = require('./fixtures/_index');
4
5module.exports.extractor = {};
6
7module.exports.extractor.invalidPut = 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.respFail = function(test, common) {
32 test('resp: respFail', function(t) {
33 var proxy = extractor( function( err, resp ){
34 t.equal(err, undefined, 'no error emitted');
35 t.equal(resp, false, 'put operation failed');
36 t.end();
37 });
38 t.equal(typeof proxy, 'function', 'function returned');
39 proxy(); // no hits
40 });
41 test('resp: respFail', function(t) {
42 var proxy = extractor( function( err, resp ){
43 t.equal(err, undefined, 'no error emitted');
44 t.equal(resp, false, 'put operation failed');
45 t.end();
46 });
47 t.equal(typeof proxy, 'function', 'function returned');
48 proxy( undefined, { created: false } ); // fail
49 });
50}
51
52module.exports.extractor.respSuccess = function(test, common) {
53 test('resp: respSuccess', function(t) {
54 var proxy = extractor( function( err, resp ){
55 t.equal(err, undefined, 'no error emitted');
56 t.equal(typeof resp, 'object', 'put operation success');
57 t.equal(resp._id, '1', 'field returned');
58 t.equal(resp._index, 'delme', 'field returned');
59 t.equal(resp._type, 'tweet', 'field returned');
60 t.end();
61 });
62 t.equal(typeof proxy, 'function', 'function returned');
63 proxy( null, fixtures.put );
64 });
65}
66
67module.exports.extractor.genericFailure = function(test, common) {
68 test('resp: genericFailure', function(t) {
69 var proxy = extractor( function( err, resp ){
70 t.equal(err, fixtures.genericfail.error, 'error emitted');
71 t.equal(resp, undefined, 'no results returned');
72 t.end();
73 });
74 t.equal(typeof proxy, 'function', 'function returned');
75 proxy( null, fixtures.genericfail );
76 });
77}
78
79module.exports.all = function (tape, common) {
80
81 function test(name, testFunction) {
82 return tape('put extractor: ' + name, testFunction)
83 }
84
85 for( var testCase in module.exports.extractor ){
86 module.exports.extractor[testCase](test, common);
87 }
88}
\No newline at end of file