/*! * @license * Copyright Squiz Australia Pty Ltd. All Rights Reserved. */ import { faker } from '@faker-js/faker/locale/en'; import { JOB_EXECUTION_STATUS } from '../../../constants/JobExecutionStatus.constants'; import { ENTITY_TYPES } from '../../../constants/Repository.constants'; import { JobExecutionDto, JobExecutionRecord } from '../JobExecution'; export const createMockJobExecutionDto = (partialRecord: Partial = {}): JobExecutionDto => { const tenant = faker.string.uuid(); const jobName = partialRecord.jobName ?? faker.lorem.word(); const timeQueued = faker.date.recent().toISOString(); const id = `${timeQueued}-${faker.string.uuid()}`; const version = Array.from({ length: 3 }) .map(() => faker.number.int()) .join('.'); const status = partialRecord.status ?? faker.helpers.arrayElement(Object.values(JOB_EXECUTION_STATUS)); const input = 'input' in partialRecord ? partialRecord.input : faker.helpers.arrayElement([ faker.datatype.boolean(), faker.lorem.word(), faker.number.int(), { [faker.lorem.word()]: faker.lorem.words }, null, undefined, ]); return { context: { S: partialRecord.context ?? faker.string.uuid(), }, ecsTaskId: partialRecord.ecsTaskId ? { S: partialRecord.ecsTaskId } : { NULL: true }, gsi1pk: { S: `${ENTITY_TYPES.jobExecution}~${status}`, }, id: { S: partialRecord.id ?? id, }, jobName: { S: jobName, }, lsi1sk: { S: `${status}~${jobName}`, }, pk: { S: partialRecord.pk ?? `${ENTITY_TYPES.jobExecution}~${tenant}`, }, sk: { S: partialRecord.sk ?? `${jobName}~${id}`, }, status: { S: status, }, timeFinished: partialRecord.timeFinished ? { S: partialRecord.timeFinished } : { NULL: true }, timeQueued: { S: partialRecord.timeQueued ?? timeQueued, }, timeStarted: partialRecord.timeStarted ? { S: partialRecord.timeStarted } : { NULL: true }, version: { S: partialRecord.version ?? version, }, input: input === undefined || input === null ? { NULL: true } : { S: JSON.stringify(input) }, retryCount: { N: String(partialRecord.retryCount ?? 0), }, lastFailureReason: partialRecord.lastFailureReason ? { S: partialRecord.lastFailureReason } : { NULL: true }, retryAfter: partialRecord.retryAfter ? { S: partialRecord.retryAfter } : { NULL: true }, }; }; export const createMockJobExecutionDtos = (size?: number): Array => { const randomSize = size ?? faker.number.int({ max: 3, min: 1 }); return Array.from({ length: randomSize }).map(() => createMockJobExecutionDto()); };