From fa02161e973cc1a10547fa6a7175369fb693775b Mon Sep 17 00:00:00 2001 From: Brock Anderson Date: Wed, 11 Dec 2024 11:48:04 -0800 Subject: [PATCH 1/2] fixed 'updated date' in the updateAnnouncement method. it's now the current time in UTC --- backend/src/v1/services/announcements-service.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/src/v1/services/announcements-service.ts b/backend/src/v1/services/announcements-service.ts index 12e57e474..da02292e4 100644 --- a/backend/src/v1/services/announcements-service.ts +++ b/backend/src/v1/services/announcements-service.ts @@ -1,7 +1,6 @@ import { convert, DateTimeFormatter, - LocalDateTime, ZonedDateTime, ZoneId, } from '@js-joda/core'; @@ -15,6 +14,7 @@ import { import { DefaultArgs } from '@prisma/client/runtime/library'; import isEmpty from 'lodash/isEmpty'; import { config } from '../../config'; +import { deleteFiles } from '../../external/services/s3-api'; import { logger } from '../../logger'; import prisma from '../prisma/prisma-client'; import { PaginatedResult } from '../types'; @@ -26,7 +26,6 @@ import { } from '../types/announcements'; import { UserInputError } from '../types/errors'; import { utils } from './utils-service'; -import { deleteFiles } from '../../external/services/s3-api'; const saveHistory = async ( tx: Omit< @@ -321,7 +320,7 @@ export const announcementService = { input: AnnouncementDataType, currentUserId: string, ) { - const updateDate = convert(LocalDateTime.now(ZoneId.UTC)).toDate(); + const updateDate = convert(ZonedDateTime.now(ZoneId.UTC)).toDate(); await prisma.$transaction(async (tx) => { const announcementData = await tx.announcement.findUniqueOrThrow({ where: { From c8ef9aa0892ee3739e5896bf9acd976ca6a2a19f Mon Sep 17 00:00:00 2001 From: Brock Anderson Date: Wed, 11 Dec 2024 12:18:15 -0800 Subject: [PATCH 2/2] extended a unit test on updateAnnouncement to confirm that the correct 'updated_date' is saved to the db --- backend/src/v1/services/announcements-service.spec.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/src/v1/services/announcements-service.spec.ts b/backend/src/v1/services/announcements-service.spec.ts index f212e8578..743040309 100644 --- a/backend/src/v1/services/announcements-service.spec.ts +++ b/backend/src/v1/services/announcements-service.spec.ts @@ -694,6 +694,7 @@ describe('AnnouncementsService', () => { linkDisplayName: faker.lorem.words(3), linkUrl: faker.internet.url(), }; + const now = new Date(); await announcementService.updateAnnouncement( 'announcement-id', announcementInput, @@ -738,6 +739,16 @@ describe('AnnouncementsService', () => { }), }), ); + + //Ensure the update date saved to the database is approximately now + //(within 5 seconds of now) + const updateObj = mockUpdate.mock.calls[0][0]; + const updatedDate = updateObj.data.updated_date; + const expectedUpdateDate = now; + const updateDateDiffMs = + updatedDate.getTime() - expectedUpdateDate.getTime(); + expect(updateDateDiffMs).toBeGreaterThanOrEqual(0); + expect(updateDateDiffMs).toBeLessThan(5000); }); }); describe('with existing attachment resource', () => {