Skip to content

Commit

Permalink
Fix 813 (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro Alonso authored Mar 27, 2017
1 parent d313336 commit a9d71e9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion erizo_controller/erizoController/erizoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ exports.deleteUser = function (user, room, callback) {
}
else {
log.error('mesagge: deleteUser user does not exist, user: ' + user );
callback('User does not exist', 404);
callback('User does not exist');
return;
}

Expand Down
46 changes: 24 additions & 22 deletions nuve/nuveAPI/cloudHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,43 +238,45 @@ var getErizoControllerForRoom = exports.getErizoControllerForRoom = function (ro
};

exports.getUsersInRoom = function (roomId, callback) {

roomRegistry.getRoom(roomId, function (room) {
if (!room.erizoControllerId) {
if (room && room.erizoControllerId) {
var rpcID = 'erizoController_' + room.erizoControllerId;
rpc.callRpc(rpcID, 'getUsersInRoom', [roomId], {'callback': function (users) {
callback(users);
}});

} else {
callback([]);
return;
}
var rpcID = 'erizoController_' + room.erizoControllerId;
rpc.callRpc(rpcID, 'getUsersInRoom', [roomId], {'callback': function (users) {
callback(users);
}});

});

};

exports.deleteRoom = function (roomId, callback) {

roomRegistry.getRoom(roomId, function (room) {
if (!room.erizoControllerId) {
if (room && room.erizoControllerId) {
var rpcID = 'erizoController_' + room.erizoControllerId;
rpc.callRpc(rpcID, 'deleteRoom', [roomId], {'callback': function (result) {
callback(result);
}});
} else {
callback('Success');
return;
}
var rpcID = 'erizoController_' + room.erizoControllerId;
rpc.callRpc(rpcID, 'deleteRoom', [roomId], {'callback': function (result) {
callback(result);
}});
});
};

exports.deleteUser = function (user, roomId, callback) {
roomRegistry.getRoom(roomId, function (room) {
var rpcID = 'erizoController_' + room.erizoControllerId;
rpc.callRpc(rpcID,
'deleteUser',
[{user: user, roomId:roomId}],
{'callback': function (result) {
callback(result);
}});
if (room && room.erizoControllerId) {
var rpcID = 'erizoController_' + room.erizoControllerId;
rpc.callRpc(rpcID,
'deleteUser',
[{user: user, roomId:roomId}],
{'callback': function (result) {
callback(result);
}});
} else {
callback('Room does not exist or the user is not connected');
}
});
};
7 changes: 6 additions & 1 deletion nuve/nuveAPI/nuve.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ app.get('/rooms/:room/users', usersResource.getList);
app.get('/rooms/:room/users/:user', userResource.getUser);
app.delete('/rooms/:room/users/:user', userResource.deleteUser);

app.listen(3000);
// handle 404 errors
app.use(function(req, res){
res.status(404).send('Resource not found');
});

app.listen(3000);
16 changes: 5 additions & 11 deletions nuve/nuveAPI/resource/userResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ exports.getUser = function (req, res) {

var user = req.params.user;


cloudHandler.getUsersInRoom(currentRoom._id, function (users) {
if (users === 'error') {
res.status(401).send('CloudHandler does not respond');
res.status(503).send('CloudHandler does not respond');
return;
}
for (var index in users){
Expand All @@ -51,15 +50,11 @@ exports.getUser = function (req, res) {
res.send(users[index]);
return;
}

}
log.error('message: getUser user not found, userId: ' + req.params.user);
res.status(404).send('User does not exist');
return;


});

});
};

Expand All @@ -81,15 +76,14 @@ exports.deleteUser = function (req, res) {

var user = req.params.user;

cloudHandler.deleteUser (user, currentRoom._id, function(result){
if(result === 'User does not exist'){
cloudHandler.deleteUser(user, currentRoom._id, function(result){
if (result !== 'Success'){
res.status(404).send(result);
}
else {
} else {
res.send(result);
return;
}
});
//Consultar RabbitMQ
});
};
};
6 changes: 3 additions & 3 deletions nuve/nuveAPI/test/resource/userResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('User Resource', function() {
cloudHandlerMock.getUsersInRoom.callsArgWith(1, 'error');
request(app)
.get('/rooms/1/users/1')
.expect(401, 'CloudHandler does not respond')
.expect(503, 'CloudHandler does not respond')
.end(function(err) {
if (err) throw err;
done();
Expand Down Expand Up @@ -149,10 +149,10 @@ describe('User Resource', function() {
it('should succeed if user exists', function(done) {
serviceRegistryMock.getRoomForService.callsArgWith(2, kArbitraryRoom);
setServiceStub.returns(kArbitraryService);
cloudHandlerMock.deleteUser.callsArgWith(2, kArbtiraryUser);
cloudHandlerMock.deleteUser.callsArgWith(2, 'Success');
request(app)
.delete('/rooms/1/users/1')
.expect(200, JSON.stringify(kArbtiraryUser))
.expect(200, 'Success')
.end(function(err) {
if (err) throw err;
done();
Expand Down

0 comments on commit a9d71e9

Please sign in to comment.