Skip to content

Commit

Permalink
write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Jan 5, 2019
1 parent d7863c6 commit bf73168
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/services/credentials/credential.dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ dao.removeAllCredentials = function (id) {
const awaitAllPromises = credentialTypes.map(type => {
const authKey = buildIdKey(type, id);

if (type === 'key-auth' || 'jwt') {
if (type === 'key-auth' || type === 'jwt') {
const promises = [];

// id in this call is actually consumerId, so we need to get all referenced keyIds
Expand Down
20 changes: 19 additions & 1 deletion test/services/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const uuid = require('uuid');
const redisConfig = require('../../lib/config').systemConfig.db.redis;
const services = require('../../lib/services');
const userService = services.user;
const credentialService = services.credential;
const db = require('../../lib/db');

describe('User service tests', function () {
Expand Down Expand Up @@ -314,7 +315,7 @@ describe('User service tests', function () {

describe('Delete user tests', function () {
let user;
before(() => db.flushdb().then(() => {
beforeEach(() => db.flushdb().then(() => {
user = createRandomUserObject();
return userService.insert(user);
}).then(newUser => {
Expand All @@ -337,6 +338,23 @@ describe('User service tests', function () {
deleted.should.eql(false);
});
});

describe('should delete all the related credentials', () => {
const credentials = [];
before(() =>
Promise.all([
credentialService.insertScopes(['someScope']),
credentialService.insertCredential(user.id, 'jwt'),
credentialService.insertCredential(user.id, 'jwt')]
).then(([scope, jwt1, jwt2]) =>
Promise.all([jwt1, jwt2].map(cred => {
credentials.push(cred);
return credentialService.addScopesToCredential(cred.id, 'jwt', ['someScope']);
}))
));
it('should remove the user', () => should(userService.remove(user.id)).resolvedWith(true));
it('should remove the credentials', () => should(credentialService.getCredential(credentials[0].id, 'jwt')).resolvedWith(null));
});
});
});

Expand Down

0 comments on commit bf73168

Please sign in to comment.