mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-24 13:15:40 +00:00
fix: ensure timestamp and isoTimestamp return current time instead of random values
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
import { mockDataFunctions } from "./faker-functions";
|
||||
|
||||
describe("mockDataFunctions Regex Validation", () => {
|
||||
test("timestamp and isoTimestamp should return current time values", () => {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const timestamp = parseInt(mockDataFunctions.timestamp());
|
||||
const isoTimestamp = new Date(mockDataFunctions.isoTimestamp()).getTime() / 1000;
|
||||
|
||||
// Allow for a 2-second difference to account for test execution time
|
||||
expect(Math.abs(timestamp - now)).toBeLessThanOrEqual(2);
|
||||
expect(Math.abs(isoTimestamp - now)).toBeLessThanOrEqual(2);
|
||||
});
|
||||
|
||||
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,}$/,
|
||||
timestamp: /^\d{10}$/,
|
||||
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]$/,
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user