@@ -32,64 +32,13 @@ const customCheckTemplate = <CustomCheck>{
3232export const hasCustomChecks =
3333 ( failingCount : number , passingCount : number ) =>
3434 ( { driver } : SetupFactoryOptions ) => {
35- const serviceControlInstanceUrl = window . defaultConfig . service_control_url ;
36-
37- // Calculate total count
38- const totalCount = failingCount + passingCount ;
39-
40- // Create checks (both failing and passing)
41- const customChecks = Array . from ( { length : totalCount } ) . map ( ( _ , index ) => {
42- // Generate the date based on the index
43- const date = new Date ( ) ;
44- date . setDate ( date . getDate ( ) - index ) ; // Subtract `index` days from the current date
45- const reportedAt = date . toISOString ( ) ; // Convert to ISO string format
46-
47- // Determine status and failure reason
48- const status = index < failingCount ? "Fail" : "Pass" ;
49- const failureReason = status === "Fail" ? `configured to fail on endpoint ${ index } ` : "" ;
50-
51- // Generate a new GUID for the ID and host_id
52- const newGuid = generateGuid ( ) ;
53- const originatingEndpointName = `endpoint ${ index } ` ;
54- const originatingHost = `ABC ${ index } ` ;
55- const customCategory = `Some Category ${ index } ` ;
56- const customeCheckId = `SampleCustomeCheck ${ index } ` ;
57-
58- return {
59- ...customCheckTemplate ,
60- id : `customchecks/${ newGuid } ` , // New GUID for ID
61- category : customCategory ,
62- custom_check_id : customeCheckId ,
63- status, // Fail or Pass based on index
64- failure_reason : failureReason , // Failure reason or empty for passing
65- reported_at : reportedAt , // Autogenerated reported_at based on index
66- originating_endpoint : {
67- name : originatingEndpointName , // Endpoint name based on index
68- host_id : newGuid , // New GUID for host_id
69- host : originatingHost , // Host name based on index
70- } ,
71- } ;
72- } ) ;
35+ const customChecksData = generateCustomChecksData ( failingCount , passingCount ) ( ) ;
7336
74- const failedCustomChecks = customChecks . filter ( ( check ) => check . status === "Fail" ) ;
75-
76- driver . mockEndpointDynamic ( `${ serviceControlInstanceUrl } customchecks` , ( url ) => {
77- const status = url . searchParams . get ( "status" ) ;
78- if ( status === "fail" ) {
79- return {
80- body : failedCustomChecks ,
81- headers : { "Total-Count" : failedCustomChecks . length . toString ( ) } ,
82- } ;
83- }
84-
85- return {
86- body : customChecks ,
87- headers : { "Total-Count" : customChecks . length . toString ( ) } ,
88- } ;
89- } ) ;
37+ // Call getCustomChecks to mock the endpoints with the generated data
38+ getCustomChecks ( customChecksData ) ( { driver } ) ;
9039 } ;
9140
92- export const setCustomChecksData = ( failingCount : number , passingCount : number ) => ( ) => {
41+ export const generateCustomChecksData = ( failingCount : number , passingCount : number ) => ( ) => {
9342 // Calculate total count
9443 const totalCount = failingCount + passingCount ;
9544
@@ -136,24 +85,34 @@ export const getCustomChecks =
13685
13786 const failedCustomChecks = customChecks . filter ( ( check ) => check . status === "Fail" ) ;
13887
139- driver . mockEndpointDynamic ( `${ serviceControlInstanceUrl } customchecks` , ( url ) => {
88+ driver . mockEndpointDynamic ( `${ serviceControlInstanceUrl } customchecks` , "get" , ( url ) => {
14089 const status = url . searchParams . get ( "status" ) ;
14190 if ( status === "fail" ) {
142- return {
91+ return Promise . resolve ( {
14392 body : failedCustomChecks ,
14493 headers : { "Total-Count" : failedCustomChecks . length . toString ( ) } ,
145- } ;
94+ } ) ;
14695 }
14796
148- return {
97+ return Promise . resolve ( {
14998 body : customChecks ,
15099 headers : { "Total-Count" : customChecks . length . toString ( ) } ,
151- } ;
100+ } ) ;
101+ } ) ;
102+ driver . mockEndpointDynamic ( `${ serviceControlInstanceUrl } customchecks/:id` , "delete" , ( url , params ) => {
103+ const status = url . searchParams . get ( "status" ) ;
104+ console . log ( status + ", " + params . id ) ;
105+
106+ return Promise . resolve ( {
107+ body : { message : "Successfully deleted" } ,
108+ status : 200 ,
109+ headers : { "Content-Type" : "application/json" } ,
110+ } ) ;
152111 } ) ;
153112 } ;
154113
155- export const updateCustomCheckItem = ( data : CustomCheck [ ] , statusToUpdate : string ) => {
156- const itemToUpdate = data . find ( ( item ) => item . status === status ) ;
114+ export const updateCustomCheckItemByStatus = ( data : CustomCheck [ ] , statusToUpdate : string ) => {
115+ const itemToUpdate = data . find ( ( item ) => item . status === statusToUpdate ) ;
157116
158117 if ( itemToUpdate ) {
159118 if ( statusToUpdate === "Pass" ) {
@@ -165,3 +124,15 @@ export const updateCustomCheckItem = (data: CustomCheck[], statusToUpdate: strin
165124 }
166125 }
167126} ;
127+ export const updateCustomCheckItemByItem = ( data : CustomCheck [ ] , itemToUpdate : CustomCheck , statusToUpdate : string ) => {
128+ const itemFound = data . find ( ( item ) => item . id === itemToUpdate . id ) ;
129+ if ( itemFound != null ) {
130+ if ( statusToUpdate === "Fail" ) {
131+ itemToUpdate . status = Status . Fail ;
132+ itemToUpdate . failure_reason = "Some reason I dont know" ;
133+ } else {
134+ itemToUpdate . status = Status . Pass ;
135+ itemToUpdate . failure_reason = "" ;
136+ }
137+ }
138+ } ;
0 commit comments