Skip to content
Open
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
14 changes: 13 additions & 1 deletion lib/lambda/setupIndex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ describe("handler", () => {
deleted: { type: "boolean" },
finalDispositionDate: { type: "date" },
proposedDate: { type: "date" },
raiId: { type: "keyword" },
raiName: { type: "keyword" },
raiWithdrawnToggleDate: { type: "date" },
spaWaiverId: { type: "keyword" },
smartRecordType: { type: "keyword" },
statusDate: { type: "date" },
Expand All @@ -67,7 +70,16 @@ describe("handler", () => {
statusDate: { type: "date" },
},
);
expect(updateMappingSpy).toHaveBeenCalledTimes(2);
expect(updateMappingSpy).toHaveBeenCalledWith(
OPENSEARCH_DOMAIN,
`${OPENSEARCH_INDEX_NAMESPACE}changelog`,
{
raiId: { type: "keyword" },
raiName: { type: "keyword" },
raiWithdrawnToggleDate: { type: "date" },
},
);
expect(updateMappingSpy).toHaveBeenCalledTimes(3);

expect(callback).toHaveBeenCalledWith(null, { statusCode: 200 });
});
Expand Down
8 changes: 8 additions & 0 deletions lib/lambda/setupIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const handler: Handler = async (event, __, callback) => {
deleted: { type: "boolean" },
finalDispositionDate: { type: "date" },
proposedDate: { type: "date" },
raiId: { type: "keyword" },
raiName: { type: "keyword" },
raiWithdrawnToggleDate: { type: "date" },
spaWaiverId: { type: "keyword" },
smartRecordType: { type: "keyword" },
statusDate: { type: "date" },
Expand All @@ -38,6 +41,11 @@ export const handler: Handler = async (event, __, callback) => {
await manageIndexResource({
osDomain: event.osDomain,
index: `${event.indexNamespace}changelog`,
update: {
raiId: { type: "keyword" },
raiName: { type: "keyword" },
raiWithdrawnToggleDate: { type: "date" },
},
});
await manageIndexResource({
osDomain: event.osDomain,
Expand Down
78 changes: 76 additions & 2 deletions lib/lambda/sinkSmart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,12 +595,87 @@ describe("SMART operation dispatch", () => {
);
});

it("consumes MSP_RAI_WITHDRAWAL_TOGGLED for an existing package", async () => {
const packageId = "AL-26-0001-GATT";
const spaWaiverId = "a0ncp000006RG8TAAW";
const raiId = "a0qcp000005GbK5AAK";
const toggleDate = "2026-08-17T16:11:46.000Z";
const raiTogglePayload = {
...smartEvent,
spaWaiverId,
id: packageId,
correlationId: "",
authority: "Medicaid SPA",
status: "Pending Second Clock",
createdAt: toggleDate,
operationType: "MSP_RAI_WITHDRAWAL_TOGGLED",
raiId,
raiName: `${packageId}-RAI`,
raiWithdrawnToggle: true,
raiWithdrawnToggleDate: toggleDate,
};
const existingPackage = {
id: packageId,
origin: "OneMAC",
authority: "Medicaid SPA",
state: "AL",
seatoolStatus: SEATOOL_STATUS.PENDING,
cmsStatus: "Pending",
stateStatus: "Under Review",
raiRequestedDate: "2026-07-01T12:00:00.000Z",
raiReceivedDate: "2026-08-01T12:00:00.000Z",
raiWithdrawEnabled: false,
spaWaiverId,
deleted: false,
};
getItemSpy.mockResolvedValue({
found: true,
_id: packageId,
_source: existingPackage,
} as Awaited<ReturnType<typeof os.getItem>>);
searchSpy.mockImplementation(async (_domain, index) =>
String(index).endsWith("main")
? { hits: { hits: [{ _id: packageId, _source: existingPackage }] } }
: { hits: { hits: [] } },
);

await expect(
invokeHandler(createSmartEvent(createSmartRecord(raiTogglePayload, packageId))),
).resolves.toBeUndefined();

expect(updateItemSpy).toHaveBeenCalledWith(
expect.anything(),
expect.stringMatching(/main$/),
packageId,
expect.objectContaining({
raiWithdrawEnabled: true,
raiId,
raiWithdrawnToggleDate: toggleDate,
}),
);
expect(bulkUpdateDataSpy).toHaveBeenCalledWith(
expect.anything(),
expect.stringMatching(/changelog$/),
[
expect.objectContaining({
packageId,
event: "toggle-withdraw-rai",
timestamp: Date.parse(toggleDate),
isAdminChange: true,
raiWithdrawEnabled: true,
}),
],
{ throwOnBulkError: true },
);
expect(createItemSpy).not.toHaveBeenCalled();
expect(publishSmartIngestErrorSpy).not.toHaveBeenCalled();
});

it.each([
"MSP_MANUAL_RECORD_CREATED",
"MSP_STATUS_UPDATED",
"MSP_ADMINISTRATIVE_FIELD_UPDATED",
"MSP_ASSIGNMENT_UPDATED",
"MSP_RAI_WITHDRAWAL_TOGGLED",
"NOT_A_REAL_TYPE",
undefined,
])(
Expand Down Expand Up @@ -635,7 +710,6 @@ describe("SMART operation dispatch", () => {
"MSP_STATUS_UPDATED",
"MSP_ADMINISTRATIVE_FIELD_UPDATED",
"MSP_ASSIGNMENT_UPDATED",
"MSP_RAI_WITHDRAWAL_TOGGLED",
"NOT_A_REAL_TYPE",
undefined,
])(
Expand Down
Loading
Loading