Skip to content
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

fix: GEO-988 - use UTC timezone for dates saved to the pay_transparency_reports table #604

Merged
merged 4 commits into from
Jul 18, 2024
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
25 changes: 25 additions & 0 deletions backend/src/v1/services/admin-report-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,31 @@ describe('admin-report-service', () => {
expect(report.admin_modified_date).toBe(report.report_unlock_date);
expect(report.admin_user_id).toBe('1234');
});
it('should update the report_unlock_date to the current date/time in UTC', async () => {
const updateSpy = jest.spyOn(
prismaClient.pay_transparency_report,
'update',
);
await adminReportService.changeReportLockStatus(
'4492feff-99d7-4b2b-8896-12a59a75d4e2',
'5678',
false,
);

const updateParam: any = updateSpy.mock.calls[0][0];
expect(updateParam.data.admin_modified_date).toBe(
updateParam.data.report_unlock_date,
);

//check that the unlock report date/time submitted to the database is approximately
//equal to the current UTC date/time
const currentDateUtc = convert(ZonedDateTime.now(ZoneId.UTC)).toDate();
const unlockDateDiffMs =
currentDateUtc.getTime() -
updateParam.data.report_unlock_date.getTime();
expect(unlockDateDiffMs).toBeGreaterThanOrEqual(0);
expect(unlockDateDiffMs).toBeLessThan(10000); //10 seconds
});
});

describe('getReportPdf', () => {
Expand Down
8 changes: 4 additions & 4 deletions backend/src/v1/services/admin-report-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convert, LocalDateTime, ZonedDateTime, ZoneId } from '@js-joda/core';
import { convert, ZonedDateTime, ZoneId } from '@js-joda/core';
import { Prisma } from '@prisma/client';
import prisma from '../prisma/prisma-client';
import prismaReadOnlyReplica from '../prisma/prisma-client-readonly-replica';
Expand Down Expand Up @@ -136,14 +136,14 @@ const adminReportService = {
where: { report_id: reportId },
});

const currentDate = convert(LocalDateTime.now(ZoneId.UTC)).toDate();
const currentDateUtc = convert(ZonedDateTime.now(ZoneId.UTC)).toDate();

await prisma.pay_transparency_report.update({
where: { report_id: reportId },
data: {
is_unlocked: isUnLocked,
report_unlock_date: currentDate,
admin_modified_date: currentDate,
report_unlock_date: currentDateUtc,
admin_modified_date: currentDateUtc,
admin_user: { connect: { idir_user_guid: idirGuid } },
},
});
Expand Down
9 changes: 9 additions & 0 deletions backend/src/v1/services/report-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
LocalDate,
TemporalAdjusters,
ZoneId,
ZonedDateTime,
convert,
nativeJs,
} from '@js-joda/core';
Expand Down Expand Up @@ -878,6 +879,14 @@ describe('publishReport', () => {
expect(updateStatement.where.report_id).toBe(
mockPublishedReportInDb.report_id,
);

// Expect the update date to be approximately equal to the current date
// in the UTC timezone (within 10 seconds)
const currentDateUtc = convert(ZonedDateTime.now(ZoneId.UTC)).toDate();
const dateDiffMs =
currentDateUtc.getTime() - updateStatement.data.update_date.getTime();
expect(dateDiffMs).toBeGreaterThanOrEqual(0);
expect(dateDiffMs).toBeLessThan(10000); //10 seconds
});
});
describe('if the given report has status=Draft, and there is an existing Published and locked report', () => {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/v1/services/report-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
LocalDate,
LocalDateTime,
TemporalAdjusters,
ZoneId,
ZonedDateTime,
convert,
nativeJs,
} from '@js-joda/core';
Expand Down Expand Up @@ -1321,7 +1321,7 @@ const reportService = {
pay_transparency_user: {
connect: { user_id: full_report_to_publish.user_id },
},
update_date: convert(LocalDateTime.now(ZoneId.UTC)).toDate(),
update_date: convert(ZonedDateTime.now(ZoneId.UTC)).toDate(), //current date/time in the UTC timezone
update_user: full_report_to_publish.update_user,
pay_transparency_calculated_data: {
createMany: {
Expand Down