Skip to content

Instantly share code, notes, and snippets.

@nolandubeau
Last active Dec 17, 2015
Embed
What would you like to do?
Unit Testing Issue
function getUser(event,rc,prc){
//load user record
rc.user = userService.getUser(arguments.prc.user_id,getcoldBoxOCM().get('activePartners'));
//validate user is not empty
if(structIsEmpty(rc.user)){
if( log.canError() ){
log.error("Invalid User Request |#arguments.rc.Authorization# from #cgi.REMOTE_ADDR#",arguments.rc);
}
rc.results.setStatus(404);
rc.results.addError(404,'User does not exist');
}else{
rc.results.setData(rc.user);
}
}
public void function should_return_404_and_not_log_when_unable_to_obtain_a_user()
{
var rc = {
authorization='UserTest',
results=Results
};
var prc = {
user_id = 0
};
Log.$('canError',false).$('error');
UserService.$('getUser',{});
SUT.getUser(Event,rc,prc);
assertEquals(1,log.$count('canError'),'log.canError() method count failure');
assertEquals(0,log.$count('error'),'log.error() method count failure');
assertEquals(1,results.$count('setStatus'),'results.setStatus() method count failure');
assertEquals(1,results.$count('addError'),'results.addError() method count failure');
assertEquals(404,results.$callLog().setStatus[1]['1'],'order position of first argument is not as expected');
assertEquals(404,results.$callLog().addError[1]['1'],'order position of first argument is not as expected');
assertEquals('User does not exist',results.$callLog().addError[1]['2'],'error message is not as expected');
/*writeDump(results.$callLog());
abort;*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment