Skip to content

Commit

Permalink
give love to the current user tests
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Jan 5, 2019
1 parent 08e1f39 commit a0a42fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lib/services/consumers/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ s.remove = function (userId) {
return this.get(userId) // validate user exists
.then(user => Promise.all([user, !user ? false : userDao.remove(userId)]))
.then(([user, userDeleted]) => {
if (!userDeleted) {
if (user && !userDeleted) {
throw new Error('user delete failed');
} else {
return Promise.all([applicationService.removeAll(userId), // Cascade delete all apps associated with user
Expand Down
81 changes: 28 additions & 53 deletions test/services/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,13 @@ describe('User service tests', function () {

describe('Get and Find User tests', function () {
let user;
before(function (done) {
db.flushdb()
.then(function () {
user = createRandomUserObject();
userService
.insert(user)
.then(function (newUser) {
should.exist(newUser);
user.id = newUser.id;
done();
});
})
.catch(done);
});
before(() => db.flushdb().then(() => {
user = createRandomUserObject();
return userService.insert(user);
}).then(newUser => {
should.exist(newUser);
user.id = newUser.id;
}));

it('should get user by userId', function (done) {
userService.get(user.id)
Expand All @@ -110,6 +103,7 @@ describe('User service tests', function () {
})
.catch(done);
});

it('should get user all users', function () {
return userService.findAll()
.then(function (data) {
Expand Down Expand Up @@ -264,21 +258,13 @@ describe('User service tests', function () {

describe('Activate and deactivate user tests', function () {
let user;
before(function (done) {
db.flushdb()
.then(function () {
user = createRandomUserObject();
userService
.insert(user)
.then(function (newUser) {
should.exist(newUser);
user = Object.assign(user, newUser);
user.createdAt = newUser.createdAt;
done();
});
})
.catch(done);
});
before(() => db.flushdb().then(() => {
user = createRandomUserObject();
return userService.insert(user);
}).then(newUser => {
should.exist(newUser);
user.id = newUser.id;
}));

it('should deactivate user', function (done) {
userService.deactivate(user.id)
Expand Down Expand Up @@ -328,39 +314,28 @@ describe('User service tests', function () {

describe('Delete user tests', function () {
let user;
before(function (done) {
db.flushdb()
.then(function () {
user = createRandomUserObject();
userService
.insert(user)
.then(function (newUser) {
should.exist(newUser);
user.id = newUser.id;
done();
});
})
.catch(done);
});
before(() => db.flushdb().then(() => {
user = createRandomUserObject();
return userService.insert(user);
}).then(newUser => {
should.exist(newUser);
user.id = newUser.id;
}));

it('should delete user', function (done) {
userService.remove(user.id)
it('should delete user', function () {
return userService.remove(user.id)
.then(function (deleted) {
should.exist(deleted);
deleted.should.eql(true);
done();
})
.catch(done);
});
});

it('should not delete user with invalid id', function (done) {
userService.remove('invalid_id')
it('should not delete user with invalid id', function () {
return userService.remove('invalid_id')
.then(function (deleted) {
should.exist(deleted);
deleted.should.eql(false);
done();
})
.catch(done);
});
});
});
});
Expand Down

0 comments on commit a0a42fb

Please sign in to comment.