Skip to content

fix: ensure timestamp and isoTimestamp return current time instead of random values #4679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions packages/bruno-common/src/utils/faker-functions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { mockDataFunctions } from "./faker-functions";

describe("mockDataFunctions Regex Validation", () => {
beforeAll(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date('2024-01-01T00:00:00.000Z'));
});

afterAll(() => {
jest.useRealTimers();
});

test("timestamp and isoTimestamp should return mocked time values", () => {
const expectedTimestamp = '1704067200';
const expectedIsoTimestamp = '2024-01-01T00:00:00.000Z';

expect(mockDataFunctions.timestamp()).toBe(expectedTimestamp);
expect(mockDataFunctions.isoTimestamp()).toBe(expectedIsoTimestamp);
});

test("all values should match their expected patterns", () => {
const patterns: Record<string, RegExp> = {
guid: /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/,
timestamp: /^\d{13,}$/,
isoTimestamp: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/,
randomUUID: /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/,
randomAlphaNumeric: /^[\w]$/,
randomBoolean: /^(true|false)$/,
Expand Down
4 changes: 2 additions & 2 deletions packages/bruno-common/src/utils/faker-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { faker } from '@faker-js/faker';

export const mockDataFunctions = {
guid: () => faker.string.uuid(),
timestamp: () => faker.date.anytime().getTime().toString(),
isoTimestamp: () => faker.date.anytime().toISOString(),
timestamp: () => Math.floor(Date.now() / 1000).toString(),
isoTimestamp: () => new Date().toISOString(),
randomUUID: () => faker.string.uuid(),
randomAlphaNumeric: () => faker.string.alphanumeric(),
randomBoolean: () => faker.datatype.boolean(),
Expand Down
Loading