Skip to content

Commit 73b0f09

Browse files
authored
Merge pull request #4679 from anusree-bruno/bugfix/timestamp-current-time
fix: ensure timestamp and isoTimestamp return current time instead of random values
2 parents 51f36b1 + 8ac916b commit 73b0f09

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

packages/bruno-common/src/utils/faker-functions.spec.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
import { mockDataFunctions } from "./faker-functions";
22

33
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+
421
test("all values should match their expected patterns", () => {
522
const patterns: Record<string, RegExp> = {
623
guid: /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/,
7-
timestamp: /^\d{13,}$/,
8-
isoTimestamp: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/,
924
randomUUID: /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/,
1025
randomAlphaNumeric: /^[\w]$/,
1126
randomBoolean: /^(true|false)$/,

packages/bruno-common/src/utils/faker-functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { faker } from '@faker-js/faker';
22

33
export const mockDataFunctions = {
44
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(),
77
randomUUID: () => faker.string.uuid(),
88
randomAlphaNumeric: () => faker.string.alphanumeric(),
99
randomBoolean: () => faker.datatype.boolean(),

0 commit comments

Comments
 (0)