-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* BRS-950: Updated unit tests * BRS-950: added back removed park tests, added IS_TEST flag and updated permissionUtils, updated some tests. * BRS-950: Update dynamoUtil test, update export test * BRS-950: Fixing last tests
- Loading branch information
Showing
8 changed files
with
538 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
const AWS = require("aws-sdk"); | ||
const { DocumentClient } = require("aws-sdk/clients/dynamodb"); | ||
const { REGION, ENDPOINT, TABLE_NAME } = require("./global/settings"); | ||
const { PARKSLIST, SUBAREAS, SUBAREA_ENTRIES} = require("./global/data.json"); | ||
|
||
const utils = require("../lambda/dynamoUtil"); | ||
|
||
async function setupDb() { | ||
new AWS.DynamoDB({ | ||
region: REGION, | ||
endpoint: ENDPOINT, | ||
}); | ||
docClient = new DocumentClient({ | ||
region: REGION, | ||
endpoint: ENDPOINT, | ||
convertEmptyValues: true, | ||
}); | ||
|
||
for (const park of PARKSLIST) { | ||
await docClient | ||
.put({ | ||
TableName: TABLE_NAME, | ||
Item: park, | ||
}) | ||
.promise(); | ||
} | ||
|
||
for (const subarea of SUBAREAS) { | ||
await docClient | ||
.put({ | ||
TableName: TABLE_NAME, | ||
Item: subarea, | ||
}) | ||
.promise(); | ||
} | ||
|
||
for (const subEntry of SUBAREA_ENTRIES) { | ||
await docClient | ||
.put({ | ||
TableName: TABLE_NAME, | ||
Item: subEntry, | ||
}) | ||
.promise(); | ||
} | ||
} | ||
|
||
describe("Pass Succeeds", () => { | ||
beforeAll(async () => { | ||
return await setupDb(); | ||
}); | ||
|
||
test("dynamoUtil - runScan", async () => { | ||
let queryObj = { | ||
TableName: TABLE_NAME | ||
}; | ||
queryObj.FilterExpression = "pk = :pk"; | ||
queryObj.ExpressionAttributeValues = {}; | ||
queryObj.ExpressionAttributeValues[':pk'] = { S: `park` }; | ||
|
||
const result = await utils.runScan(queryObj, null) | ||
|
||
expect(result).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
parkName: PARKSLIST[0].parkName | ||
}), | ||
expect.objectContaining({ | ||
parkName: PARKSLIST[1].parkName | ||
}), | ||
]) | ||
); | ||
}); | ||
|
||
test("dynamoUtil - getParks", async () => { | ||
const result = await utils.getParks() | ||
|
||
expect(result).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
parkName: PARKSLIST[0].parkName | ||
}), | ||
expect.objectContaining({ | ||
parkName: PARKSLIST[1].parkName | ||
}), | ||
]) | ||
); | ||
}); | ||
|
||
test("dynamoUtil - getSubAreas", async () => { | ||
let orc = '0041' | ||
let specificSubAreas = []; | ||
for (const area of SUBAREAS) { | ||
if (area.pk === `park::${orc}`) { | ||
specificSubAreas.push(area); | ||
} | ||
} | ||
const result = await utils.getSubAreas(orc) | ||
|
||
expect(result).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
subAreaName: specificSubAreas[0].subAreaName | ||
}), | ||
expect.objectContaining({ | ||
subAreaName: specificSubAreas[1].subAreaName | ||
}), | ||
]) | ||
); | ||
}); | ||
|
||
test("dynamoUtil - getRecords", async () => { | ||
const result = await utils.getRecords(SUBAREAS[0]) | ||
|
||
expect(result).toEqual( | ||
expect.not.arrayContaining([ | ||
expect.not.objectContaining({ | ||
orcs: SUBAREAS[0].pk.split("::")[1] | ||
}) | ||
]) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
const AWS = require("aws-sdk"); | ||
const { DocumentClient } = require("aws-sdk/clients/dynamodb"); | ||
const { REGION, ENDPOINT, TABLE_NAME } = require("./global/settings"); | ||
const { PARKSLIST, SUBAREAS, JOBSLIST, MOCKJOB } = require("./global/data.json"); | ||
|
||
const exportGET = require("../lambda/export/GET/index"); | ||
const exportFUNCTIONS = require("../lambda/export/functions"); | ||
const utils = require("../lambda/dynamoUtil"); | ||
|
||
|
||
const jwt = require("jsonwebtoken"); | ||
const tokenContent = { | ||
resource_access: { "attendance-and-revenue": { roles: ["sysadmin"] } }, | ||
}; | ||
const token = jwt.sign(tokenContent, "defaultSecret"); | ||
|
||
|
||
async function setupDb() { | ||
new AWS.DynamoDB({ | ||
region: REGION, | ||
endpoint: ENDPOINT, | ||
}); | ||
docClient = new DocumentClient({ | ||
region: REGION, | ||
endpoint: ENDPOINT, | ||
convertEmptyValues: true, | ||
}); | ||
|
||
for (const park of PARKSLIST) { | ||
await docClient | ||
.put({ | ||
TableName: TABLE_NAME, | ||
Item: park, | ||
}) | ||
.promise(); | ||
} | ||
|
||
for (const subarea of SUBAREAS) { | ||
await docClient | ||
.put({ | ||
TableName: TABLE_NAME, | ||
Item: subarea, | ||
}) | ||
.promise(); | ||
} | ||
|
||
for (const job of JOBSLIST) { | ||
await docClient | ||
.put({ | ||
TableName: TABLE_NAME, | ||
Item: job, | ||
}) | ||
.promise(); | ||
} | ||
} | ||
|
||
describe("Export Report", () => { | ||
beforeAll(async () => { | ||
return await setupDb(); | ||
}); | ||
|
||
test("Handler - 403 GET Invalid Auth", async () => { | ||
const response = await exportGET.handler( | ||
{ | ||
headers: { | ||
Authorization: "Bearer " + token + "invalid", | ||
PsuedoToken: "error", | ||
}, | ||
}, | ||
null | ||
); | ||
|
||
expect(response.statusCode).toBe(403); | ||
}); | ||
|
||
test("Handler - 200 GET, with no jobs", async () => { | ||
const dateField = "dateGenerated" | ||
const event = { | ||
headers: { | ||
Authorization: "Bearer " + token, | ||
}, | ||
httpMethod: "GET", | ||
queryStringParameters: { | ||
getJob: "true" | ||
}, | ||
}; | ||
|
||
const result = await exportGET.handler(event, null) | ||
let body; | ||
try { | ||
body = JSON.parse(result.body) | ||
} 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: 200, | ||
}), | ||
); | ||
expect(body.jobObj[dateField]).toMatch(JOBSLIST[0][dateField]) | ||
}) | ||
|
||
test("Handler - 200 GET, generate report", async () => { | ||
const event = { | ||
headers: { | ||
Authorization: "Bearer " + token, | ||
}, | ||
httpMethod: "GET", | ||
}; | ||
|
||
const result = await exportGET.handler(event, null) | ||
|
||
// Returns value below even with no job | ||
// Update when invokable can be called | ||
expect(result.body).toBe("{\"status\":\"Job is already running\"}") | ||
}); | ||
|
||
test("Functions - updateJobEntry", async () => { | ||
const query = { | ||
TableName: TABLE_NAME, | ||
KeyConditionExpression: "pk = :pk AND sk = :sk", | ||
ExpressionAttributeValues: { | ||
":pk": { S: "job" }, | ||
":sk": {S: "MOCK_JOB_ID"} | ||
} | ||
}; | ||
|
||
await exportFUNCTIONS.updateJobEntry(MOCKJOB, TABLE_NAME) | ||
const result = await utils.runQuery(query) | ||
|
||
expect(result).toMatchObject([MOCKJOB]) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.