Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Commit

Permalink
Update ORM tests to ensure plain objects are returned
Browse files Browse the repository at this point in the history
  • Loading branch information
DesignByOnyx committed May 2, 2017
1 parent 7f786c6 commit 3124a09
Showing 1 changed file with 64 additions and 3 deletions.
67 changes: 64 additions & 3 deletions src/orm-tests.js
Expand Up @@ -2,12 +2,73 @@

import { expect } from 'chai';

export default function orm (people, _ids, errors) {
describe('Feathers ORM Specific Tests', () => {
export default function orm (people, errors, idProp = 'id') {
describe('Feathers ORM Common Tests', () => {
it('wraps an ORM error in a feathers error', () => {
return people.create({}).catch(error =>
return people.create({}).catch(error => {
expect(error instanceof errors.FeathersError).to.be.ok
});
});

describe('Raw/Lean Queries', () => {
const _ids = {};
const _data = {};

beforeEach(() =>
people.create({
name: 'Doug',
age: 32
}).then(data => {
_data.Doug = data;
_ids.Doug = data[idProp];
})
);

afterEach(() =>
people.remove(_ids.Doug).catch(() => {})
);

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()', () => {
return people.find({}).then(results =>
expect(Object.getPrototypeOf(results[0])).to.equal(Object.prototype)
).catch(noPOJO);
});

it('returns a POJO for get()', () => {
return people.get(_ids.Doug).then(result =>
expect(Object.getPrototypeOf(result)).to.equal(Object.prototype)
).catch(noPOJO);
});

it('returns a POJO for create()', () => {
return people.create({name: 'Sarah', age: 30}).then(result =>
expect(Object.getPrototypeOf(result)).to.equal(Object.prototype)
).catch(noPOJO);
});

it('returns POJOs for bulk create()', () => {
return people.create([{name: 'Sarah', age: 30}]).then(result =>
expect(Object.getPrototypeOf(result[0])).to.equal(Object.prototype)
).catch(noPOJO);
});

it('returns a POJO for patch()', () => {
return people.patch(_ids.Doug, {name: 'Sarah'}).then(result =>
expect(Object.getPrototypeOf(result)).to.equal(Object.prototype)
).catch(noPOJO);
});

it('returns a POJO for update()', () => {
return people.update(_ids.Doug, Object.assign(_data.Doug, {name: 'Sarah'})).then(result =>
expect(Object.getPrototypeOf(result)).to.equal(Object.prototype)
).catch(noPOJO);
});
});
});
}

0 comments on commit 3124a09

Please sign in to comment.