Skip to content
Snippets Groups Projects
Commit 33cdfb42 authored by Edouard DE BRYE's avatar Edouard DE BRYE
Browse files

added integration test + modified lambdas to log errors

parent 3b9c7e35
No related branches found
No related tags found
No related merge requests found
......@@ -81,6 +81,243 @@
},
"response": []
},
{
"name": "CREATE no body",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 400\", function () {",
" pm.response.to.have.status(400);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PUT",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "SignedHeaders",
"disabled": true
},
{
"key": "Date",
"type": "text",
"value": "{{$timestamp}}",
"disabled": true
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{endpoint}}/crud",
"host": [
"{{endpoint}}"
],
"path": [
"crud"
]
}
},
"response": []
},
{
"name": "UPDATE no body",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 400\", function () {",
" pm.response.to.have.status(400);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PATCH",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{endpoint}}/crud?id={{id}}",
"host": [
"{{endpoint}}"
],
"path": [
"crud"
],
"query": [
{
"key": "id",
"value": "{{id}}"
}
]
}
},
"response": []
},
{
"name": "UPDATE empty body",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 400\", function () {",
" pm.response.to.have.status(400);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PATCH",
"header": [],
"body": {
"mode": "raw",
"raw": "{}"
},
"url": {
"raw": "{{endpoint}}/crud?id={{id}}",
"host": [
"{{endpoint}}"
],
"path": [
"crud"
],
"query": [
{
"key": "id",
"value": "{{id}}"
}
]
}
},
"response": []
},
{
"name": "UPDATE no id",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 400\", function () {",
" pm.response.to.have.status(400);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PATCH",
"header": [],
"body": {
"mode": "raw",
"raw": "{\"hello\":\"bonjour\"}"
},
"url": {
"raw": "{{endpoint}}/crud",
"host": [
"{{endpoint}}"
],
"path": [
"crud"
]
}
},
"response": []
},
{
"name": "UPDATE inexistant id",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 204\", function () {",
" pm.response.to.have.status(204);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PATCH",
"header": [],
"body": {
"mode": "raw",
"raw": "{\"hello\":\"bonjour\"}"
},
"url": {
"raw": "{{endpoint}}/crud?id=noid",
"host": [
"{{endpoint}}"
],
"path": [
"crud"
],
"query": [
{
"key": "id",
"value": "noid"
}
]
}
},
"response": []
},
{
"name": "UPDATE",
"event": [
......@@ -171,6 +408,179 @@
},
"response": []
},
{
"name": "GET no id",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 400\", function () {",
" pm.response.to.have.status(400);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{endpoint}}/crud",
"host": [
"{{endpoint}}"
],
"path": [
"crud"
]
}
},
"response": []
},
{
"name": "GET item created after update",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"pm.test(\"response have correct payload\", function () {",
" var jsonData = pm.response.json();",
" pm.expect(jsonData.hello).to.eql(\"bonjour\");",
" pm.expect(jsonData.ID).to.eql(\"noid\");",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{endpoint}}/crud?id=noid",
"host": [
"{{endpoint}}"
],
"path": [
"crud"
],
"query": [
{
"key": "id",
"value": "noid"
}
]
}
},
"response": []
},
{
"name": "DELETE no id",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 400\", function () {",
" pm.response.to.have.status(400);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "DELETE",
"header": [],
"url": {
"raw": "{{endpoint}}/crud",
"host": [
"{{endpoint}}"
],
"path": [
"crud"
]
}
},
"response": []
},
{
"name": "DELETE inexistant id",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "DELETE",
"header": [],
"url": {
"raw": "{{endpoint}}/crud?id=noid",
"host": [
"{{endpoint}}"
],
"path": [
"crud"
],
"query": [
{
"key": "id",
"value": "noid"
}
]
}
},
"response": []
},
{
"name": "DELETE item created after update",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "DELETE",
"header": [],
"url": {
"raw": "{{endpoint}}/crud?id=noid",
"host": [
"{{endpoint}}"
],
"path": [
"crud"
],
"query": [
{
"key": "id",
"value": "noid"
}
]
}
},
"response": []
},
{
"name": "DELETE",
"event": [
......@@ -207,6 +617,46 @@
}
},
"response": []
},
{
"name": "GET inexistant id",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"response don't have payload\", function () {",
" pm.response.to.not.have.body",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{endpoint}}/crud?id=noid",
"host": [
"{{endpoint}}"
],
"path": [
"crud"
],
"query": [
{
"key": "id",
"value": "noid"
}
]
}
},
"response": []
}
]
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ const RESERVED_RESPONSE = `Error: You're using AWS reserved keywords as attribut
exports.handler = async (event = {}) => {
console.log(event)
if (!event.body) {
console.error("400 invalid request, you are missing the parameter body")
return { statusCode: 400, body: 'invalid request, you are missing the parameter body' };
}
const item = typeof event.body == 'object' ? event.body : JSON.parse(event.body);
......@@ -22,6 +23,7 @@ exports.handler = async (event = {}) => {
catch (dbError) {
const errorResponse = dbError.code === 'ValidationException' && dbError.message.includes('reserved keyword') ?
DYNAMODB_EXECUTION_ERROR : RESERVED_RESPONSE;
console.error("500 " + errorResponse)
return { statusCode: 500, body: errorResponse };
}
return { statusCode: 201, body: JSON.stringify({ id: item[PRIMARY_KEY] }) };
......
......@@ -3,8 +3,13 @@ const db = new AWS.DynamoDB.DocumentClient();
const TABLE_NAME = process.env.TABLE_NAME || '';
const PRIMARY_KEY = process.env.TABLE_KEY || '';
exports.handler = async (event = {}) => {
if (!event.queryStringParameters) {
console.error("400 invalid request, you are missing the path parameter id")
return { statusCode: 400, body: `Error: You are missing the path parameter id` };
}
const requestedItemId = event.queryStringParameters.id;
if (!requestedItemId) {
console.error("400 invalid request, you are missing the path parameter id")
return { statusCode: 400, body: `Error: You are missing the path parameter id` };
}
const params = {
......@@ -22,6 +27,7 @@ exports.handler = async (event = {}) => {
return { statusCode: 200, body: '' };
}
catch (dbError) {
console.error("500 "+JSON.stringify(dbError))
return { statusCode: 500, body: JSON.stringify(dbError) };
}
};
\ No newline at end of file
......@@ -3,8 +3,13 @@ const db = new AWS.DynamoDB.DocumentClient();
const TABLE_NAME = process.env.TABLE_NAME || '';
const PRIMARY_KEY = process.env.TABLE_KEY || '';
exports.handler = async (event = {}) => {
if (!event.queryStringParameters) {
console.error("400 invalid request, you are missing the path parameter id")
return { statusCode: 400, body: `Error: You are missing the path parameter id` };
}
const requestedItemId = event.queryStringParameters.id;
if (!requestedItemId) {
console.error("400 invalid request, you are missing the path parameter id")
return { statusCode: 400, body: `Error: You are missing the path parameter id` };
}
const params = {
......@@ -19,9 +24,12 @@ exports.handler = async (event = {}) => {
})
try {
const response = await db.get(params).promise();
console.log({response:{ statusCode: 200, body: JSON.stringify(response.Item) }
})
return { statusCode: 200, body: JSON.stringify(response.Item) };
}
catch (dbError) {
console.error("500 "+JSON.stringify(dbError))
return { statusCode: 500, body: JSON.stringify(dbError) };
}
};
\ No newline at end of file
......@@ -5,15 +5,22 @@ const PRIMARY_KEY = process.env.TABLE_KEY || '';
const RESERVED_RESPONSE = `Error: You're using AWS reserved keywords as attributes`, DYNAMODB_EXECUTION_ERROR = `Error: Execution update, caused a Dynamodb error, please take a look at your CloudWatch Logs.`;
exports.handler = async (event = {}) => {
if (!event.body) {
console.error("400 invalid request, you are missing the parameter body")
return { statusCode: 400, body: 'invalid request, you are missing the parameter body' };
}
if (!event.queryStringParameters) {
console.error("400 invalid request, you are missing the path parameter id")
return { statusCode: 400, body: `Error: You are missing the path parameter id` };
}
const editedItemId = event.queryStringParameters.id;
if (!editedItemId) {
console.error("400 invalid request, you are missing the path parameter id")
return { statusCode: 400, body: 'invalid request, you are missing the path parameter id' };
}
const editedItem = typeof event.body == 'object' ? event.body : JSON.parse(event.body);
const editedItemProperties = Object.keys(editedItem);
if (!editedItem || editedItemProperties.length < 1) {
console.error("400 invalid request, you are missing the parameter body")
return { statusCode: 400, body: 'invalid request, no arguments provided' };
}
const firstProperty = editedItemProperties.splice(0, 1);
......@@ -42,6 +49,7 @@ exports.handler = async (event = {}) => {
catch (dbError) {
const errorResponse = dbError.code === 'ValidationException' && dbError.message.includes('reserved keyword') ?
DYNAMODB_EXECUTION_ERROR : RESERVED_RESPONSE;
console.error("500 "+errorResponse)
return { statusCode: 500, body: errorResponse };
}
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment