@anddone/coretestautomation 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm-release.yml +102 -0
- package/dist/api/base.api.d.ts +32 -0
- package/dist/api/base.api.d.ts.map +1 -0
- package/dist/api/base.api.js +7 -0
- package/dist/api/base.api.js.map +1 -0
- package/dist/api/headers.d.ts +6 -0
- package/dist/api/headers.d.ts.map +1 -0
- package/dist/api/headers.js +23 -0
- package/dist/api/headers.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/pages/basepage.d.ts +6 -0
- package/dist/pages/basepage.d.ts.map +1 -0
- package/dist/pages/basepage.js +10 -0
- package/dist/pages/basepage.js.map +1 -0
- package/dist/testData/api.data.json +6 -0
- package/dist/utils/apiUtils.d.ts +123 -0
- package/dist/utils/apiUtils.d.ts.map +1 -0
- package/dist/utils/apiUtils.js +264 -0
- package/dist/utils/apiUtils.js.map +1 -0
- package/dist/utils/assertionUtils.d.ts +223 -0
- package/dist/utils/assertionUtils.d.ts.map +1 -0
- package/dist/utils/assertionUtils.js +400 -0
- package/dist/utils/assertionUtils.js.map +1 -0
- package/dist/utils/commonUtils.d.ts +590 -0
- package/dist/utils/commonUtils.d.ts.map +1 -0
- package/dist/utils/commonUtils.js +1292 -0
- package/dist/utils/commonUtils.js.map +1 -0
- package/dist/utils/fakerStaticData.d.ts +16 -0
- package/dist/utils/fakerStaticData.d.ts.map +1 -0
- package/dist/utils/fakerStaticData.js +88 -0
- package/dist/utils/fakerStaticData.js.map +1 -0
- package/dist/utils/fileCommonUtils.d.ts +22 -0
- package/dist/utils/fileCommonUtils.d.ts.map +1 -0
- package/dist/utils/fileCommonUtils.js +243 -0
- package/dist/utils/fileCommonUtils.js.map +1 -0
- package/dist/utils/generationUtils.d.ts +424 -0
- package/dist/utils/generationUtils.d.ts.map +1 -0
- package/dist/utils/generationUtils.js +869 -0
- package/dist/utils/generationUtils.js.map +1 -0
- package/dist/utils/pageUtils.d.ts +90 -0
- package/dist/utils/pageUtils.d.ts.map +1 -0
- package/dist/utils/pageUtils.js +214 -0
- package/dist/utils/pageUtils.js.map +1 -0
- package/dist/utils/tableUtils.d.ts +304 -0
- package/dist/utils/tableUtils.d.ts.map +1 -0
- package/dist/utils/tableUtils.js +555 -0
- package/dist/utils/tableUtils.js.map +1 -0
- package/dist/utils/validationUtils.d.ts +80 -0
- package/dist/utils/validationUtils.d.ts.map +1 -0
- package/dist/utils/validationUtils.js +172 -0
- package/dist/utils/validationUtils.js.map +1 -0
- package/package.json +23 -0
- package/playwright.config.ts +79 -0
- package/src/api/base.api.ts +39 -0
- package/src/api/headers.ts +17 -0
- package/src/index.ts +12 -0
- package/src/pages/basepage.ts +11 -0
- package/src/testData/api.data.json +6 -0
- package/src/types/pdf-parse.d.ts +6 -0
- package/src/utils/apiUtils.ts +307 -0
- package/src/utils/assertionUtils.ts +455 -0
- package/src/utils/commonUtils.ts +1544 -0
- package/src/utils/fakerStaticData.ts +91 -0
- package/src/utils/fileCommonUtils.ts +239 -0
- package/src/utils/generationUtils.ts +929 -0
- package/src/utils/pageUtils.ts +224 -0
- package/src/utils/tableUtils.ts +715 -0
- package/src/utils/validationUtils.ts +179 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { differenceInDays, differenceInMonths, differenceInYears, format, isValid, parse } from "date-fns";
|
|
2
|
+
|
|
3
|
+
export class ValidationUtils {
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether a Date object is valid.
|
|
6
|
+
*
|
|
7
|
+
* @param date Date object
|
|
8
|
+
* @returns true if valid Date, false otherwise
|
|
9
|
+
*/
|
|
10
|
+
static isValidDate(date: Date): boolean {
|
|
11
|
+
try {
|
|
12
|
+
return date instanceof Date && isValid(date);
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether two dates fall on the same calendar day.
|
|
20
|
+
*
|
|
21
|
+
* @param date1 First date
|
|
22
|
+
* @param date2 Second date
|
|
23
|
+
* @returns True if date1 is before date2
|
|
24
|
+
*/
|
|
25
|
+
static isBefore(date1: Date, date2: Date): boolean {
|
|
26
|
+
try {
|
|
27
|
+
return this.isValidDate(date1) && this.isValidDate(date2) && date1.getTime() < date2.getTime();
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Checks whether two dates fall on the same calendar day.
|
|
35
|
+
*
|
|
36
|
+
* @param date1 First date
|
|
37
|
+
* @param date2 Second date
|
|
38
|
+
* @returns True if date1 is after date2
|
|
39
|
+
*/
|
|
40
|
+
static isAfter(date1: Date, date2: Date): boolean {
|
|
41
|
+
try {
|
|
42
|
+
return this.isValidDate(date1) && this.isValidDate(date2) && date1.getTime() > date2.getTime();
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether two dates fall on the same calendar day.
|
|
50
|
+
*
|
|
51
|
+
* @param date1 First date
|
|
52
|
+
* @param date2 Second date
|
|
53
|
+
* @returns True if both dates are on the same day
|
|
54
|
+
*/
|
|
55
|
+
static isSameDay(date1: Date, date2: Date): boolean {
|
|
56
|
+
try {
|
|
57
|
+
if (!this.isValidDate(date1) || !this.isValidDate(date2)) return false;
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
date1.getFullYear() === date2.getFullYear() &&
|
|
61
|
+
date1.getMonth() === date2.getMonth() &&
|
|
62
|
+
date1.getDate() === date2.getDate()
|
|
63
|
+
);
|
|
64
|
+
} catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Checks whether a list of dates is in ascending order (oldest → newest).
|
|
71
|
+
*
|
|
72
|
+
* @param dates Array of Date objects
|
|
73
|
+
* @returns true if dates are in ascending order
|
|
74
|
+
*/
|
|
75
|
+
static isAscendingDateList(dates: Date[]): boolean {
|
|
76
|
+
try {
|
|
77
|
+
if (!Array.isArray(dates) || dates.length < 2) return true;
|
|
78
|
+
|
|
79
|
+
for (let i = 1; i < dates.length; i++) {
|
|
80
|
+
if (!this.isAfter(dates[i], dates[i - 1]) &&
|
|
81
|
+
dates[i].getTime() !== dates[i - 1].getTime()) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return true;
|
|
87
|
+
} catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Checks whether a list of dates is in descending order (newest → oldest).
|
|
94
|
+
*
|
|
95
|
+
* @param dates Array of Date objects
|
|
96
|
+
* @returns true if dates are in descending order
|
|
97
|
+
*/
|
|
98
|
+
static isDescendingDateList(dates: Date[]): boolean {
|
|
99
|
+
try {
|
|
100
|
+
if (!Array.isArray(dates) || dates.length < 2) return true;
|
|
101
|
+
|
|
102
|
+
for (let i = 1; i < dates.length; i++) {
|
|
103
|
+
if (!this.isBefore(dates[i], dates[i - 1]) &&
|
|
104
|
+
dates[i].getTime() !== dates[i - 1].getTime()) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Checks whether a date string strictly matches the given date format.
|
|
118
|
+
*
|
|
119
|
+
* @param dateStr input date string
|
|
120
|
+
* @param formatStr expected date format
|
|
121
|
+
* @returns true if date matches the format exactly, false otherwise
|
|
122
|
+
*
|
|
123
|
+
* Example:
|
|
124
|
+
* doesDateMatchFormat("02/10/2003", "dd/MM/yyyy") → true
|
|
125
|
+
* doesDateMatchFormat("2/10/2003", "dd/MM/yyyy") → false
|
|
126
|
+
*/
|
|
127
|
+
static isDateMatchFormat(dateStr: string, formatStr: string): boolean {
|
|
128
|
+
try {
|
|
129
|
+
if (!dateStr || !formatStr) return false;
|
|
130
|
+
|
|
131
|
+
const parsedDate = parse(dateStr, formatStr, new Date());
|
|
132
|
+
|
|
133
|
+
if (!this.isValidDate(parsedDate)) return false;
|
|
134
|
+
const reformatted = format(parsedDate, formatStr);
|
|
135
|
+
|
|
136
|
+
return reformatted === dateStr;
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Checks whether a string matches a given regular expression.
|
|
145
|
+
*
|
|
146
|
+
* @param value Input string to test
|
|
147
|
+
* @param pattern Regular expression pattern
|
|
148
|
+
* @returns true if pattern matches, otherwise false
|
|
149
|
+
*
|
|
150
|
+
* Example:
|
|
151
|
+
* matchRegex("test@example.com", /^[^\s@]+@[^\s@]+\.[^\s@]+$/) → true
|
|
152
|
+
*/
|
|
153
|
+
static isMatchedRegex(value: string, pattern: RegExp): boolean {
|
|
154
|
+
try {
|
|
155
|
+
if (!value || !pattern) return false;
|
|
156
|
+
|
|
157
|
+
return pattern.test(value);
|
|
158
|
+
} catch {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Validates whether the actual transaction/payment ID matches
|
|
165
|
+
* the expected partially visible and hidden (masked) pattern.
|
|
166
|
+
* @since 27-01-2026
|
|
167
|
+
* @param actualId String (Full transaction/payment ID)
|
|
168
|
+
* @param expectedId String (Expected masked transaction/payment ID)
|
|
169
|
+
* @returns true if the masked actual ID matches the expected ID, otherwise false
|
|
170
|
+
*/
|
|
171
|
+
static isTransactionIdMatchingPartialVisibleHiddenPattern(
|
|
172
|
+
actualId: string,
|
|
173
|
+
expectedId: string
|
|
174
|
+
): boolean {
|
|
175
|
+
const maskedActualId = `${actualId.slice(0, 6)}...${actualId.slice(-6)}`;
|
|
176
|
+
return expectedId === maskedActualId;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"moduleResolution": "node",
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"module": "CommonJS",
|
|
7
|
+
"rootDir": "src",
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"sourceMap": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"typeRoots": ["./node_modules/@types", "./src/types"]
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*.ts"],
|
|
18
|
+
"exclude": ["node_modules", "dist"]
|
|
19
|
+
}
|