Skip to content

Commit

Permalink
Small test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Oct 30, 2017
1 parent 5d3dedd commit bd08c1a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 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 @@ -118,7 +118,7 @@ dao.insertCredential = function (id, type, credentialObj) {
db.saddAsync(buildIdKey(type, credentialObj.consumerId), id),
// store key-auth keyid -> credentialObj
db.hmsetAsync(buildIdKey(type, id), credentialObj)
]).catch((e) => console.log(e));
]);
}
return db.hmsetAsync(buildIdKey(type, id), credentialObj);
};
Expand Down
8 changes: 4 additions & 4 deletions test/services/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ describe('Auth tests', function () {
return credentialService.insertScopes(['someScope1', 'someScope2', 'someScope3']);
})
.then(() => {
return credentialService.insertCredential(userFromDb.id, 'oauth2', _credential)
.then((res) => should.exist(res));
});
return credentialService.insertCredential(userFromDb.id, 'oauth2', _credential);
})
.then((res) => should.exist(res));
});

after(() => {
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('Auth tests', function () {
});

it('should not authenticate valid user with invalid credentials', () => {
return authService.authenticateCredential(user.username, 'invalidSecret', 'oauth2')
return authService.authenticateCredential(userFromDb.id, 'invalidSecret', 'oauth2')
.then(authResponse => {
should.exist(authResponse);
authResponse.should.eql(false);
Expand Down
33 changes: 17 additions & 16 deletions test/services/credential-service/credentials.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const credentialService = services.credential;
const userService = services.user;
const db = require('../../../lib/db')();

describe('Credential service tests', function () {
describe('Credential tests', function () {
describe('Credential service tests', () => {
describe('Credential tests', () => {
let credential;
const originalModelConfig = config.models.credentials;
const username = 'someUser';
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('Credential service tests', function () {

return credentialService
.insertCredential(username, 'oauth2', _credential)
.then(function (newCredential) {
.then((newCredential) => {
should.exist(newCredential);
credential = Object.assign(newCredential, _credential);
});
Expand All @@ -65,10 +65,10 @@ describe('Credential service tests', function () {

return credentialService
.insertCredential('someUsername', 'oauth2', _credential)
.then(function (newCredential) {
.then((newCredential) => {
should.exist(newCredential);
should.exist(newCredential.secret);
newCredential.secret.length.should.greaterThanOrEqual(10);
should(newCredential.secret.length).greaterThanOrEqual(10);
});
});

Expand All @@ -79,7 +79,7 @@ describe('Credential service tests', function () {

return credentialService
.insertCredential(username, 'basic-auth', _credential)
.then(function (newCredential) {
.then((newCredential) => {
should.exist(newCredential);
newCredential.isActive.should.eql(true);
});
Expand All @@ -88,7 +88,7 @@ describe('Credential service tests', function () {
it('should get a credential', () => {
return credentialService
.getCredential(username, 'oauth2')
.then(function (cred) {
.then((cred) => {
should.exist(cred);
should.not.exist(cred.secret);
credential.isActive.should.eql(true);
Expand All @@ -109,12 +109,12 @@ describe('Credential service tests', function () {
it('should reactivate a credential', () => {
return credentialService
.activateCredential(username, 'oauth2')
.then(function (res) {
.then((res) => {
should.exist(res);

return credentialService.getCredential(username, 'oauth2');
})
.then(function (cred) {
.then((cred) => {
should.exist(cred);
should.not.exist(cred.secret);
cred.isActive.should.eql(true);
Expand Down Expand Up @@ -236,12 +236,13 @@ describe('Credential service tests', function () {
.then(() => credentialService.insertCredential(username, 'oauth2', _credential))
.then((newCredential) => {
should.exist(newCredential);
newCredential.isActive.should.eql(true);
should.exist(newCredential.scopes);
should.not.exist(newCredential.secret);

newCredential.isActive.should.eql(true);
newCredential.scopes.should.eql(['someScope']);
newCredential.someProperty.should.eql('propVal');
newCredential.otherProperty.should.eql('someDefaultValue');
should.not.exist(newCredential.secret);
});
});

Expand All @@ -254,12 +255,12 @@ describe('Credential service tests', function () {
.then((cred) => {
should.exist(cred);
should.exist(cred.scopes);
cred.isActive.should.eql(true);
cred.scopes.should.containEql(_credential.scopes);
cred.scopes.should.containEql('someScope1');
cred.scopes.should.containEql('someScope2');
cred.scopes.should.containEql('someScope3');
cred.scopes.should.containEql('someOtherOne');
cred.isActive.should.eql(true);
});
});
});
Expand Down Expand Up @@ -344,10 +345,10 @@ describe('Credential service tests', function () {
.updateCredential(username, 'oauth2', {})
.then((newCredential) => {
should.not.exist(newCredential);
return credentialService.getCredential(username, 'oauth2')
.then(credential => {
should.exist(credential);
});
return credentialService.getCredential(username, 'oauth2');
})
.then(credential => {
should.exist(credential);
});
});
});
Expand Down

0 comments on commit bd08c1a

Please sign in to comment.