Skip to content
Draft
Changes from 1 commit
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
116 changes: 67 additions & 49 deletions tests/unit/test.mapreduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,81 @@ 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(
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a style nit, but I’d be okay with having the opening curlies start with the method: upsert({ to save a mostly empty line

get: function () {
return 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 put if get throws 404', function () {
return upsert({
get: function () {
return Promise.reject({ status: 404 });

it('should fulfill if the diff returns false', async function () {
const res = await upsert(
{
get: function () {
return Promise.resolve({ _rev: 'xyz' });
},
},
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');
});
'foo',
function () {
return false;
},
);

res.updated.should.equal(false);
res.rev.should.equal('xyz');
});
it('should error if it can\'t put', function () {
return upsert({
get: function () {
return Promise.resolve({ _rev: '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" };
},
put: function () {
return Promise.reject(new Error('falala'));
}
}, 'foo', function () {
return { difference: "something" };
})
.then(function () {
);

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(function (err) {
} catch (err) {
err.message.should.equal("falala");
});
}
});
});

Expand Down
Loading