From 99dfd4888c47fa699e964ae7203a114d31a405b7 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Wed, 3 Jun 2020 10:15:34 +0200 Subject: [PATCH] Add test for new debug call and test helpers --- .../test/java/bubble/test/DebugCallsTest.java | 14 ++++++ .../resources/models/tests/debug_echo.json | 48 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 bubble-server/src/test/java/bubble/test/DebugCallsTest.java create mode 100644 bubble-server/src/test/resources/models/tests/debug_echo.json diff --git a/bubble-server/src/test/java/bubble/test/DebugCallsTest.java b/bubble-server/src/test/java/bubble/test/DebugCallsTest.java new file mode 100644 index 00000000..2e0cb7cc --- /dev/null +++ b/bubble-server/src/test/java/bubble/test/DebugCallsTest.java @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2020 Bubble, Inc. All rights reserved. + * For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ + */ +package bubble.test; + +import org.junit.Test; + +public class DebugCallsTest extends ActivatedBubbleModelTestBase { + + @Override protected String getManifest() { return "manifest-empty"; } + + @Test public void testEcho() throws Exception { modelTest("debug_echo"); } +} diff --git a/bubble-server/src/test/resources/models/tests/debug_echo.json b/bubble-server/src/test/resources/models/tests/debug_echo.json new file mode 100644 index 00000000..e9baf69d --- /dev/null +++ b/bubble-server/src/test/resources/models/tests/debug_echo.json @@ -0,0 +1,48 @@ +[ + { + "comment": "Simplest example of using ECHO debug call without the query param", + "request": { "uri": "debug/echo", "entity": { "anything": "something" } }, + "response": { "check": [{ "condition": "len(json) == 0" }] }, + "after": "add_to_ctx { \"added\": \"val\", \"addedInner\": { \"inner\": \"value\", \"another\": \"variable\" }, \"addedArray\": [ \"abc\", \"def\" ] }" + }, + + { + "comment": "Example of using ECHO debug call and echo_in_log after", + "request": { + "uri": "debug/echo?respondWith=inner.comment", + "entity": { + "inner": { "comment": "Fixed text comment" }, + "non-existing": "{{notexistingvar}}" + } + }, + "response": { + "raw": true, + "store": "echoedResponse", + "check": [{ "condition": "response.json == 'Fixed text comment'" }] + }, + "after": "echo_in_log Test:\n\tnon existent value: {{somethingThatDoesntExist}}\n\tjust stored response: {{echoedResponse}}" + }, + + { + "comment": "Another example of using ECHO debug call and echo_in_log after", + "before": "add_to_ctx { \"brand\": \"new\" }", + "request": { + "uri": "debug/echo?respondWith=inner", + "entity": { + "previouslyStored": "{{echoedResponse}}", + "inner": { "comment": "Another fixed text comment" } + } + }, + "response": { + "store": "echoedJson", + "check": [ + { "condition": "json.get('comment') == 'Another fixed text comment'" }, + { "condition": "'{{brand}}' == 'new'" }, + { "condition": "'{{addedInner.another}}' == 'variable'" }, + { "condition": "'{{added}}' == 'val'" } + ] + }, + "after": "echo_in_log \"And now the stored value is: {{echoedJson.comment}}\"" + // echo_in_log is, of course, available within `before` also + } +]