11/* eslint-disable no-undef */
2+ import moment from 'moment' ;
23import {
34 LABEL_CONFIG_KEYS ,
45 FIELD_CONFIG_KEYS ,
@@ -34,26 +35,7 @@ const APPLY_BUTTON_TEXT = 'Apply';
3435const RESET_BUTTON_TEXT = 'Reset' ;
3536
3637/**
37- * Converts a JavaScript Date object to a database-compatible timestamp string.
38- * @param {Date } [dateObject=new Date()] - The date to convert. Defaults to current date/time.
39- * @returns {string } Formatted timestamp string in format: "YYYY-MM-DD HH:MM:SS.mmmmmm" like "2025-11-06 05:30:45.123000"
40- */
41- function getDateStringInDbFormat ( dateObject = new Date ( ) ) {
42- const year = dateObject . getFullYear ( ) ;
43- const month = String ( dateObject . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
44- const day = String ( dateObject . getDate ( ) ) . padStart ( 2 , '0' ) ;
45- const hours = String ( dateObject . getHours ( ) ) . padStart ( 2 , '0' ) ;
46- const minutes = String ( dateObject . getMinutes ( ) ) . padStart ( 2 , '0' ) ;
47- const seconds = String ( dateObject . getSeconds ( ) ) . padStart ( 2 , '0' ) ;
48- const millis = String ( dateObject . getMilliseconds ( ) ) . padStart ( 3 , '0' ) ;
49- // JS only gives milliseconds (3 digits) so converting it to 6 digits like ".812169"
50- const micros = millis + '000' ;
51-
52- return `${ year } -${ month } -${ day } ${ hours } :${ minutes } :${ seconds } .${ micros } ` ;
53- }
54-
55- /**
56- * Function to do assertions on table data
38+ * Function to do assertions on table data
5739 */
5840function assertGtlData ( { columnIndex, expectedRowCount, rowContainsText } ) {
5941 cy . gtlGetRows ( [ columnIndex ] ) . then ( ( data ) => {
@@ -154,9 +136,7 @@ describe('Automate Service Requests form operations: Services > Requests', () =>
154136
155137 describe ( 'Validate button click actions' , ( ) => {
156138 beforeEach ( ( ) => {
157- const tenDaysAgo = new Date (
158- new Date ( ) . getTime ( ) - 10 * 24 * 60 * 60 * 1000
159- ) ;
139+ const today = moment ( ) . format ( ) ;
160140
161141 cy . appFactories ( [
162142 [
@@ -166,7 +146,7 @@ describe('Automate Service Requests form operations: Services > Requests', () =>
166146 description : 'Cypress mock data for approval state: Approved' ,
167147 approval_state : 'approved' ,
168148 type : 'ServiceTemplateProvisionRequest' ,
169- fulfilled_on : getDateStringInDbFormat ( ) ,
149+ fulfilled_on : today ,
170150 request_type : 'clone_to_service' ,
171151 request_state : 'finished' ,
172152 message : 'Cypress mock data for approval state: Approved' ,
@@ -180,7 +160,7 @@ describe('Automate Service Requests form operations: Services > Requests', () =>
180160 description : 'Cypress mock data for approval state: Denied' ,
181161 approval_state : 'denied' ,
182162 type : 'ServiceTemplateProvisionRequest' ,
183- fulfilled_on : getDateStringInDbFormat ( ) ,
163+ fulfilled_on : today ,
184164 request_type : 'clone_to_service' ,
185165 request_state : 'finished' ,
186166 message : 'Cypress mock data for approval state: Denied' ,
@@ -210,8 +190,8 @@ describe('Automate Service Requests form operations: Services > Requests', () =>
210190 'Cypress mock data for request made in the last 30 days' ,
211191 approval_state : 'approved' ,
212192 type : 'ServiceTemplateProvisionRequest' ,
213- created_on : getDateStringInDbFormat ( tenDaysAgo ) ,
214- fulfilled_on : getDateStringInDbFormat ( ) ,
193+ created_on : moment ( ) . subtract ( 10 , 'days' ) ,
194+ fulfilled_on : today ,
215195 request_type : 'clone_to_service' ,
216196 request_state : 'finished' ,
217197 message : 'Cypress mock data for request made in the last 30 days' ,
0 commit comments