From ae43be101dd23ddd2588d152545cf01a6b12e9b0 Mon Sep 17 00:00:00 2001 From: Mitch MacKenzie Date: Thu, 15 Feb 2024 23:04:08 -0400 Subject: [PATCH] Get e2e passing --- .github/workflows/e2e.yml | 2 +- src/index.js | 2 +- tests/e2e/local.sh | 8 ++++---- tests/e2e/test.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index f3a1d30..8fb7b58 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -16,7 +16,7 @@ jobs: working-directory: ./tests/e2e - run: > - curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"path":"/index.php"}' + curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"path":"/index.php"}' | grep -q '{"statusCode":200,"headers"' - run: > curl -s -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"path":"/index.php", "postRequestPlugin": "1"}' | grep -q '{"statusCode":201,"body":"Foo"}' diff --git a/src/index.js b/src/index.js index cbacbbc..b939e2a 100644 --- a/src/index.js +++ b/src/index.js @@ -23,7 +23,7 @@ async function handler(data) { const { event, docRoot } = data; const preRequestResponse = await plugins.executePreRequest(event); - if (preRequestResponse !== null) { + if (preRequestResponse != null) { return preRequestResponse; } diff --git a/tests/e2e/local.sh b/tests/e2e/local.sh index d9b4122..7619d77 100755 --- a/tests/e2e/local.sh +++ b/tests/e2e/local.sh @@ -4,13 +4,13 @@ docker run -p 9000:8080 -d --name serverlesswp-local docker-lambda-serverlesswp -curl -s -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"path":"/index.php"}' | grep -q '{"statusCode":200,"headers"' +curl -s -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"path":"/index.php"}' | grep -q '{"statusCode":200,"headers"' || echo 'fail 1' -curl -s -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"path":"/index.php", "postRequestPlugin": "1"}' | grep -q '{"statusCode":201,"body":"Foo"}' +curl -s -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"path":"/index.php", "postRequestPlugin": "1"}' | grep -q '{"statusCode":201,"body":"Foo"}' || echo 'fail 2' -curl -s -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"path":"/index.php", "preRequestPlugin": "1"}' | grep -q '{"statusCode":200,"body":"Foo"}' +curl -s -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"path":"/index.php", "preRequestPlugin": "1"}' | grep -q '{"statusCode":200,"body":"Foo"}' || echo 'fail 3' -curl -s -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"path":"/static.css"}' | grep -q 'background-color: blue' +curl -s -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"path":"/static.css"}' | grep -q 'background-color: blue' || echo 'fail 4' docker stop serverlesswp-local docker rm serverlesswp-local \ No newline at end of file diff --git a/tests/e2e/test.js b/tests/e2e/test.js index b4946cb..5e7b5f5 100644 --- a/tests/e2e/test.js +++ b/tests/e2e/test.js @@ -5,7 +5,7 @@ serverlesswp.registerPlugin({ name: 'postRequest', postRequest: async function(event, pluginResponse) { // Bypass this plugin conditionally - if (event.postRequestPlugin) { + if (event.hasOwnProperty("postRequestPlugin")) { return { statusCode: pluginResponse.statusCode + 1, body: 'Foo' @@ -18,7 +18,7 @@ serverlesswp.registerPlugin({ name: 'preRequest', preRequest: async function(event) { // Bypass this plugin conditionally - if (event.preRequestPlugin) { + if (event.hasOwnProperty("preRequestPlugin")) { return { statusCode: 200, body: 'Foo'