Skip to content

Commit

Permalink
NOBUG: Test suites completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
marklise committed Apr 22, 2022
1 parent 02957ac commit 5c431b2
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 213 deletions.
38 changes: 14 additions & 24 deletions __tests__/global/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,30 @@
{
"pk": "park::0041",
"sk": "Maple Bay",
"activities": {
"wrapperName": "Set",
"values": [
"Boating",
"Day Use"
],
"type": "String"
},
"activities": [
"Boating",
"Day Use"
],
"parkName": "Cultus Lake Park",
"orcs": 41,
"subAreaName": "Maple Bay"
},
{
"pk": "park::0041",
"sk": "Teapot Hill",
"activities": {
"wrapperName": "Set",
"values": [
"Day Use"
],
"type": "String"
},
"activities": [
"Day Use"
],
"parkName": "Cultus Lake Park",
"orcs": 41,
"subAreaName": "Teapot Hill"
},
{
"pk": "park::6161",
"sk": "Holt Creek",
"activities": {
"wrapperName": "Set",
"values": [
"Day Use"
],
"type": "String"
},
"activities": [
"Day Use"
],
"orcs": 41,
"subAreaName": "Holt Creek"
}
Expand Down Expand Up @@ -125,7 +113,8 @@
"busModifier": 40
},
"orcs": "0041",
"subAreaName": "Maple Bay"
"subAreaName": "Maple Bay",
"activity": "Day Use"
},
{
"pk": "0041::Maple Bay::Boating",
Expand All @@ -136,7 +125,8 @@
"busModifier": 40
},
"subAreaName": "Maple Bay",
"orcs": "0041"
"orcs": "0041",
"activity": "Day Use"
}
]
}
2 changes: 1 addition & 1 deletion __tests__/global/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ module.exports = async () => {
})
.promise();
} catch (err) {
console.log(err);
console.error(err);
}
};
2 changes: 1 addition & 1 deletion __tests__/global/teardown.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ module.exports = async () => {
})
.promise();
} catch (err) {
console.log(err);
console.error(err);
}
};
52 changes: 52 additions & 0 deletions __tests__/park.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { REGION, ENDPOINT, TABLE_NAME } = require('./global/settings');
const { PARKSLIST, SUBAREAS, SUBAREA_INFORMATION } = require('./global/data.json');

const parkGET = require('../lambda/park/GET/index');
const parkPOST = require('../lambda/park/POST/index');

async function setupDb() {
new AWS.DynamoDB({
Expand Down Expand Up @@ -52,4 +53,55 @@ describe('Pass Succeeds', () => {
statusCode: 200
});
});

test('Handler - 200 Receive park specific information', async () => {
let specificSubAreas = [];
for(const area of SUBAREAS) {
if (area.pk === "park::0041") {
specificSubAreas.push(area);
}
}
const response = await parkGET.handler({
queryStringParameters: {
orcs: PARKSLIST[0].sk,
subAreaName: specificSubAreas[0].subAreaName
}
}, null);

const body = JSON.parse(response.body);

expect(body.data[0].subAreaName).toMatch(body.data[0].subAreaName);
});

test('Handler - 400 GET Bad Request', async () => {
const response = await parkGET.handler({
queryStringParameters: {
badParam: "oops"
}
}, null);

expect(response.statusCode).toBe(400);
});

test('Handler - 400 POST Bad Request', async () => {
const response = await parkPOST.handler({
body: JSON.stringify({
badParam: "{xxxxxx}"
})
}, null);

expect(response.statusCode).toBe(400);
});

test('Handler - 200 POST Park', async () => {
const response = await parkPOST.handler({
body: JSON.stringify({
orcs: '0000', // Not in the data.json set
someconfig: "test"
})
}, null);

expect(response.statusCode).toBe(200);
});

});
102 changes: 101 additions & 1 deletion __tests__/subarea.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { REGION, ENDPOINT, TABLE_NAME } = require('./global/settings');
const { PARKSLIST, SUBAREAS, CONFIG_ENTRIES, SUBAREA_ENTRIES } = require('./global/data.json');

const subareaGET = require('../lambda/subarea/GET/index');
const subareaPOST = require('../lambda/subarea/POST/index');

async function setupDb() {
new AWS.DynamoDB({
Expand Down Expand Up @@ -44,7 +45,7 @@ describe('Subarea Test', () => {
return await setupDb();
});

test('Handler - 200 Get specific activity entry', async () => {
test('Handler - 200 GET specific activity entry', async () => {
const obj = await subareaGET.handler(
{
queryStringParameters: {
Expand All @@ -56,4 +57,103 @@ describe('Subarea Test', () => {
}, null);
expect(JSON.parse(obj.body)).toMatchObject(SUBAREA_ENTRIES[0]);
});

test('Handler - 400 GET Bad Request', async () => {
const response = await subareaGET.handler({
queryStringParameters: {
badParam: "oops"
}
}, null);

expect(response.statusCode).toBe(400);
});

test('Handler - 200 POST handle Activity', async () => {
const response = await subareaPOST.handler(
{
queryStringParameters: {
type: "activity"
},
body: JSON.stringify({
orcs: SUBAREA_ENTRIES[0].orcs,
subAreaName: SUBAREA_ENTRIES[0].subAreaName,
activity: SUBAREA_ENTRIES[0].pk.split("::")[2],
date: "202201"
})
}, null);
expect(response.statusCode).toBe(200);
});

test('Handler - 200 POST handle Config', async () => {
const response = await subareaPOST.handler(
{
queryStringParameters: {
type: "config"
},
body: JSON.stringify(CONFIG_ENTRIES[0])
}, null);
expect(response.statusCode).toBe(200);
});

test('Handler - 400 POST handle Activity', async () => {
const response = await subareaPOST.handler(
{
queryStringParameters: {
type: "activity"
},
body: JSON.stringify({
orcs: SUBAREA_ENTRIES[0].orcs,
})
}, null);
expect(response.statusCode).toBe(400);
});

test('Handler - 400 POST handle Config', async () => {
const response = await subareaPOST.handler(
{
queryStringParameters: {
type: "config"
},
body: JSON.stringify({
orcs: SUBAREA_ENTRIES[0].orcs,
})
}, null);
expect(response.statusCode).toBe(400);
});

test('Handler - 400 POST handle Activity', async () => {
const response = await subareaPOST.handler(
{
queryStringParameters: {
type: "activity"
}
}, null);
expect(response.statusCode).toBe(400);
});

test('Handler - 400 POST handle Activity date', async () => {
const response = await subareaPOST.handler(
{
queryStringParameters: {
type: "activity"
},
body: JSON.stringify({
orcs: SUBAREA_ENTRIES[0].orcs,
subAreaName: SUBAREA_ENTRIES[0].subAreaName,
activity: SUBAREA_ENTRIES[0].pk.split("::")[2],
date: "2022" // Invalid
})
}, null);
expect(response.statusCode).toBe(400);
});

test('Handler - 400 POST Bad Request', async () => {
const response = await subareaPOST.handler({
body: {
badParam: "{xxxxxx}"
}
}, null);

expect(response.statusCode).toBe(400);
});
});
Loading

0 comments on commit 5c431b2

Please sign in to comment.