Skip to content

Commit

Permalink
fake time for time based unit tests (#772)
Browse files Browse the repository at this point in the history
Fix unit tests that depends on the current time to format dates. issue solved by faking system time for those test cases.
  • Loading branch information
Assem-Hafez authored Jan 2, 2025
1 parent 79cca64 commit 91dfe18
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {
} from '../../workflow-history.types';
import getCommonHistoryGroupFields from '../get-common-history-group-fields';

jest.useFakeTimers().setSystemTime(new Date('2024-05-25'));

describe('getCommonHistoryGroupFields', () => {
it('should return group eventsMetadata with correct labels', () => {
const group = setup({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
import type { ActivityHistoryEvent } from '../../../workflow-history.types';
import getActivityGroupFromEvents from '../get-activity-group-from-events';

jest.useFakeTimers().setSystemTime(new Date('2024-05-25'));

describe('getActivityGroupFromEvents', () => {
it('should return a group with a proper label when scheduled event exists', () => {
const events: ActivityHistoryEvent[] = [scheduleActivityTaskEvent];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import type { ChildWorkflowExecutionHistoryEvent } from '../../../workflow-history.types';
import getChildWorkflowExecutionGroupFromEvents from '../get-child-workflow-execution-group-from-events';

jest.useFakeTimers().setSystemTime(new Date('2024-05-25'));

describe('getChildWorkflowExecutionGroupFromEvents', () => {
it('should return a group with a proper label', () => {
const events: ChildWorkflowExecutionHistoryEvent[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
import type { DecisionHistoryEvent } from '../../../workflow-history.types';
import getDecisionGroupFromEvents from '../get-decision-group-from-events';

jest.useFakeTimers().setSystemTime(new Date('2024-05-25'));

describe('getDecisionGroupFromEvents', () => {
it('should return a group with a proper label when scheduled event exists', () => {
const events: DecisionHistoryEvent[] = [scheduleDecisionTaskEvent];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
import type { RequestCancelExternalWorkflowExecutionHistoryEvent } from '../../../workflow-history.types';
import getRequestCancelExternalWorkflowExecutionGroupFromEvents from '../get-request-cancel-external-workflow-execution-group-from-events';

jest.useFakeTimers().setSystemTime(new Date('2024-05-25'));

describe('getRequestCancelExternalWorkflowExecutionGroupFromEvents', () => {
it('should return a group with a correct label', () => {
const events: RequestCancelExternalWorkflowExecutionHistoryEvent[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
import type { SignalExternalWorkflowExecutionHistoryEvent } from '../../../workflow-history.types';
import getSignalExternalWorkflowExecutionGroupFromEvents from '../get-signal-external-workflow-execution-group-from-events';

jest.useFakeTimers().setSystemTime(new Date('2024-05-25'));

describe('getSignalExternalWorkflowExecutionGroupFromEvents', () => {
it('should return a group with a correct label', () => {
const events: SignalExternalWorkflowExecutionHistoryEvent[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
import type { TimerHistoryEvent } from '../../../workflow-history.types';
import getTimerGroupFromEvents from '../get-timer-group-from-events';

jest.useFakeTimers().setSystemTime(new Date('2024-05-25'));

describe('getTimerGroupFromEvents', () => {
it('should return a group with a correct label', () => {
const events: TimerHistoryEvent[] = [startTimerTaskEvent];
Expand Down

0 comments on commit 91dfe18

Please sign in to comment.