Skip to content

Commit

Permalink
fix(lambda): Split Spa & NOSO timestamp bugs (#1165)
Browse files Browse the repository at this point in the history
* added type for statusDate & also changed NOSO timestamp to use same time as others

---------

Co-authored-by: tiffanyvu <tiffany.v330@gmail.com>
  • Loading branch information
andieswift and tiffanyvu authored Feb 20, 2025
1 parent 1bd3cc6 commit 31e7968
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 32 deletions.
28 changes: 28 additions & 0 deletions lib/lambda/sinkChangelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ describe("syncing Changelog events", () => {
isAdminChange: true,
adminChangeType: "update-id",
idToBeUpdated: TEST_ITEM_ID,
makoChangedDate: TIMESTAMP,
changedDate: TIMESTAMP,
statusDate: TIMESTAMP,
timestamp: TIMESTAMP,
}),
offset: 3,
Expand Down Expand Up @@ -208,6 +211,9 @@ describe("syncing Changelog events", () => {
isAdminChange: true,
adminChangeType: "update-values",
additionalInformation: "changed additional information",
makoChangedDate: TIMESTAMP,
changedDate: TIMESTAMP,
statusDate: TIMESTAMP,
timestamp: TIMESTAMP,
}),
offset: 3,
Expand All @@ -230,6 +236,9 @@ describe("syncing Changelog events", () => {
submitterName: "George Harrison",
submitterEmail: "george@example.com",
additionalInformation: "changed additional information",
makoChangedDate: expect.any(Number),
changedDate: expect.any(Number),
statusDate: expect.any(Number),
timestamp: expect.any(Number),
},
]);
Expand All @@ -249,6 +258,9 @@ describe("syncing Changelog events", () => {
isAdminChange: true,
adminChangeType: "update-values",
additionalInformation: "changed additional information",
makoChangedDate: TIMESTAMP,
changedDate: TIMESTAMP,
statusDate: TIMESTAMP,
timestamp: TIMESTAMP,
}),
offset: 3,
Expand All @@ -264,6 +276,9 @@ describe("syncing Changelog events", () => {
isAdminChange: true,
adminChangeType: "update-id",
idToBeUpdated: TEST_ITEM_ID,
makoChangedDate: TIMESTAMP,
changedDate: TIMESTAMP,
statusDate: TIMESTAMP,
timestamp: TIMESTAMP,
}),
offset: 3,
Expand Down Expand Up @@ -293,6 +308,9 @@ describe("syncing Changelog events", () => {
submitterName: "George Harrison",
submitterEmail: "george@example.com",
additionalInformation: "changed additional information",
makoChangedDate: expect.any(Number),
changedDate: expect.any(Number),
statusDate: expect.any(Number),
timestamp: expect.any(Number),
},
{
Expand All @@ -306,6 +324,9 @@ describe("syncing Changelog events", () => {
submitterName: "George Harrison",
submitterEmail: "george@example.com",
additionalInformation: "changed additional information",
makoChangedDate: expect.any(Number),
changedDate: expect.any(Number),
statusDate: expect.any(Number),
timestamp: expect.any(Number),
},
...expectedChangelogs,
Expand Down Expand Up @@ -359,6 +380,10 @@ describe("syncing Changelog events", () => {
deleted: false,
submitterName: "George Harrison",
submitterEmail: "george@example.com",
makoChangedDate: TIMESTAMP,
changedDate: TIMESTAMP,
statusDate: TIMESTAMP,
timestamp: TIMESTAMP,
}),
offset: 3,
}),
Expand All @@ -383,6 +408,9 @@ describe("syncing Changelog events", () => {
packageId: TEST_ITEM_ID,
submitterName: "George Harrison",
submitterEmail: "george@example.com",
makoChangedDate: expect.any(Number),
changedDate: expect.any(Number),
statusDate: expect.any(Number),
timestamp: expect.any(Number),
},
]);
Expand Down
24 changes: 24 additions & 0 deletions lib/lambda/sinkMainProcessors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => {
changeMade: "ID has been updated.",
submitterName: "George Harrison",
submitterEmail: "george@example.com",
makoChangedDate: TIMESTAMP,
changedDate: TIMESTAMP,
statusDate: TIMESTAMP,
timestamp: TIMESTAMP,
}),
}),
],
Expand All @@ -327,6 +331,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => {
changeMade: "ID has been updated.",
submitterName: "George Harrison",
submitterEmail: "george@example.com",
makoChangedDate: TIMESTAMP,
changedDate: TIMESTAMP,
statusDate: TIMESTAMP,
timestamp: TIMESTAMP,
},
]);
});
Expand All @@ -345,6 +353,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => {
changeMade: "title has been updated.",
submitterName: "George Harrison",
submitterEmail: "george@example.com",
makoChangedDate: TIMESTAMP,
changedDate: TIMESTAMP,
statusDate: TIMESTAMP,
timestamp: TIMESTAMP,
}),
}),
],
Expand All @@ -360,6 +372,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => {
changeMade: "title has been updated.",
submitterName: "George Harrison",
submitterEmail: "george@example.com",
makoChangedDate: TIMESTAMP,
changedDate: TIMESTAMP,
statusDate: TIMESTAMP,
timestamp: TIMESTAMP,
},
]);
});
Expand All @@ -377,6 +393,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => {
deleted: false,
submitterName: "George Harrison",
submitterEmail: "george@example.com",
makoChangedDate: TIMESTAMP,
changedDate: TIMESTAMP,
statusDate: TIMESTAMP,
timestamp: TIMESTAMP,
}),
}),
],
Expand All @@ -391,6 +411,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => {
deleted: false,
submitterName: "George Harrison",
submitterEmail: "george@example.com",
makoChangedDate: TIMESTAMP,
changedDate: TIMESTAMP,
statusDate: TIMESTAMP,
timestamp: TIMESTAMP,
},
]);
});
Expand Down
14 changes: 5 additions & 9 deletions lib/lambda/submit/submitSplitSPA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ import { events } from "shared-types/events";
import { getNextSplitSPAId } from "./getNextSplitSPAId";
import { z } from "zod";

