From 2b96c1282db186b96249ffa12a94dda0200b56e7 Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Thu, 19 Sep 2024 16:06:22 +0200 Subject: [PATCH] v4 certified --- .../api/modules_app/v3/models/BaseService.cfc | 1 + .../api/modules_app/v4/handlers/Echo.cfc | 8 --- .../api/modules_app/v4/handlers/Rants.cfc | 2 +- tests/specs/integration/api-v4/RantsTest.cfc | 72 ------------------- 4 files changed, 2 insertions(+), 81 deletions(-) diff --git a/modules_app/api/modules_app/v3/models/BaseService.cfc b/modules_app/api/modules_app/v3/models/BaseService.cfc index a45c613..9213a37 100644 --- a/modules_app/api/modules_app/v3/models/BaseService.cfc +++ b/modules_app/api/modules_app/v3/models/BaseService.cfc @@ -22,6 +22,7 @@ component accessors="true" { setPrimaryKey( arguments.primaryKey ); setServiceName( arguments.serviceName ); setModuleName( arguments.moduleName ); + return this; } /** diff --git a/modules_app/api/modules_app/v4/handlers/Echo.cfc b/modules_app/api/modules_app/v4/handlers/Echo.cfc index 6d61bed..b2f5ac4 100644 --- a/modules_app/api/modules_app/v4/handlers/Echo.cfc +++ b/modules_app/api/modules_app/v4/handlers/Echo.cfc @@ -3,14 +3,6 @@ */ component extends="coldbox.system.RestHandler" { - // OPTIONAL HANDLER PROPERTIES - this.prehandler_only = ""; - this.prehandler_except = ""; - this.posthandler_only = ""; - this.posthandler_except = ""; - this.aroundHandler_only = ""; - this.aroundHandler_except = ""; - // REST Allowed HTTP Methods Ex: this.allowedMethods = {delete='POST,DELETE',index='GET'} this.allowedMethods = {}; diff --git a/modules_app/api/modules_app/v4/handlers/Rants.cfc b/modules_app/api/modules_app/v4/handlers/Rants.cfc index 8daf35a..3d246e7 100644 --- a/modules_app/api/modules_app/v4/handlers/Rants.cfc +++ b/modules_app/api/modules_app/v4/handlers/Rants.cfc @@ -16,7 +16,7 @@ component extends="coldbox.system.RestHandler" { * Returns a list of Rants */ any function index( event, rc, prc ){ - prc.response.setData( rantService.list().map( ( rant ) => rant.getMemento() ) ); + prc.response.setData( rantService.list().map( rant => rant.getMemento() ) ); } /** diff --git a/tests/specs/integration/api-v4/RantsTest.cfc b/tests/specs/integration/api-v4/RantsTest.cfc index 7de76a3..478e55d 100644 --- a/tests/specs/integration/api-v4/RantsTest.cfc +++ b/tests/specs/integration/api-v4/RantsTest.cfc @@ -14,9 +14,7 @@ component extends="tests.resources.BaseTest" { var event = get( "/api/v4/rants" ); var returnedJSON = event.getRenderData().data; // debug( returnedJSON ); - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeFalse(); - expect( returnedJSON ).toHaveKey( "data" ); expect( returnedJSON.data ).toBeArray(); expect( returnedJSON.data ).toHaveLengthGTE( 1 ); } ); @@ -31,11 +29,8 @@ component extends="tests.resources.BaseTest" { var rantID = "x" var event = get( "/api/v4/rants/#rantID#" ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -45,11 +40,8 @@ component extends="tests.resources.BaseTest" { var rantID = createUUID(); var event = get( "/api/v4/rants/#rantID#" ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 404 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -59,15 +51,11 @@ component extends="tests.resources.BaseTest" { var testRantId = queryExecute( "select id from rants limit 1" ).id; var event = get( "/api/v4/rants/#testRantId#" ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeFalse(); expect( event ).toHaveStatus( 200 ); - expect( returnedJSON ).toHaveKey( "data" ); expect( returnedJSON.data ).toBeStruct(); expect( returnedJSON.data ).toHaveKey( "rantId" ); expect( returnedJSON.data.rantId ).toBe( testRantId ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLength( 0 ); } ); } ); @@ -90,11 +78,8 @@ component extends="tests.resources.BaseTest" { then( "I will get a 400 error", function(){ var event = post( "/api/v4/rants", {} ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -103,11 +88,8 @@ component extends="tests.resources.BaseTest" { then( "I will get a 400 error", function(){ var event = post( "/api/v4/rants", { "userID" : "" } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -116,11 +98,8 @@ component extends="tests.resources.BaseTest" { then( "I will get a 400 error", function(){ var event = post( "/api/v4/rants", { "userID" : "abc" } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -129,11 +108,8 @@ component extends="tests.resources.BaseTest" { then( "I will get a 400 error", function(){ var event = post( "/api/v4/rants", { "userID" : createUUID() } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -142,11 +118,8 @@ component extends="tests.resources.BaseTest" { then( "I will get a 400 error", function(){ var event = post( "/api/v4/rants", { "userID" : createUUID(), "body" : "" } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -155,11 +128,8 @@ component extends="tests.resources.BaseTest" { then( "I will get a 404 error", function(){ var event = post( "/api/v4/rants", { "body" : "xsxswxws", "userID" : createUUID() } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 404 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -169,14 +139,10 @@ component extends="tests.resources.BaseTest" { var testUserId = queryExecute( "select id from users limit 1" ).id; var event = post( "/api/v4/rants", { "body" : "xsxswxws", "userID" : testUserId } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeFalse(); expect( event.getStatusCode() ).toBe( 200 ); - expect( returnedJSON ).toHaveKey( "data" ); expect( returnedJSON.data ).toBeStruct(); expect( returnedJSON.data ).toHaveKey( "rantId" ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); expect( returnedJSON.messages[ 1 ] ).toBe( "Rant Created" ); } ); @@ -213,11 +179,8 @@ component extends="tests.resources.BaseTest" { var testRant = queryExecute( "select id,userId from rants limit 1" ); var event = put( "/api/v4/rants/#testRant.id#", {} ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -227,11 +190,8 @@ component extends="tests.resources.BaseTest" { var testRant = queryExecute( "select id,userId from rants limit 1" ); var event = put( "/api/v4/rants/#testRant.id#", { "userID" : "" } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -241,11 +201,8 @@ component extends="tests.resources.BaseTest" { var testRant = queryExecute( "select id,userId from rants limit 1" ); var event = put( "/api/v4/rants/#testRant.id#", { "userID" : "abc" } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -255,11 +212,8 @@ component extends="tests.resources.BaseTest" { var testRant = queryExecute( "select id,userId from rants limit 1" ); var event = put( "/api/v4/rants/#testRant.id#", { "userID" : testRant.userId } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -272,11 +226,8 @@ component extends="tests.resources.BaseTest" { { "userID" : testRant.userId, "body" : "" } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -290,11 +241,8 @@ component extends="tests.resources.BaseTest" { { "userID" : testRant.userId, "body" : "abc" } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -307,11 +255,8 @@ component extends="tests.resources.BaseTest" { { "body" : "xsxswxws", "userID" : createUUID() } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 404 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -324,11 +269,8 @@ component extends="tests.resources.BaseTest" { { "userID" : createUUID(), "body" : "xsxswxws" } ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 404 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -342,12 +284,8 @@ component extends="tests.resources.BaseTest" { ); var returnedJSON = event.getRenderData().data; // debug( returnedJSON ); - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeFalse(); expect( event.getStatusCode() ).toBe( 200 ); - expect( returnedJSON ).toHaveKey( "data" ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); expect( returnedJSON.messages[ 1 ] ).toBe( "Rant Updated" ); } ); @@ -395,11 +333,8 @@ component extends="tests.resources.BaseTest" { var rantID = "abc"; var event = delete( "/api/v4/rants/#rantID#" ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 400 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -409,11 +344,8 @@ component extends="tests.resources.BaseTest" { var rantID = createUUID(); var event = delete( "/api/v4/rants/#rantID#" ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeTrue(); expect( event ).toHaveStatus( 404 ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); } ); } ); @@ -431,12 +363,8 @@ component extends="tests.resources.BaseTest" { var event = delete( "/api/v4/rants/#testRant.getId()#" ); var returnedJSON = event.getRenderData().data; - expect( returnedJSON ).toHaveKey( "error" ); expect( returnedJSON.error ).toBeFalse(); expect( event.getStatusCode() ).toBe( 200 ); - expect( returnedJSON ).toHaveKey( "data" ); - expect( returnedJSON ).toHaveKey( "messages" ); - expect( returnedJSON.messages ).toBeArray(); expect( returnedJSON.messages ).toHaveLengthGTE( 1 ); expect( returnedJSON.messages[ 1 ] ).toBe( "Rant Deleted" ); } );