Skip to content

Commit

Permalink
fix(tests): using resolvedOptions of Intl.DateTimeFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
lonelydev committed Oct 18, 2024
1 parent ecabb55 commit 3883039
Showing 1 changed file with 68 additions and 30 deletions.
98 changes: 68 additions & 30 deletions test/OnCallPaymentCalculator.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {describe, expect, test} from '@jest/globals';
import { describe, expect, test } from '@jest/globals';
import { OnCallPaymentsCalculator } from "../src/OnCallPaymentsCalculator";
import { OnCallPeriod } from '../src/OnCallPeriod';
import { OnCallUser } from '../src/OnCallUser';
import { convertTimezone } from '../src/DateUtilities';

var runtimeEnvTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
var runtimeEnvLocale = Intl.DateTimeFormat().resolvedOptions().locale;

describe('should calculate the payment for an on call user', () => {

var runtimeEnvTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
var runtimeEnvLocale = "en-US";

test('- when person continues to be on-call from end of Month to 12th of subsequent month', () => {
const since = new Date('2024-07-31T23:00:00+01:00');
const until = new Date('2024-08-12T10:00:00+01:00');
Expand All @@ -22,7 +22,7 @@ describe('should calculate the payment for an on call user', () => {
new OnCallPeriod(sinceInEnvTimezone, untilInEnvTimezone)
]
);

const calculator = new OnCallPaymentsCalculator();
expect(onCallUser.onCallPeriods).toBeDefined();
expect(onCallUser.onCallPeriods.length).toBe(1);
Expand All @@ -41,21 +41,19 @@ describe('should calculate the payment for an on call user', () => {
new OnCallPeriod(since, until)
]
);

const calculator = new OnCallPaymentsCalculator();
expect(onCallUser.onCallPeriods).toBeDefined();
expect(onCallUser.onCallPeriods.length).toBe(1);
expect(onCallUser.onCallPeriods[0].since).toEqual(since);
expect(onCallUser.onCallPeriods[0].until).toEqual(until);
expect(onCallUser.onCallPeriods[0].numberOfOOhWeekDays).toBe(5);
expect(onCallUser.onCallPeriods[0].numberOfOohWeekends).toBe(6);
expect(calculator.calculateOnCallPayment(onCallUser)).toBe(700);
});

test('- when person starts to be on-call from 28th of August 10am to end of August', () => {
const since = convertTimezone(
new Date('2024-08-28T10:00:00+01:00'),
runtimeEnvTimezone,
new Date('2024-08-28T10:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale);
const until = convertTimezone(new Date('2024-08-31T23:59:59+01:00'),
runtimeEnvTimezone,
Expand All @@ -67,12 +65,10 @@ describe('should calculate the payment for an on call user', () => {
new OnCallPeriod(since, until)
]
);

const calculator = new OnCallPaymentsCalculator();
expect(onCallUser.onCallPeriods).toBeDefined();
expect(onCallUser.onCallPeriods.length).toBe(1);
expect(onCallUser.onCallPeriods[0].since).toEqual(since);
expect(onCallUser.onCallPeriods[0].until).toEqual(until);
expect(onCallUser.onCallPeriods[0].numberOfOOhWeekDays).toBe(2);
expect(onCallUser.onCallPeriods[0].numberOfOohWeekends).toBe(1);
expect(calculator.calculateOnCallPayment(onCallUser)).toBe(175);
Expand All @@ -88,7 +84,7 @@ describe('should calculate the payment for an on call user', () => {
new OnCallPeriod(since, until)
]
);

const calculator = new OnCallPaymentsCalculator();
expect(onCallUser.onCallPeriods).toBeDefined();
expect(onCallUser.onCallPeriods.length).toBe(1);
Expand All @@ -107,13 +103,13 @@ describe('should calculate the payment for an on call user', () => {
[
new OnCallPeriod(
convertTimezone(
new Date('2024-08-01T00:00:00+01:00'),
runtimeEnvTimezone,
new Date('2024-08-01T00:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
),
convertTimezone(
new Date('2024-08-06T10:00:00+01:00'),
runtimeEnvTimezone,
new Date('2024-08-06T10:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
)
),
Expand All @@ -122,11 +118,11 @@ describe('should calculate the payment for an on call user', () => {
new Date('2024-08-28T10:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
),
),
convertTimezone(
new Date('2024-09-01T00:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
runtimeEnvTimezone,
runtimeEnvLocale
)
)
]
Expand Down Expand Up @@ -188,7 +184,7 @@ describe('should calculate the payment for an on call user', () => {
new Date('2024-08-21T10:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
),
),
convertTimezone(
new Date('2024-08-28T10:00:00+01:00'),
runtimeEnvTimezone,
Expand All @@ -198,7 +194,7 @@ describe('should calculate the payment for an on call user', () => {
]
)
];

const calculator = new OnCallPaymentsCalculator();
expect(calculator.calculateOnCallPayments(onCallUsers)).toStrictEqual({
"1PF7DNAV": 575,
Expand All @@ -216,22 +212,64 @@ describe('should be able to audit the payment for an on call user', () => {
'1PF7DNAV',
'YW Oncall',
[
new OnCallPeriod(new Date('2024-08-01T00:00:00+01:00'), new Date('2024-08-06T10:00:00+01:00')),
new OnCallPeriod(new Date('2024-08-28T10:00:00+01:00'), new Date('2024-09-01T00:00:00+01:00'))
new OnCallPeriod(
convertTimezone(
new Date('2024-08-01T00:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
),
convertTimezone(
new Date('2024-08-06T10:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
)
),
new OnCallPeriod(
convertTimezone(
new Date('2024-08-28T10:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
),
convertTimezone(
new Date('2024-09-01T00:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
)
)
]
),
new OnCallUser(
'PGO3DTM',
'SK Oncall',
[
new OnCallPeriod(new Date('2024-08-06T10:00:00+01:00'),
new Date('2024-08-15T10:00:00+01:00')),
new OnCallPeriod(new Date('2024-08-16T10:00:00+01:00'),
new Date('2024-08-21T10:00:00+01:00'))
new OnCallPeriod(
convertTimezone(
new Date('2024-08-06T10:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
),
convertTimezone(
new Date('2024-08-15T10:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
)
),
new OnCallPeriod(
convertTimezone(
new Date('2024-08-16T10:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
),
convertTimezone(
new Date('2024-08-21T10:00:00+01:00'),
runtimeEnvTimezone,
runtimeEnvLocale
)
)
]
)
];

expect(onCallUsers.length).toBe(2);
expect(onCallUsers[0].id).toBe('1PF7DNAV');
expect(onCallUsers[0].getTotalOohWeekDays()).toBe(4);
Expand Down

0 comments on commit 3883039

Please sign in to comment.