I am hitting a seemingly basic issue while testing an API in two ways: one directly via URL, the other by calling the corresponding event. Here are the two tests (results are attached):
scenario( “I request a list of all carriers”, function(){
given( “A call to the /api/v1/carriers route”, function(){
then( “I should get all carriers in the system”, function(){
var e = execute( event=“api.v1.carriers.index”, renderResults = true );
var response = getRequestContext().getPrivateValue( “response” );
expect( e.getRenderedContent() ).toBeJSON();
expect( response.getError() ).toBeFalse( “Error in call” );
expect( response.getStatusCode() ).toBe( 200 );
});
});
// Another way to test (via the URL)
it( “index - get all carriers”, function(){
var cfhttpResponse = “”;
http url=“http://127.0.0.1:50427/api/v1/carriers” result=“cfhttpResponse”;
expect( cfhttpResponse.statusCode ).toBe(200);
});
});
The test using the URL passes while the scenario based test fails with the error: “event: api.v1.carriers.index is not a valid registered event”.
The locations of my files follow the default implementation of the REST HMVC template (see Directory Structure). Any suggestion?