Skip to content

Commit

Permalink
fix: Add test to make sure different id in adapter query works (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Jan 10, 2019
1 parent c3ae9d7 commit 0ba4580
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 43 deletions.
119 changes: 78 additions & 41 deletions packages/adapter-tests/lib/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,37 @@ module.exports = (test, app, errors, serviceName, idProp) => {
'Got a NotFound Feathers error'
);
}
});

test('.get + NotFound', async () => {
try {
await service.get(doug[idProp], {
query: { [idProp]: '568225fbfe21222432e836ff' }
});
await service.get('568225fbfe21222432e836ff');
throw new Error('Should never get here');
} catch (error) {
assert.ok(error instanceof errors.NotFound,
'Got a NotFound Feathers error'
'Error is a NotFound Feathers error'
);
}
});

test('.get + NotFound', async () => {
test('.get + id + query id', async () => {
const alice = await service.create({
name: 'Alice',
age: 12
});

try {
await service.get('568225fbfe21222432e836ff');
await service.get(doug[idProp], {
query: { [idProp]: alice[idProp] }
});
throw new Error('Should never get here');
} catch (error) {
assert.ok(error instanceof errors.NotFound,
'Error is a NotFound Feathers error'
'Got a NotFound Feathers error'
);
}

await service.remove(alice[idProp]);
});
});

Expand Down Expand Up @@ -113,17 +122,6 @@ module.exports = (test, app, errors, serviceName, idProp) => {
'Got a NotFound Feathers error'
);
}

try {
await service.remove(doug[idProp], {
query: { [idProp]: '568225fbfe21222432e836ff' }
});
throw new Error('Should never get here');
} catch (error) {
assert.ok(error instanceof errors.NotFound,
'Got a NotFound Feathers error'
);
}
});

test('.remove + multi', async () => {
Expand Down Expand Up @@ -156,6 +154,26 @@ module.exports = (test, app, errors, serviceName, idProp) => {
assert.ok(names.includes('Dave'), 'Dave removed');
assert.ok(names.includes('David'), 'David removed');
});

test('.remove + id + query id', async () => {
const alice = await service.create({
name: 'Alice',
age: 12
});

try {
await service.remove(doug[idProp], {
query: { [idProp]: alice[idProp] }
});
throw new Error('Should never get here');
} catch (error) {
assert.ok(error instanceof errors.NotFound,
'Got a NotFound Feathers error'
);
}

await service.remove(alice[idProp]);
});
});

describe('update', () => {
Expand Down Expand Up @@ -203,28 +221,38 @@ module.exports = (test, app, errors, serviceName, idProp) => {
'Got a NotFound Feathers error'
);
}
});

test('.update + NotFound', async () => {
try {
await service.update('568225fbfe21222432e836ff', { name: 'NotFound' });
throw new Error('Should never get here');
} catch (error) {
assert.ok(error instanceof errors.NotFound, 'Error is a NotFound Feathers error');
}
});

test('.update + id + query id', async () => {
const alice = await service.create({
name: 'Alice',
age: 12
});

try {
await service.update(doug[idProp], {
name: 'Dougler'
name: 'Dougler',
age: 33
}, {
query: { [idProp]: '568225fbfe21222432e836ff' }
query: { [idProp]: alice[idProp] }
});
throw new Error('Should never get here');
} catch (error) {
assert.ok(error instanceof errors.NotFound,
'Got a NotFound Feathers error'
);
}
});

test('.update + NotFound', async () => {
try {
await service.update('568225fbfe21222432e836ff', { name: 'NotFound' });
throw new Error('Should never get here');
} catch (error) {
assert.ok(error instanceof errors.NotFound, 'Error is a NotFound Feathers error');
}
await service.remove(alice[idProp]);
});
});

Expand Down Expand Up @@ -269,19 +297,6 @@ module.exports = (test, app, errors, serviceName, idProp) => {
'Got a NotFound Feathers error'
);
}

try {
await service.patch(doug[idProp], {
name: 'id patched doug'
}, {
query: { [idProp]: '568225fbfe21222432e836ff' }
});
throw new Error('Should never get here');
} catch (error) {
assert.ok(error instanceof errors.NotFound,
'Got a NotFound Feathers error'
);
}
});

test('.patch multiple', async () => {
Expand Down Expand Up @@ -360,6 +375,28 @@ module.exports = (test, app, errors, serviceName, idProp) => {
);
}
});

test('.patch + id + query id', async () => {
const alice = await service.create({
name: 'Alice',
age: 12
});

try {
await service.patch(doug[idProp], {
age: 33
}, {
query: { [idProp]: alice[idProp] }
});
throw new Error('Should never get here');
} catch (error) {
assert.ok(error instanceof errors.NotFound,
'Got a NotFound Feathers error'
);
}

await service.remove(alice[idProp]);
});
});

describe('create', () => {
Expand Down
43 changes: 42 additions & 1 deletion packages/adapter-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion packages/adapter-tests/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ const testSuite = adapterTests([
'.find + paginate',
'.find + paginate + $limit + $skip',
'.find + paginate + $limit 0',
'.find + paginate + params'
'.find + paginate + params',
'.get + id + query id',
'.remove + id + query id',
'.update + id + query id',
'.patch + id + query id'
]);

describe('Feathers Memory Service', () => {
Expand Down

0 comments on commit 0ba4580

Please sign in to comment.