chore: adds some tests #13
Merged
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 introduces several updates to the
FormbricksSDK
codebase, focusing on improving test coverage, enhancing the flexibility of theAPIClient
, and refining the SonarQube configuration. The most notable changes include making theURLSession
injectable for testing, adding comprehensive unit tests forAPIClient
and other components, and updating SonarQube exclusions.Enhancements to
APIClient
:URLSession
injectable by adding asession
parameter to theAPIClient
initializer, defaulting to.shared
. This change improves testability by allowing the use of mock sessions during testing. (Sources/FormbricksSDK/Networking/Base/APIClient.swift
, Sources/FormbricksSDK/Networking/Base/APIClient.swiftL5-R11)Expanded Test Coverage:
APIClientTests
test suite with multiple test cases for various scenarios, including successful responses, API errors, invalid URLs, decoding errors, and network errors. AMockURLSession
was introduced to simulate network requests. (Tests/FormbricksSDKTests/Networking/APIClientTests.swift
, Tests/FormbricksSDKTests/Networking/APIClientTests.swiftR1-R383)GetEnvironmentRequest
andPostUserRequest
, to validate their initialization and properties. (Tests/FormbricksSDKTests/Networking/ClientAPIEndpointsTests.swift
, Tests/FormbricksSDKTests/Networking/ClientAPIEndpointsTests.swiftR1-R18)UpdateQueueTests
to verify the behavior of theUpdateQueue
class, including debouncing, attribute updates, and state resets, using aMockUserManager
for assertions. (Tests/FormbricksSDKTests/Networking/UpdateQueueTests.swift
, Tests/FormbricksSDKTests/Networking/UpdateQueueTests.swiftR1-R136)SonarQube Configuration:
sonar.coverage.exclusions
to exclude additional files (HTTPStatusCode.swift
andEncodableRequest.swift
) from coverage analysis, ensuring a more focused code quality assessment. (sonar-project.properties
, sonar-project.propertiesL18-R18)