feathers-service-tests
Version:
A standardized testing harness for Feathers services
89 lines (73 loc) • 3.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = orm;
var _chai = require('chai');
function orm(people, errors) {
var idProp = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'id';
describe('Feathers ORM Common Tests', function () {
it('wraps an ORM error in a feathers error', function () {
return people.create({}).catch(function (error) {
(0, _chai.expect)(error instanceof errors.FeathersError).to.be.ok;
});
});
describe('Raw/Lean Queries', function () {
var _ids = {};
var _data = {};
beforeEach(function () {
return people.create({
name: 'Doug',
age: 32
}).then(function (data) {
_data.Doug = data;
_ids.Doug = data[idProp];
});
});
afterEach(function () {
return people.remove(_ids.Doug).catch(function () {});
});
function noPOJO() {
// The prototype objects are huge and cause node to hang
// when the reporter tries to log the errors to the console.
throw new Error('The expected result was not a POJO.');
}
it('returns POJOs for find()', function () {
return people.find({}).then(function (results) {
return (0, _chai.expect)(Object.getPrototypeOf(results[0])).to.equal(Object.prototype);
}).catch(noPOJO);
});
it('returns a POJO for get()', function () {
return people.get(_ids.Doug).then(function (result) {
return (0, _chai.expect)(Object.getPrototypeOf(result)).to.equal(Object.prototype);
}).catch(noPOJO);
});
it('returns a POJO for create()', function () {
return people.create({ name: 'Sarah', age: 30 }).then(function (result) {
return (0, _chai.expect)(Object.getPrototypeOf(result)).to.equal(Object.prototype);
}).catch(noPOJO);
});
it('returns POJOs for bulk create()', function () {
return people.create([{ name: 'Sarah', age: 30 }]).then(function (result) {
return (0, _chai.expect)(Object.getPrototypeOf(result[0])).to.equal(Object.prototype);
}).catch(noPOJO);
});
it('returns a POJO for patch()', function () {
return people.patch(_ids.Doug, { name: 'Sarah' }).then(function (result) {
return (0, _chai.expect)(Object.getPrototypeOf(result)).to.equal(Object.prototype);
}).catch(noPOJO);
});
it('returns a POJO for update()', function () {
return people.update(_ids.Doug, Object.assign(_data.Doug, { name: 'Sarah' })).then(function (result) {
return (0, _chai.expect)(Object.getPrototypeOf(result)).to.equal(Object.prototype);
}).catch(noPOJO);
});
it('returns a POJO for remove()', function () {
return people.remove(_ids.Doug).then(function (result) {
return (0, _chai.expect)(Object.getPrototypeOf(result)).to.equal(Object.prototype);
}).catch(noPOJO);
});
});
});
} /* eslint-disable no-unused-expressions */
module.exports = exports['default'];