Skip to content

Commit 7e70b96

Browse files
greenkeeperio-botdaffl
authored andcommitted
Update service tests, id and events option (#31)
* chore(package): update feathers-service-tests to version 0.7.0 * Add updated tests and functionality
1 parent 503de4d commit 7e70b96

3 files changed

Lines changed: 28 additions & 42 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"body-parser": "^1.14.1",
5757
"feathers": "^2.0.0-pre.4",
5858
"feathers-rest": "^1.2.2",
59-
"feathers-service-tests": "^0.6.0",
59+
"feathers-service-tests": "^0.7.0",
6060
"feathers-socketio": "^1.3.3",
6161
"jshint": "^2.8.0",
6262
"mocha": "^3.0.0"

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ const _ = {
3232
class Service {
3333
constructor(options = {}) {
3434
this.paginate = options.paginate || {};
35-
this._id = options.idField || 'id';
35+
this._id = this.id = options.idField || options.id || 'id';
3636
this._uId = options.startId || 0;
3737
this.store = options.store || {};
38+
this.events = options.events || [];
3839
}
3940

4041
extend(obj) {

test/index.test.js

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,35 @@ import assert from 'assert';
77
import server from './test-app';
88
import memory from '../src';
99

10-
const _ids = {};
11-
const app = feathers().use('/people', memory());
12-
const people = app.service('people');
13-
14-
function clean() {
15-
people._uId = 0;
16-
people.store = {};
17-
}
18-
1910
describe('Feathers Memory Service', () => {
20-
before(clean);
21-
after(clean);
22-
23-
beforeEach(done => {
24-
people.create({
25-
name: 'Doug',
26-
age: 32
27-
}).then(data => {
28-
_ids.Doug = data.id;
29-
done();
30-
}, done);
31-
});
32-
33-
afterEach(done => {
34-
const doneNow = () => done();
35-
people.remove(_ids.Doug).then(doneNow, doneNow);
36-
});
37-
38-
it('is CommonJS compatible', () => {
39-
assert.equal(typeof require('../lib'), 'function');
40-
});
41-
42-
it('update with string id works', done => {
43-
people.create({
11+
const events = [ 'testing' ];
12+
const app = feathers()
13+
.use('/people', memory({ events }))
14+
.use('/people-customid', memory({
15+
id: 'customid', events
16+
}));
17+
18+
it('is CommonJS compatible', () =>
19+
assert.equal(typeof require('../lib'), 'function')
20+
);
21+
22+
it('update with string id works', () =>
23+
app.service('people').create({
4424
name: 'Tester',
4525
age: 33
4626
}).then(person =>
47-
people.update(person.id.toString(), person).then(updatedPerson =>
48-
assert.equal(typeof updatedPerson.id, 'number')
49-
).then(() => people.remove(person.id.toString()))
50-
).then(() => done()).catch(done);
51-
});
52-
53-
base(people, _ids, errors);
27+
app.service('people')
28+
.update(person.id.toString(), person)
29+
.then(updatedPerson =>
30+
assert.equal(typeof updatedPerson.id, 'number')
31+
)
32+
.then(() => app.service('people')
33+
.remove(person.id.toString()))
34+
)
35+
);
36+
37+
base(app, errors);
38+
base(app, errors, 'people-customid', 'customid');
5439
});
5540

5641
describe('Memory service example test', () => {

0 commit comments

Comments
 (0)