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

Val -> Prod #4384

Merged
merged 34 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
49a78c0
MDCT-1992: Update ReportDrawer so admins can't submit for users (#4158)
Sep 30, 2022
114f003
page structure changes (dynamic drawer step 1) (#4172)
braxex Oct 3, 2022
3ecab67
MDCT-1993 api updates (#4180)
gmrabian Oct 3, 2022
c4c5d3d
simplify dynamodb mocking (#4181)
gmrabian Oct 3, 2022
533a24e
Update DashboardPage.tsx (#4189)
scwambach Oct 3, 2022
7bf0711
remove delete button flash (#4168)
scwambach Oct 3, 2022
5762054
renamed ReportPage types (#4201)
braxex Oct 4, 2022
4917888
[MDCT-1959] Clear nested fields after they are hidden from view (#4125)
juliuscaesar Oct 4, 2022
09bc493
MDCT-1995: Add Delete Modal to DynamicFields (#4188)
Oct 5, 2022
6b02ebd
fix type error (#4238)
braxex Oct 5, 2022
4ebcf8b
ModalDrawerReportPage step 1 (initial state, creation, & initial card…
braxex Oct 6, 2022
61c6876
Mdct 2000 (#4236)
scwambach Oct 6, 2022
9d43e0b
MDCT-1979: Delete Measure Details (#4222)
Oct 6, 2022
90adda6
Update mcpar.json (#4258)
scwambach Oct 6, 2022
c5f7440
added spreadsheet widgets (#4248)
scwambach Oct 6, 2022
e175126
MDCT-1980: Edit Measure Details (#4221)
karla-vm Oct 7, 2022
0bbb72c
redline section A (#4264)
britt-mo Oct 7, 2022
f5ddeaa
fix nested field validation bug (#4268)
braxex Oct 7, 2022
34a414c
accept valid 404 use case (#4276)
gmrabian Oct 7, 2022
0aaa440
Enter access measure details (#4247)
braxex Oct 7, 2022
1a147a1
edit access measure details (last part of ModalDrawerReportPage) (#4287)
braxex Oct 7, 2022
3add8da
Simplify hydration (#4301)
gmrabian Oct 7, 2022
62e129a
MDCT-2009 add skipnav to sidebar (#4315)
gmrabian Oct 11, 2022
863b04a
MDCT-2004: Remove React-Query Dependency (#4314)
Oct 11, 2022
0480598
MDCT-2016: Section C Redlines (#4253)
Oct 11, 2022
62f1a6f
MDCT-2027: Scotts Great Ampersand (#4346)
Oct 12, 2022
6f730be
MDT-2029: Loading Spinner for "Current Banner" Section (Admin Only) (…
karla-vm Oct 12, 2022
5b7ed80
Customize entity card per type (#4336)
gmrabian Oct 12, 2022
66f5816
Update README.md (#4340)
britt-mo Oct 12, 2022
88a6819
parse out entities util (#4337)
gmrabian Oct 12, 2022
b4a6fc1
skipnav: a tragedy in 3 acts (#4351)
braxex Oct 12, 2022
71793ec
Fix amazingly huge drawer (#4372)
Oct 12, 2022
18e42a0
unwrap (#4376)
gmrabian Oct 12, 2022
06e3c58
Merge pull request #4383 from CMSgov/main
Oct 12, 2022
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
13 changes: 1 addition & 12 deletions services/app-api/handlers/banners/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import { proxyEvent } from "../../utils/testing/proxyEvent";
import { StatusCodes } from "../../utils/types/types";
import error from "../../utils/constants/constants";

jest.mock("../../utils/dynamo/dynamodb-lib", () => ({
__esModule: true,
default: {
put: jest.fn(),
},
}));

jest.mock("../../utils/auth/authorization", () => ({
isAuthorized: jest.fn().mockReturnValue(true),
hasPermissions: jest.fn().mockReturnValueOnce(false).mockReturnValue(true),
Expand All @@ -36,10 +29,6 @@ const testEventWithInvalidData: APIGatewayProxyEvent = {
};

describe("Test createBanner API method", () => {
beforeEach(() => {
process.env["BANNER_TABLE_NAME"] = "fakeBannerTable";
});

test("Test unauthorized banner creation throws 403 error", async () => {
const res = await createBanner(testEvent, null);
expect(res.statusCode).toBe(403);
Expand All @@ -48,7 +37,7 @@ describe("Test createBanner API method", () => {

test("Test Successful Run of Banner Creation", async () => {
const res = await createBanner(testEvent, null);
expect(res.statusCode).toBe(StatusCodes.SUCCESS);
expect(res.statusCode).toBe(StatusCodes.CREATED);
expect(res.body).toContain("test banner");
expect(res.body).toContain("test description");
});
Expand Down
2 changes: 1 addition & 1 deletion services/app-api/handlers/banners/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const createBanner = handler(async (event, _context) => {
},
};
await dynamoDb.put(params);
return { status: StatusCodes.SUCCESS, body: params };
return { status: StatusCodes.CREATED, body: params };
}
}
});
12 changes: 0 additions & 12 deletions services/app-api/handlers/banners/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import { proxyEvent } from "../../utils/testing/proxyEvent";
import { StatusCodes } from "../../utils/types/types";
import error from "../../utils/constants/constants";

jest.mock("../../utils/dynamo/dynamodb-lib", () => ({
__esModule: true,
default: {
delete: jest.fn(),
},
}));

jest.mock("../../utils/auth/authorization", () => ({
isAuthorized: jest.fn().mockReturnValue(true),
hasPermissions: jest.fn().mockReturnValueOnce(false).mockReturnValue(true),
Expand All @@ -28,10 +21,6 @@ const testEvent: APIGatewayProxyEvent = {
};

describe("Test deleteBanner API method", () => {
beforeEach(() => {
process.env["BANNER_TABLE_NAME"] = "fakeBannerTable";
});

test("Test not authorized to delete banner throws 403 error", async () => {
const res = await deleteBanner(testEvent, null);

Expand All @@ -43,7 +32,6 @@ describe("Test deleteBanner API method", () => {
const res = await deleteBanner(testEvent, null);

expect(res.statusCode).toBe(StatusCodes.SUCCESS);
expect(res.body).toContain("fakeBannerTable");
expect(res.body).toContain("testKey");
});

Expand Down
30 changes: 11 additions & 19 deletions services/app-api/handlers/banners/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,10 @@ import { APIGatewayProxyEvent } from "aws-lambda";
import { proxyEvent } from "../../utils/testing/proxyEvent";
import { StatusCodes } from "../../utils/types/types";
import error from "../../utils/constants/constants";

jest.mock("../../utils/dynamo/dynamodb-lib", () => ({
__esModule: true,
default: {
get: jest.fn().mockReturnValue({
Item: {
createdAt: 1654198665696,
endDate: 1657252799000,
lastAltered: 1654198665696,
description: "testDesc",
title: "testTitle",
key: "admin-banner-id",
startDate: 1641013200000,
},
}),
},
}));
import {
mockBannerResponse,
mockDocumentClient,
} from "../../utils/testing/setupJest";

jest.mock("../../utils/auth/authorization", () => ({
isAuthorized: jest.fn().mockReturnValue(true),
Expand All @@ -38,11 +25,16 @@ const testEvent: APIGatewayProxyEvent = {
};

describe("Test fetchBanner API method", () => {
beforeEach(() => {
process.env["BANNER_TABLE_NAME"] = "fakeBannerTable";
test("Test Report not found Fetch", async () => {
mockDocumentClient.get.promise.mockReturnValueOnce({ Item: undefined });
const res = await fetchBanner(testEvent, null);
expect(res.statusCode).toBe(StatusCodes.NOT_FOUND);
});

test("Test Successful Banner Fetch", async () => {
mockDocumentClient.get.promise.mockReturnValueOnce({
Item: mockBannerResponse,
});
const res = await fetchBanner(testEvent, null);

expect(res.statusCode).toBe(StatusCodes.SUCCESS);
Expand Down
9 changes: 7 additions & 2 deletions services/app-api/handlers/banners/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export const fetchBanner = handler(async (event, _context) => {
key: event?.pathParameters?.bannerId!,
},
};
const queryResponse = await dynamoDb.get(params);
return { status: StatusCodes.SUCCESS, body: queryResponse };
const response = await dynamoDb.get(params);

let status = StatusCodes.SUCCESS;
if (!response?.Item) {
status = StatusCodes.NOT_FOUND;
}
return { status: status, body: response };
});
9 changes: 1 addition & 8 deletions services/app-api/handlers/reports/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import { StatusCodes } from "../../utils/types/types";
import { mockReport } from "../../utils/testing/setupJest";
import error from "../../utils/constants/constants";

jest.mock("../../utils/dynamo/dynamodb-lib", () => ({
__esModule: true,
default: {
put: jest.fn(),
},
}));

jest.mock("../../utils/auth/authorization", () => ({
isAuthorized: jest.fn().mockResolvedValue(true),
hasPermissions: jest.fn().mockReturnValueOnce(false).mockReturnValue(true),
Expand Down Expand Up @@ -55,7 +48,7 @@ describe("Test createReport API method", () => {
const res = await createReport(creationEvent, null);

const body = JSON.parse(res.body);
expect(res.statusCode).toBe(StatusCodes.SUCCESS);
expect(res.statusCode).toBe(StatusCodes.CREATED);
expect(body.status).toContain("Not started");
});

Expand Down
2 changes: 1 addition & 1 deletion services/app-api/handlers/reports/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const createReport = handler(async (event, _context) => {
};
await dynamoDb.put(reportParams);
return {
status: StatusCodes.SUCCESS,
status: StatusCodes.CREATED,
body: { ...reportParams.Item },
};
} else throw new Error(error.MISSING_DATA);
Expand Down
19 changes: 11 additions & 8 deletions services/app-api/handlers/reports/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import { APIGatewayProxyEvent } from "aws-lambda";
import { proxyEvent } from "../../utils/testing/proxyEvent";
import { StatusCodes } from "../../utils/types/types";
import error from "../../utils/constants/constants";
import { mockReport } from "../../utils/testing/setupJest";

jest.mock("../../utils/dynamo/dynamodb-lib", () => ({
__esModule: true,
default: {
query: jest.fn(() => ({ Items: [mockReport] })),
},
}));
import { mockDocumentClient, mockReport } from "../../utils/testing/setupJest";

jest.mock("../../utils/auth/authorization", () => ({
isAuthorized: jest.fn().mockReturnValue(true),
Expand All @@ -35,7 +28,14 @@ const testReadEventByState: APIGatewayProxyEvent = {
};

describe("Test fetchReport API method", () => {
test("Test Report not found Fetch", async () => {
mockDocumentClient.get.promise.mockReturnValueOnce({ Item: undefined });
const res = await fetchReport(testReadEvent, null);
expect(res.statusCode).toBe(StatusCodes.NOT_FOUND);
});

test("Test Successful Report Fetch", async () => {
mockDocumentClient.get.promise.mockReturnValueOnce({ Item: mockReport });
const res = await fetchReport(testReadEvent, null);
expect(res.statusCode).toBe(StatusCodes.SUCCESS);
const body = JSON.parse(res.body);
Expand Down Expand Up @@ -66,6 +66,9 @@ describe("Test fetchReport API method", () => {

describe("Test fetchReportsByState API method", () => {
test("Test successful call", async () => {
mockDocumentClient.query.promise.mockReturnValueOnce({
Items: [mockReport],
});
const res = await fetchReportsByState(testReadEventByState, null);
expect(res.statusCode).toBe(StatusCodes.SUCCESS);
const body = JSON.parse(res.body);
Expand Down
26 changes: 13 additions & 13 deletions services/app-api/handlers/reports/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ export const fetchReport = handler(async (event, _context) => {
if (!event?.pathParameters?.state! || !event?.pathParameters?.id!) {
throw new Error(error.NO_KEY);
}
const queryParams = {
const params = {
TableName: process.env.MCPAR_REPORT_TABLE_NAME!,
KeyConditionExpression: "#state = :state AND #id = :id",
ExpressionAttributeValues: {
":state": event.pathParameters.state,
":id": event.pathParameters.id,
},
ExpressionAttributeNames: {
"#state": "state",
"#id": "id",
Key: {
state: event.pathParameters.state,
id: event.pathParameters.id,
},
};
const reportQueryResponse = await dynamoDb.query(queryParams);
const responseBody = reportQueryResponse.Items![0] ?? {};
const response = await dynamoDb.get(params);

let status = StatusCodes.SUCCESS;
if (!response?.Item) {
status = StatusCodes.NOT_FOUND;
}
return {
status: StatusCodes.SUCCESS,
body: responseBody,
status: status,
body: response.Item,
};
});

Expand All @@ -42,6 +41,7 @@ export const fetchReportsByState = handler(async (event, _context) => {
},
};
const reportQueryResponse = await dynamoDb.query(queryParams);

return {
status: StatusCodes.SUCCESS,
body: reportQueryResponse.Items,
Expand Down
70 changes: 30 additions & 40 deletions services/app-api/handlers/reports/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import { StatusCodes } from "../../utils/types/types";
import { mockReport } from "../../utils/testing/setupJest";
import error from "../../utils/constants/constants";

jest.mock("../../utils/dynamo/dynamodb-lib", () => ({
__esModule: true,
default: {
put: jest.fn(),
},
}));

jest.mock("../../utils/auth/authorization", () => ({
isAuthorized: jest.fn().mockResolvedValue(true),
hasPermissions: jest.fn().mockReturnValueOnce(false).mockReturnValue(true),
Expand Down Expand Up @@ -60,11 +53,6 @@ const updateEventWithInvalidData: APIGatewayProxyEvent = {
body: `{"programName":{}}`,
};

const submissionEventWithInvalidData: APIGatewayProxyEvent = {
...mockProxyEvent,
body: ``,
};

describe("Test updateReport API method", () => {
test("Test unauthorized report status creation throws 403 error", async () => {
const res = await updateReport(updateEvent, null);
Expand All @@ -90,7 +78,20 @@ describe("Test updateReport API method", () => {
expect(body.fieldData.text).toContain("text-input");
});

test("Test attempted report update with invalid data fails", async () => {
test("Test report update submission succeeds", async () => {
mockedFetchReport.mockResolvedValue({
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "string",
"Access-Control-Allow-Credentials": true,
},
body: JSON.stringify(mockReport),
});
const response = await updateReport(submissionEvent, null);
expect(response.statusCode).toBe(StatusCodes.SUCCESS);
});

test("Test attempted report update with invalid data throws 400", async () => {
mockedFetchReport.mockResolvedValue({
statusCode: 200,
headers: {
Expand All @@ -100,7 +101,22 @@ describe("Test updateReport API method", () => {
body: JSON.stringify(mockReport),
});
const res = await updateReport(updateEventWithInvalidData, null);
expect(res.statusCode).toBe(StatusCodes.SERVER_ERROR);
expect(res.statusCode).toBe(StatusCodes.BAD_REQUEST);
expect(res.body).toContain(error.MISSING_DATA);
});

test("Test attempted report update with no existing record throws 404", async () => {
mockedFetchReport.mockResolvedValue({
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "string",
"Access-Control-Allow-Credentials": true,
},
body: undefined!,
});
const res = await updateReport(updateEventWithInvalidData, null);
expect(res.statusCode).toBe(StatusCodes.NOT_FOUND);
expect(res.body).toContain(error.NO_MATCHING_RECORD);
});

test("Test reportKey not provided throws 500 error", async () => {
Expand All @@ -124,30 +140,4 @@ describe("Test updateReport API method", () => {
expect(res.statusCode).toBe(500);
expect(res.body).toContain(error.NO_KEY);
});

test("Test report update submission succeeds", async () => {
mockedFetchReport.mockResolvedValue({
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "string",
"Access-Control-Allow-Credentials": true,
},
body: JSON.stringify(mockReport),
});
const response = await updateReport(submissionEvent, null);
expect(response.statusCode).toBe(StatusCodes.SUCCESS);
});

test("Report update submission fails with invalid data", async () => {
mockedFetchReport.mockResolvedValue({
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "string",
"Access-Control-Allow-Credentials": true,
},
body: JSON.stringify(mockReport),
});
const response = await updateReport(submissionEventWithInvalidData, null);
expect(response.statusCode).toBe(StatusCodes.SERVER_ERROR);
});
});
21 changes: 15 additions & 6 deletions services/app-api/handlers/reports/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const updateReport = handler(async (event, context) => {
const getCurrentReport = await fetchReport(reportEvent, context);
const { fieldData: unvalidatedFieldData } = unvalidatedPayload;

let status, body;
if (getCurrentReport?.body) {
if (unvalidatedFieldData) {
// validate report metadata
Expand Down Expand Up @@ -59,10 +60,18 @@ export const updateReport = handler(async (event, context) => {
},
};
await dynamoDb.put(reportParams);
return {
status: StatusCodes.SUCCESS,
body: { ...reportParams.Item },
};
} else throw new Error(error.MISSING_DATA);
} else throw new Error(error.NO_MATCHING_RECORD);
status = StatusCodes.SUCCESS;
body = reportParams.Item;
} else {
status = StatusCodes.BAD_REQUEST;
body = error.MISSING_DATA;
}
} else {
status = StatusCodes.NOT_FOUND;
body = error.NO_MATCHING_RECORD;
}
return {
status: status,
body: body,
};
});
Loading