Here is a sample of a simple event which accepts up to 8 optional arguments and returns some data. What should I be testing for? And does anyone have an example of a test suite for something like this?
Model:
`
Handler:
`
component extends=“handlers.baseHandler” {
property name=“projectMetaService” inject=“projectMetaService”;
property name=“queryToArray” inject=“queryToArray”;
// Client Names
function getClientNames(event,rc,prc){
var results = projectMetaService.getClientNames(rc);
prc.results.data.clientnames = QueryToArray.convert(results);
}
}
`
Test:
`
component extends=“coldbox.system.testing.BaseTestCase” {
// executes before all suites+specs in the run() method
function beforeAll(){
// do your own stuff here
// super.setup();
super.beforeAll();
}
// executes after all suites+specs in the run() method
function afterAll(){
super.afterAll();
// do your own stuff here
}
function run(){
describe( title=“Project Meta Methods”, body=function(){
beforeEach(function(){
reset();
structClear(FORM);
});
it( title=“should get City of Arizona”, labels=“super”, body=function(){
FORM.wbs1 = ‘5COR0101’;
FORM.wbs2 = ‘00001’;
FORM.wbs3 = ‘5AA’;
FORM.projectname = ‘Arizona Street’;
FORM.clientname = ‘City of Arizona’;
FORM.projectmanager = ‘Pablo’;
FORM.teamlead = ‘Maria’;
FORM.qamanager = ‘Juan’;
var event = execute( event=“project:meta.getClientNames”);
expect( getRequestContext().getRenderData().DATA.data.PROJECTS[1].clientname ).toBe(“City of Arizona”);
});
it( title=“should get a list of client names”, labels=“super”, body=function(){
var event = execute( event=“project:meta.getClientNames”);
expect( ArrayLen(getRequestContext().getRenderData().DATA.data.PROJECTS) ).toBeGTE(1);
});
}
}
}
`