unit testing resources

27 views
Skip to first unread message

Jonathan Price

unread,
Apr 26, 2016, 1:02:45 PM4/26/16
to Taffy Users
I'm trying to set up some basic unit testing with mock/testbox and I'm getting this error:

should return 200 status on successful login (18 ms) - Element _TAFFY.SETTINGS.SERIALIZER is undefined in APPLICATION.

Here's what I've got:

CUT:

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() );
    }
}

TEST:

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
            });
         });
      });
   }
}


And here's the exception stack:

Exception Structure - struct
COLUMN0
ID??
LINE116
RAW_TRACEat cfresource2ecfc631528554$funcGETREPINSTANCE.runFunction(/Applications/ColdFusion10/cfusion/wwwroot/taffy/core/resource.cfc:116)
TEMPLATE/Applications/ColdFusion10/cfusion/wwwroot/taffy/core/resource.cfc
TYPECFML
Exception Structure - struct
COLUMN0
IDCF_UDFMETHOD
LINE15
RAW_TRACEat cfresource2ecfc631528554$funcNODATA.runFunction(/Applications/ColdFusion10/cfusion/wwwroot/taffy/core/resource.cfc:15)
TEMPLATE/Applications/ColdFusion10/cfusion/wwwroot/taffy/core/resource.cfc
TYPECFML
Exception Structure - struct
COLUMN0
IDCF_UDFMETHOD
LINE17
RAW_TRACEat cfauthentication2ecfc1447262717$funcPOST.runFunction(/Applications/ColdFusion10/cfusion/wwwroot/EM2/api/rest/resources/authentication.cfc:17)
TEMPLATE/Applications/ColdFusion10/cfusion/wwwroot/EM2/api/rest/resources/authentication.cfc
TYPECFML


Maybe my approach is flawed?  Thanks for any suggestions!

Adam Tuttle

unread,
Apr 26, 2016, 6:16:15 PM4/26/16
to Taffy Users
I guess it makes them not very testable, but Taffy resources can't function without an Application.cfc that extends taffy.core.api. There's a lot in there to wire up application state to make things work.

At one point I entertained the idea of adding a testing plugin to Taffy, but it didn't get much interest. Personally, I don't see a lot of use for it as my resources are generally just a lightweight wrapper around a DB query like a select or an update. Not much of a unit to test there.

In your case here, you're calling a service. I'd say you should have a test for the service method; but consider the api resource a "view" for interacting with it -- and thus a test, in this case at least, would seem unnecessary.

Certainly willing to be convinced, though. :)

Adam

--
You received this message because you are subscribed to the Google Groups "Taffy Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to taffy-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Puritan Paul

unread,
Apr 26, 2016, 6:18:45 PM4/26/16
to taffy...@googlegroups.com
That’s generally how I feel too.  Services calls are already tested, so yeah, testing the resource is pretty minimal and not so important.  Was considering it to validate return codes, but… nah.

You received this message because you are subscribed to a topic in the Google Groups "Taffy Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/taffy-users/Q1u5Q0u-uIk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to taffy-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages