Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 38 additions & 50 deletions tests/unit/test.mapreduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,51 @@ 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', function () {
return upsert({
get: function () {
return Promise.reject(new Error('a fake error!'));
}
}, 'foo')
.then(function () {
it('should throw an error if the doc errors', async function () {
try {
await upsert({
get: () => Promise.reject(new Error('a fake error!')),
}, 'foo');

should.fail("Expected promise to be rejected");
})
.catch(function (err) {
} catch (err) {
err.message.should.equal("a fake error!");
});
}
});
it('should fulfill if the diff returns false', function () {
return upsert({
get: function () {
return Promise.resolve({ _rev: 'xyz' });
}
}, 'foo', function () {
return false;
}).then(function (res) {
res.updated.should.equal(false);
res.rev.should.equal('xyz');
});

it('should fulfill if the diff returns false', async function () {
const res = await upsert({
get: () => Promise.resolve({ _rev: 'xyz' }),
}, 'foo', () => false
);

res.updated.should.equal(false);
res.rev.should.equal('xyz');
});
it('should put if get throws 404', function () {
return upsert({
get: function () {
return Promise.reject({ status: 404 });
},
put: function () {
return Promise.resolve({ rev: 'abc' });
}
}, 'foo', function () {
return { difference: "something" };
}).then(function (res) {
res.updated.should.equal(true);
res.rev.should.equal('abc');
});

it('should put if get throws 404', async function () {
const res = await upsert({
get: () => Promise.reject({ status: 404 }),
put: () => Promise.resolve({ rev: 'abc' }),
}, 'foo', () => ({ difference: "something" })
);

res.updated.should.equal(true);
res.rev.should.equal('abc');
});
it('should error if it can\'t put', function () {
return upsert({
get: function () {
return Promise.resolve({ _rev: 'xyz' });
},
put: function () {
return Promise.reject(new Error('falala'));
}
}, 'foo', function () {
return { difference: "something" };
})
.then(function () {

it('should error if it can\'t put', async function () {
try {
await upsert({
get: () => Promise.resolve({ _rev: 'xyz' }),
put: () => Promise.reject(new Error('falala')),
}, 'foo', () => ({ difference: "something" })
);

should.fail("Expected promise to be rejected");
})
.catch(function (err) {
} catch (err) {
err.message.should.equal("falala");
});
}
});
});

Expand Down