component extends="taffy.core.resource" taffy_uri="/authenticate/{username}/authenticate" {
// LOGIN FUNCTION //
public function post(required string username, required string password, required string deviceId ) {
transaction {
try {
var status = variables.authSvc.login(username = arguments.username, password = arguments.password, deviceId = arguments.deviceId );
transaction action="commit";
}
catch( any e ) {
transaction action="rollback";
rethrow;
}
}
if ( status.isError() )
return noData().withStatus(401, status.getMessage() );
else
return representationOf( status.getDetails().token.getId() );
}
component extends="testbox.system.BaseSpec"{
/*********************************** LIFE CYCLE Methods ***********************************/
function beforeAll(){
res = getMockBox().createMock( "em2root.api.rest.resources.authentication" );
auth = getMockBox().createMock( "em2root.model.services.authentication" );
res.$property('authSvc', "variables", auth);
}
function afterAll(){
}
function logIt() {
writeDump('testing');
}
/*********************************** BDD SUITES ***********************************/
function run(){
describe( title="authentication service ", body=function(){
beforeEach( function( currentSpec ){
});
describe( title="post function (login) ", body = function() {
it(' should return 200 status on successful login ', function() {
var status = new em2root.model.beans.returnstatus();
auth.$( method="login", returns=status );
var ret =
res.post( username = 'test', password = 'test', deviceId = 'test' );
expect(0).toBe(1); // bogus placeholder
});