/*
EXAMPLE EVENT JSON:
{
"body": {
"packageId": "MD-25-9999"
}
}
*/

/** @typedef {object} json
* @property {object} body
* @property {string} body.packageId
*/
const sendSubmitSplitSPAMessage = async (currentPackage: ItemResult) => {
const topicName = process.env.topicName as string;
if (!topicName) {
Expand Down Expand Up @@ -46,6 +41,7 @@ const sendSubmitSplitSPAMessage = async (currentPackage: ItemResult) => {
makoChangedDate: currentTime,
changedDate: currentTime,
timestamp: currentTime,
statusDate: currentTime,
origin: "OneMAC",
changeMade: "OneMAC Admin has added a package to OneMAC.",
changeReason: "Per request from CMS, this package was added to OneMAC.",
Expand Down
21 changes: 17 additions & 4 deletions lib/lambda/update/adminChangeSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ export const deleteAdminChangeSchema = z
id: z.string(),
deleted: z.boolean(),
adminChangeType: z.literal("delete"),
makoChangedDate: z.number(),
changedDate: z.number(),
statusDate: z.number(),
timestamp: z.number(),
})
.and(z.record(z.string(), z.any()));

export const updateValuesAdminChangeSchema = z
.object({
id: z.string(),
adminChangeType: z.literal("update-values"),
makoChangedDate: z.number(),
changedDate: z.number(),
statusDate: z.number(),
timestamp: z.number(),
})
.and(z.record(z.string(), z.any()));

Expand All @@ -20,6 +28,10 @@ export const updateIdAdminChangeSchema = z
id: z.string(),
adminChangeType: z.literal("update-id"),
idToBeUpdated: z.string(),
makoChangedDate: z.number(),
changedDate: z.number(),
statusDate: z.number(),
timestamp: z.number(),
})
.and(z.record(z.string(), z.any()));

Expand All @@ -28,6 +40,10 @@ export const splitSPAAdminChangeSchema = z
id: z.string(),
adminChangeType: z.literal("split-spa"),
idToBeUpdated: z.string(),
makoChangedDate: z.number(),
changedDate: z.number(),
statusDate: z.number(),
timestamp: z.number(),
})
.and(z.record(z.string(), z.any()));

Expand All @@ -37,7 +53,6 @@ export const transformDeleteSchema = (offset: number) =>
event: "delete",
packageId: data.id,
id: `${data.id}-${offset}`,
timestamp: Date.now(),
}));

export const transformUpdateValuesSchema = (offset: number) =>
Expand All @@ -46,15 +61,13 @@ export const transformUpdateValuesSchema = (offset: number) =>
event: "update-values",
packageId: data.id,
id: `${data.id}-${offset}`,
timestamp: Date.now(),
}));

export const transformedUpdateIdSchema = updateIdAdminChangeSchema.transform((data) => ({
...data,
event: "update-id",
packageId: data.id,
id: `${data.id}`,
timestamp: Date.now(),
}));

export const transformedSplitSPASchema = splitSPAAdminChangeSchema.transform((data) => ({
Expand Down Expand Up @@ -82,6 +95,7 @@ export const extendSubmitNOSOAdminSchema = submitNOSOAdminSchema.extend({
makoChangedDate: z.number(),
changedDate: z.number(),
statusDate: z.number(),
timestamp: z.number(),
isAdminChange: z.boolean(),
state: z.string(),
event: z.string(),
Expand All @@ -95,5 +109,4 @@ export const transformSubmitValuesSchema = extendSubmitNOSOAdminSchema.transform
event: "NOSO",
id: data.id,
packageId: data.id,
timestamp: Date.now(),
}));
32 changes: 13 additions & 19 deletions lib/lambda/update/submitNOSO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,18 @@ import { z } from "zod";

import { getStatus } from "shared-types";

/*
EXAMPLE EVENT JSON:
{
"body": {
"id": "CO-34304.R00.01",
"authority": "1915(c)",
"status": "Submitted",
"submitterEmail": "george@example.com",
"submitterName": "George Harrison",
"adminChangeType": "NOSO",
"mockEvent": "app-k", //needed for future actions
"changeMade": "CO-34304.R00.01 added to OneMAC.Package not originally submitted in OneMAC. Contact your CPOC to verify the initial submission documents.",
"changeReason": "Per request from CMS, this package was added to OneMAC."
}
}
*/

/** @typedef {object} json
* @property {object} body
* @property {string} body.id
* @property {string} body.authority
* @property {string} body.status
* @property {string} body.submitterEmail
* @property {string} body.submitterName
* @property {string} body.adminChangeType
* @property {string} body.mockEvent
* @property {string} body.changeMade
* @property {string} body.changeReason
*/
interface submitMessageType {
id: string;
authority: string;
Expand Down Expand Up @@ -61,6 +54,7 @@ const sendSubmitMessage = async (item: submitMessageType) => {
makoChangedDate: currentTime,
changedDate: currentTime,
statusDate: currentTime,
timestamp: currentTime,
}),
);

Expand Down
Loading

0 comments on commit 31e7968

Please sign in to comment.