@@ -734,6 +734,146 @@ func (suite *basicSuite) TestDestinationsListAPI() {
734734 suite .RunAPITests (suite .T (), tests )
735735}
736736
737+ func (suite * basicSuite ) TestDestinationEnableDisableAPI () {
738+ tenantID := uuid .New ().String ()
739+ sampleDestinationID := uuid .New ().String ()
740+ tests := []APITest {
741+ {
742+ Name : "PUT /:tenantID" ,
743+ Request : suite .AuthRequest (httpclient.Request {
744+ Method : httpclient .MethodPUT ,
745+ Path : "/" + tenantID ,
746+ }),
747+ Expected : APITestExpectation {
748+ Match : & httpclient.Response {
749+ StatusCode : http .StatusCreated ,
750+ },
751+ },
752+ },
753+ {
754+ Name : "POST /:tenantID/destinations" ,
755+ Request : suite .AuthRequest (httpclient.Request {
756+ Method : httpclient .MethodPOST ,
757+ Path : "/" + tenantID + "/destinations" ,
758+ Body : map [string ]interface {}{
759+ "id" : sampleDestinationID ,
760+ "type" : "webhook" ,
761+ "topics" : "*" ,
762+ "config" : map [string ]interface {}{
763+ "url" : "http://host.docker.internal:4444" ,
764+ },
765+ },
766+ }),
767+ Expected : APITestExpectation {
768+ Match : & httpclient.Response {
769+ StatusCode : http .StatusCreated ,
770+ },
771+ },
772+ },
773+ {
774+ Name : "GET /:tenantID/destinations/:destinationID" ,
775+ Request : suite .AuthRequest (httpclient.Request {
776+ Method : httpclient .MethodGET ,
777+ Path : "/" + tenantID + "/destinations/" + sampleDestinationID ,
778+ }),
779+ Expected : APITestExpectation {
780+ Validate : makeDestinationDisabledValidator (sampleDestinationID , false ),
781+ },
782+ },
783+ {
784+ Name : "PUT /:tenantID/destinations/:destinationID/disable" ,
785+ Request : suite .AuthRequest (httpclient.Request {
786+ Method : httpclient .MethodPUT ,
787+ Path : "/" + tenantID + "/destinations/" + sampleDestinationID + "/disable" ,
788+ }),
789+ Expected : APITestExpectation {
790+ Validate : makeDestinationDisabledValidator (sampleDestinationID , true ),
791+ },
792+ },
793+ {
794+ Name : "GET /:tenantID/destinations/:destinationID" ,
795+ Request : suite .AuthRequest (httpclient.Request {
796+ Method : httpclient .MethodGET ,
797+ Path : "/" + tenantID + "/destinations/" + sampleDestinationID ,
798+ }),
799+ Expected : APITestExpectation {
800+ Validate : makeDestinationDisabledValidator (sampleDestinationID , true ),
801+ },
802+ },
803+ {
804+ Name : "PUT /:tenantID/destinations/:destinationID/enable" ,
805+ Request : suite .AuthRequest (httpclient.Request {
806+ Method : httpclient .MethodPUT ,
807+ Path : "/" + tenantID + "/destinations/" + sampleDestinationID + "/enable" ,
808+ }),
809+ Expected : APITestExpectation {
810+ Validate : makeDestinationDisabledValidator (sampleDestinationID , false ),
811+ },
812+ },
813+ {
814+ Name : "GET /:tenantID/destinations/:destinationID" ,
815+ Request : suite .AuthRequest (httpclient.Request {
816+ Method : httpclient .MethodGET ,
817+ Path : "/" + tenantID + "/destinations/" + sampleDestinationID ,
818+ }),
819+ Expected : APITestExpectation {
820+ Validate : makeDestinationDisabledValidator (sampleDestinationID , false ),
821+ },
822+ },
823+ {
824+ Name : "PUT /:tenantID/destinations/:destinationID/enable duplicate" ,
825+ Request : suite .AuthRequest (httpclient.Request {
826+ Method : httpclient .MethodPUT ,
827+ Path : "/" + tenantID + "/destinations/" + sampleDestinationID + "/enable" ,
828+ }),
829+ Expected : APITestExpectation {
830+ Validate : makeDestinationDisabledValidator (sampleDestinationID , false ),
831+ },
832+ },
833+ {
834+ Name : "GET /:tenantID/destinations/:destinationID" ,
835+ Request : suite .AuthRequest (httpclient.Request {
836+ Method : httpclient .MethodGET ,
837+ Path : "/" + tenantID + "/destinations/" + sampleDestinationID ,
838+ }),
839+ Expected : APITestExpectation {
840+ Validate : makeDestinationDisabledValidator (sampleDestinationID , false ),
841+ },
842+ },
843+ {
844+ Name : "PUT /:tenantID/destinations/:destinationID/disable" ,
845+ Request : suite .AuthRequest (httpclient.Request {
846+ Method : httpclient .MethodPUT ,
847+ Path : "/" + tenantID + "/destinations/" + sampleDestinationID + "/disable" ,
848+ }),
849+ Expected : APITestExpectation {
850+ Validate : makeDestinationDisabledValidator (sampleDestinationID , true ),
851+ },
852+ },
853+ {
854+ Name : "PUT /:tenantID/destinations/:destinationID/disable duplicate" ,
855+ Request : suite .AuthRequest (httpclient.Request {
856+ Method : httpclient .MethodPUT ,
857+ Path : "/" + tenantID + "/destinations/" + sampleDestinationID + "/disable" ,
858+ }),
859+ Expected : APITestExpectation {
860+ Validate : makeDestinationDisabledValidator (sampleDestinationID , true ),
861+ },
862+ },
863+ {
864+ Name : "GET /:tenantID/destinations/:destinationID" ,
865+ Request : suite .AuthRequest (httpclient.Request {
866+ Method : httpclient .MethodGET ,
867+ Path : "/" + tenantID + "/destinations/" + sampleDestinationID ,
868+ }),
869+ Expected : APITestExpectation {
870+ Validate : makeDestinationDisabledValidator (sampleDestinationID , true ),
871+ },
872+ },
873+ }
874+ suite .RunAPITests (suite .T (), tests )
875+ }
876+
737877func makeDestinationListValidator (length int ) map [string ]any {
738878 return map [string ]any {
739879 "type" : "object" ,
@@ -767,3 +907,32 @@ func makeDestinationListValidator(length int) map[string]any {
767907 },
768908 }
769909}
910+
911+ func makeDestinationDisabledValidator (id string , disabled bool ) map [string ]any {
912+ var disabledValidator map [string ]any
913+ if disabled {
914+ disabledValidator = map [string ]any {
915+ "type" : "string" ,
916+ "minLength" : 1 ,
917+ }
918+ } else {
919+ disabledValidator = map [string ]any {
920+ "type" : "null" ,
921+ }
922+ }
923+ return map [string ]interface {}{
924+ "properties" : map [string ]interface {}{
925+ "statusCode" : map [string ]interface {}{
926+ "const" : 200 ,
927+ },
928+ "body" : map [string ]interface {}{
929+ "properties" : map [string ]interface {}{
930+ "id" : map [string ]interface {}{
931+ "const" : id ,
932+ },
933+ "disabled_at" : disabledValidator ,
934+ },
935+ },
936+ },
937+ }
938+ }
0 commit comments