[testbox 2.0] what to expect from api json results in an integration test and

In my ModuleConfig.cfc I have this route:

{pattern="/", handler=“projectHandler”, action=‘index’}

In my integration test

describe( “Project API Default Handler”, function(){
it( “list 113 most recently created projects”, function(){

var event = execute( event=“project:projectHandler.index”, eventArguments={max=113});

expect( length(getRequestContent().getRenderedData().DATA.data) ).toBe(113);
});
});

This test fails because my handler is not getting the “max” argument. What is the correct way of doing this?

Also is my expection logic ok? Is how you would you expect a test?

Hmm, that seems about right. Not sure why they are not passed, can you post your handler code. Also, try dumping out the event arguments inside of the handler and see what you get.

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057
Direct: (909) 248-3408

ColdBox Platform: http://www.coldbox.org

ContentBox Platform: http://www.gocontentbox.org
Linked In: http://www.linkedin.com/pub/3/731/483

Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano | twitter.com/gocontentbox

My handler is:

// list projects
function index(event,rc,prc){

prc.results.data = queryToArray.convert(paagDAOSimple.getProjects(max=rc.max));

}

I removed the default param for max and my test errors out with "Element MAX is undefined in RC"

the eventArguments get lost somewhere in the supertype controller, I think. I hard coded the argument in the BaseTestCase.cfc and in the web/Controller.cfc and it still does not come out the other way.

You have it wrong Daniel. Event arguments are received into the handler function itself, not the RC or PRC. So your method signature should be:

function index(event,rc,prc, max=10){}

If you want to pass variables into RC from testing, then pass them like a browser or a REST client would, either via URL or FORm.

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057
Direct: (909) 248-3408

ColdBox Platform: http://www.coldbox.org

ContentBox Platform: http://www.gocontentbox.org
Linked In: http://www.linkedin.com/pub/3/731/483

Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano | twitter.com/gocontentbox

Ohhhhhh, ok, thanks. I know now how that works.

so my test looks like this:

function run(){
describe( “Project Default Handler”, function(){

it( “should list a max of 100 most recently created projects”, function(){
var event = execute( event=“project:projectHandler.index”);
expect( Arraylen(getRequestContext().getRenderData().DATA.data) ).toBeBetween(1,100);
});
it( “should list 13 most recently created projects”, function(){
url.max = 13;
var event = execute( event=“project:projectHandler.index”);
debug( getRequestContext() );
expect( Arraylen(getRequestContext().getRenderData().DATA.data) ).toBe(13);
});

});
}

sweet. thanks

I haven’t found anything in the docs or blogs that show how to integration test this event with pattern placeholders.

This pattern is a RESTFUL end point. Is TESTBOX not for coldbox restful apis?

// search
{pattern="/projectsbygeo/:lat/:lng", handler=“projectHandler”, action={GET=“getProjectsByGeo”} },

At this point, I don’t believe we have any tests for the pattern matching. The integration tests assume this part is done already.

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057
Direct: (909) 248-3408

ColdBox Platform: http://www.coldbox.org

ContentBox Platform: http://www.gocontentbox.org
Linked In: http://www.linkedin.com/pub/3/731/483

Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano | twitter.com/gocontentbox

Ok. got it.

Since its directly executing the handler event using the URL scope is good enough. Tlazocamatli/Gracias Luis.