From 4948d8231e8ab1d334c239a127c8b73292210174 Mon Sep 17 00:00:00 2001 From: arifBurakDemiray Date: Wed, 27 Sep 2023 16:19:27 +0300 Subject: [PATCH] feat: construct feedback url test --- .../java/internal/ModuleFeedbackTests.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleFeedbackTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleFeedbackTests.java index 20612078d..1762e5300 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleFeedbackTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleFeedbackTests.java @@ -15,9 +15,13 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import static org.mockito.Mockito.mock; + @RunWith(JUnit4.class) public class ModuleFeedbackTests { + Log L = mock(Log.class); + @After public void stop() { Countly.stop(true); @@ -229,6 +233,60 @@ public void getAvailableFeedbackWidgets_null() { }); } + /** + * Construct feedback widget url successfully + * "constructFeedbackWidgetUrl" function should return widget url + * returned url should be same as expected url + */ + @Test + public void constructFeedbackWidgetUrl() { + Config config = TestUtils.getBaseConfig(); + config.enableFeatures(Config.Feature.Feedback).setEventQueueSizeToSend(4); + init(config); + + InternalConfig internalConfig = SDKCore.instance.config; + + CountlyFeedbackWidget widgetInfo = createFeedbackWidget(FeedbackWidgetType.nps, "nps1", "npsID1", new String[] {}); + + StringBuilder widgetListUrl = new StringBuilder(); + widgetListUrl.append(internalConfig.getServerURL()); + widgetListUrl.append("/feedback/"); + widgetListUrl.append(widgetInfo.type.name()); + widgetListUrl.append("?widget_id="); + widgetListUrl.append(Utils.urlencode(widgetInfo.widgetId, L)); + widgetListUrl.append("&device_id="); + widgetListUrl.append(Utils.urlencode(internalConfig.getDeviceId().id, L)); + widgetListUrl.append("&app_key="); + widgetListUrl.append(Utils.urlencode(internalConfig.getServerAppKey(), L)); + widgetListUrl.append("&sdk_version="); + widgetListUrl.append(internalConfig.getSdkVersion()); + widgetListUrl.append("&sdk_name="); + widgetListUrl.append(internalConfig.getSdkName()); + widgetListUrl.append("&platform=desktop"); + + Countly.instance().feedback().constructFeedbackWidgetUrl(widgetInfo, (response, error) -> { + Assert.assertNull(error); + Assert.assertEquals(widgetListUrl.toString(), response); + }); + } + + /** + * Construct feedback widget url with null widget info + * "constructFeedbackWidgetUrl" function should not return widget url and return error message + * url should be null and error message should same as expected + */ + @Test + public void constructFeedbackWidgetUrl_nullWidgetInfo() { + Config config = TestUtils.getBaseConfig(); + config.enableFeatures(Config.Feature.Feedback).setEventQueueSizeToSend(4); + init(config); + + Countly.instance().feedback().constructFeedbackWidgetUrl(null, (response, error) -> { + Assert.assertNull(response); + Assert.assertEquals("[ModuleFeedback] constructFeedbackWidgetUrlInternal, Can't continue operation with null widget", error); + }); + } + private void validateRequiredParams(Map params) { int hour = Integer.parseInt(params.get("hour")); int dow = Integer.parseInt(params.get("dow"));