File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
packages/bruno-common/src/utils Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { mockDataFunctions } from "./faker-functions" ;
2
2
3
3
describe ( "mockDataFunctions Regex Validation" , ( ) => {
4
+ beforeAll ( ( ) => {
5
+ jest . useFakeTimers ( ) ;
6
+ jest . setSystemTime ( new Date ( '2024-01-01T00:00:00.000Z' ) ) ;
7
+ } ) ;
8
+
9
+ afterAll ( ( ) => {
10
+ jest . useRealTimers ( ) ;
11
+ } ) ;
12
+
13
+ test ( "timestamp and isoTimestamp should return mocked time values" , ( ) => {
14
+ const expectedTimestamp = '1704067200' ;
15
+ const expectedIsoTimestamp = '2024-01-01T00:00:00.000Z' ;
16
+
17
+ expect ( mockDataFunctions . timestamp ( ) ) . toBe ( expectedTimestamp ) ;
18
+ expect ( mockDataFunctions . isoTimestamp ( ) ) . toBe ( expectedIsoTimestamp ) ;
19
+ } ) ;
20
+
4
21
test ( "all values should match their expected patterns" , ( ) => {
5
22
const patterns : Record < string , RegExp > = {
6
23
guid : / ^ [ \d a - f ] { 8 } - [ \d a - f ] { 4 } - [ \d a - f ] { 4 } - [ \d a - f ] { 4 } - [ \d a - f ] { 12 } $ / ,
7
- timestamp : / ^ \d { 13 , } $ / ,
8
- isoTimestamp : / ^ \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } \. \d { 3 } Z $ / ,
9
24
randomUUID : / ^ [ \d a - f ] { 8 } - [ \d a - f ] { 4 } - [ \d a - f ] { 4 } - [ \d a - f ] { 4 } - [ \d a - f ] { 12 } $ / ,
10
25
randomAlphaNumeric : / ^ [ \w ] $ / ,
11
26
randomBoolean : / ^ ( t r u e | f a l s e ) $ / ,
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ import { faker } from '@faker-js/faker';
2
2
3
3
export const mockDataFunctions = {
4
4
guid : ( ) => faker . string . uuid ( ) ,
5
- timestamp : ( ) => faker . date . anytime ( ) . getTime ( ) . toString ( ) ,
6
- isoTimestamp : ( ) => faker . date . anytime ( ) . toISOString ( ) ,
5
+ timestamp : ( ) => Math . floor ( Date . now ( ) / 1000 ) . toString ( ) ,
6
+ isoTimestamp : ( ) => new Date ( ) . toISOString ( ) ,
7
7
randomUUID : ( ) => faker . string . uuid ( ) ,
8
8
randomAlphaNumeric : ( ) => faker . string . alphanumeric ( ) ,
9
9
randomBoolean : ( ) => faker . datatype . boolean ( ) ,
You can’t perform that action at this time.
0 commit comments