Clean up access-token-invalidation tests

This commit is contained in:
Miroslav Bajtoš 2017-01-13 10:40:48 +01:00
parent dc2b6530b7
commit f8b013dab8
1 changed files with 9 additions and 15 deletions

View File

@ -1989,7 +1989,7 @@ describe('User', function() {
User.login(currentEmailCredentials, function(err, accessToken1) { User.login(currentEmailCredentials, function(err, accessToken1) {
if (err) return next(err); if (err) return next(err);
assert(accessToken1.userId); assert(accessToken1.userId);
originalUserToken1 = accessToken1.id; originalUserToken1 = accessToken1;
next(); next();
}); });
}, },
@ -1997,7 +1997,7 @@ describe('User', function() {
User.login(currentEmailCredentials, function(err, accessToken2) { User.login(currentEmailCredentials, function(err, accessToken2) {
if (err) return next(err); if (err) return next(err);
assert(accessToken2.userId); assert(accessToken2.userId);
originalUserToken2 = accessToken2.id; originalUserToken2 = accessToken2;
next(); next();
}); });
}, },
@ -2057,7 +2057,7 @@ describe('User', function() {
it('keeps sessions AS IS if firstName is added using `updateAttributes`', function(done) { it('keeps sessions AS IS if firstName is added using `updateAttributes`', function(done) {
user.updateAttributes({'firstName': 'Janny'}, function(err, userInstance) { user.updateAttributes({'firstName': 'Janny'}, function(err, userInstance) {
if (err) return done(err); if (err) return done(err);
assertUntouchedTokens(done); assertPreservedTokens(done);
}); });
}); });
@ -2068,7 +2068,7 @@ describe('User', function() {
email: currentEmailCredentials.email, email: currentEmailCredentials.email,
}, function(err, userInstance) { }, function(err, userInstance) {
if (err) return done(err); if (err) return done(err);
assertUntouchedTokens(done); assertPreservedTokens(done);
}); });
}); });
@ -2303,9 +2303,11 @@ describe('User', function() {
function assertPreservedTokens(done) { function assertPreservedTokens(done) {
AccessToken.find({where: {userId: user.id}}, function(err, tokens) { AccessToken.find({where: {userId: user.id}}, function(err, tokens) {
if (err) return done(err); if (err) return done(err);
expect(tokens.length).to.equal(2); var actualIds = tokens.map(function(t) { return t.id; });
expect([tokens[0].id, tokens[1].id]).to.have.members([originalUserToken1, actualIds.sort();
originalUserToken2]); var expectedIds = [originalUserToken1.id, originalUserToken2.id];
expectedIds.sort();
expect(actualIds).to.eql(expectedIds);
done(); done();
}); });
} }
@ -2317,14 +2319,6 @@ describe('User', function() {
done(); done();
}); });
} }
function assertUntouchedTokens(done) {
AccessToken.find({where: {userId: user.id}}, function(err, tokens) {
if (err) return done(err);
expect(tokens.length).to.equal(2);
done();
});
}
}); });
describe('Verification after updating email', function() { describe('Verification after updating email', function() {