diff --git a/__tests__/export-variance.test.js b/__tests__/export-variance.test.js index 910baaa..b769e28 100644 --- a/__tests__/export-variance.test.js +++ b/__tests__/export-variance.test.js @@ -103,7 +103,7 @@ describe("Export Variance Report", () => { expect(response.statusCode).toBe(403); }); - test("Handler - 200 GET, with no jobs", async () => { + test("Handler - 400 no fiscal year provided", async () => { const dateField = "dateGenerated" const event = { headers: { @@ -126,6 +126,45 @@ describe("Export Variance Report", () => { } catch (e) { body = 'fail' } + expect(result).toEqual( + expect.objectContaining({ + headers: { + "Access-Control-Allow-Headers": + "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token", + "Access-Control-Allow-Methods": "OPTIONS,GET,POST", + "Access-Control-Allow-Origin": "*", + "Content-Type": "application/json", + }, + statusCode: 400, + }), + ); + }) + + test("Handler - 200 GET, with no jobs", async () => { + const dateField = "dateGenerated" + const event = { + headers: { + Authorization: "Bearer " + token, + }, + httpMethod: "GET", + queryStringParameters: { + getJob: "true", + fiscalYearEnd: 2023 + }, + }; + + jest.mock('../lambda/permissionUtil', () => { + return mockedSysadmin; + }); + const varianceExportGET = require("../lambda/export-variance/GET/index"); + const result = await varianceExportGET.handler(event, null); + let body; + try { + body = JSON.parse(result.body) + console.log('body:', body); + } catch (e) { + body = 'fail' + } expect(result).toEqual( expect.objectContaining({ headers: { @@ -147,6 +186,9 @@ describe("Export Variance Report", () => { Authorization: "Bearer " + token, }, httpMethod: "GET", + queryStringParameters: { + fiscalYearEnd: 2023 + }, }; jest.mock('../lambda/permissionUtil', () => { return mockedSysadmin; diff --git a/__tests__/global/data.json b/__tests__/global/data.json index 914ee9c..de4871a 100644 --- a/__tests__/global/data.json +++ b/__tests__/global/data.json @@ -240,11 +240,11 @@ "dateGenerated": "2023-01-05T22:12:49.314Z", "lastSuccessfulJob": { "dateGenerated": "2023-01-05T22:12:49.314Z", - "key": "dad2b66eca14331cb6186d181c51d08a/A&R_Variance_Report.csv" + "key": "f36c75c5d08d41effd2ccc8fd077c6ab/A&R_Variance_Report.csv" }, "progressDescription": "Job Complete.", "progressState": "complete", - "sk": "dad2b66eca14331cb6186d181c51d08a", + "sk": "f36c75c5d08d41effd2ccc8fd077c6ab", "pk": "variance-exp-job", "progressPercentage": 100 } diff --git a/lambda/export-variance/GET/index.js b/lambda/export-variance/GET/index.js index fea6aad..3c0d1d2 100644 --- a/lambda/export-variance/GET/index.js +++ b/lambda/export-variance/GET/index.js @@ -40,6 +40,11 @@ exports.handler = async (event, context) => { let params = event?.queryStringParameters || {}; params['roles'] = permissionObject.roles; + // Must provide fiscal year end + if (!params?.fiscalYearEnd) { + return sendResponse(400, { msg: "No fiscal year end provided." }, context); + } + // generate a job id from params+role let hashParams = {...params}; delete hashParams.getJob;