-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathtest.mapreduce.js
More file actions
114 lines (100 loc) · 2.67 KB
/
test.mapreduce.js
File metadata and controls
114 lines (100 loc) · 2.67 KB
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
'use strict';
var should = require('chai').should();
var PouchDB = require('../../packages/node_modules/pouchdb-for-coverage');
var upsert = PouchDB.utils.upsert;
var utils = PouchDB.utils.mapReduceUtils;
describe('test.mapreduce.js-upsert', function () {
it('should throw an error if the doc errors', async function () {
try {
await upsert(
{
get: function () {
return Promise.reject(new Error('a fake error!'));
},
},
'foo',
);
should.fail("Expected promise to be rejected");
} catch (err) {
err.message.should.equal("a fake error!");
}
});
it('should fulfill if the diff returns false', async function () {
const res = await upsert(
{
get: function () {
return Promise.resolve({ _rev: 'xyz' });
},
},
'foo',
function () {
return false;
},
);
res.updated.should.equal(false);
res.rev.should.equal('xyz');
});
it('should put if get throws 404', async function () {
const res = await upsert(
{
get: function () {
return Promise.reject({ status: 404 });
},
put: function () {
return Promise.resolve({ rev: 'abc' });
},
},
'foo',
function () {
return { difference: "something" };
},
);
res.updated.should.equal(true);
res.rev.should.equal('abc');
});
it('should error if it can\'t put', async function () {
try {
await upsert(
{
get: function () {
return Promise.resolve({ _rev: 'xyz' });
},
put: function () {
return Promise.reject(new Error('falala'));
},
},
'foo',
function () {
return { difference: "something" };
},
);
should.fail("Expected promise to be rejected");
} catch (err) {
err.message.should.equal("falala");
}
});
});
describe('test.mapreduce.js-utils', function () {
it('callbackify should work with a callback', function (done) {
function fromPromise() {
return Promise.resolve(true);
}
utils.callbackify(fromPromise)(function (err, resp) {
should.not.exist(err);
should.exist(resp);
done();
});
});
it('fin should work without returning a function and it resolves',
function () {
return utils.fin(Promise.resolve(), function () {
return Promise.resolve();
}).should.be.fullfilled;
});
it('fin should work without returning a function and it rejects',
function () {
return utils.fin(Promise.reject(), function () {
return Promise.resolve();
}).should.be.rejected;
});
});