chore: add tests for new code in formbricks environment #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request refactors the
FormbricksEnvironment
to improve robustness by replacing fatal errors with optional returns, updates theFormbricksViewModel
to integrate these changes, and adds comprehensive unit tests for the new behavior. The most important changes are detailed below.Refactoring
FormbricksEnvironment
baseApiUrl
to returnnil
instead of crashing whenappUrl
is missing, improving error handling. (Sources/FormbricksSDK/Helpers/FormbricksEnvironment.swift
, Sources/FormbricksSDK/Helpers/FormbricksEnvironment.swiftL5-L19)surveyScriptUrlString
to returnnil
for invalid or missingappUrl
and added validation for HTTPS/HTTP schemes. (Sources/FormbricksSDK/Helpers/FormbricksEnvironment.swift
, Sources/FormbricksSDK/Helpers/FormbricksEnvironment.swiftL5-L19)Updates to
FormbricksViewModel
htmlString
generation to replace a new placeholder,{{SURVEY_SCRIPT_URL}}
, with the value ofsurveyScriptUrlString
. (Sources/FormbricksSDK/WebView/FormbricksViewModel.swift
, Sources/FormbricksSDK/WebView/FormbricksViewModel.swiftL11-R14)surveyScriptUrlString
in the JavaScript template with the{{SURVEY_SCRIPT_URL}}
placeholder for consistency. (Sources/FormbricksSDK/WebView/FormbricksViewModel.swift
, Sources/FormbricksSDK/WebView/FormbricksViewModel.swiftL67-R69)Unit Tests
FormbricksEnvironmentTests
to test the behavior ofbaseApiUrl
andsurveyScriptUrlString
, ensuring they return the correct values ornil
for invalid inputs. (Tests/FormbricksSDKTests/FormbricksEnvironmentTests.swift
, Tests/FormbricksSDKTests/FormbricksEnvironmentTests.swiftR1-R51)