diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index c9f08d60..b46fce50 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -28,7 +28,7 @@ jobs: -scheme 'FormbricksSDK' \ -sdk iphonesimulator \ -config Debug \ - -destination 'platform=iOS Simulator,name=iPhone SE (3rd generation),OS=18.2' \ + -destination 'platform=iOS Simulator,name=iPhone SE (3rd generation),OS=18.4' \ -derivedDataPath build \ -enableCodeCoverage YES @@ -39,7 +39,7 @@ jobs: # Run SonarCloud scan, pointing at the Cobertura report - name: SonarCloud Scan - uses: SonarSource/sonarqube-scan-action@v5.2.0 + uses: SonarSource/sonarqube-scan-action@fd88b7d7ccbaefd23d8f36f73b59db7a3d246602 # v6.0.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/Sources/FormbricksSDK/Manager/SurveyManager.swift b/Sources/FormbricksSDK/Manager/SurveyManager.swift index 21e0bf34..468b3148 100644 --- a/Sources/FormbricksSDK/Manager/SurveyManager.swift +++ b/Sources/FormbricksSDK/Manager/SurveyManager.swift @@ -1,5 +1,9 @@ import SwiftUI +public extension Notification.Name { + static let environmentRefreshed = Notification.Name("Formbricks.environmentRefreshed") +} + /// The SurveyManager is responsible for managing the surveys that are displayed to the user. /// Filtering surveys based on the user's segments, responses, and displays. final class SurveyManager { @@ -127,11 +131,13 @@ extension SurveyManager { self?.environmentResponse = response self?.startRefreshTimer(expiresAt: response.data.expiresAt) self?.filterSurveys() + NotificationCenter.default.post(name: .environmentRefreshed, object: self) case .failure: self?.hasApiError = true let error = FormbricksSDKError(type: .unableToRefreshEnvironment) Formbricks.logger?.error(error.message) self?.startErrorTimer() + NotificationCenter.default.post(name: .environmentRefreshed, object: self) } } } diff --git a/Tests/FormbricksSDKTests/FormbricksSDKTests.swift b/Tests/FormbricksSDKTests/FormbricksSDKTests.swift index f0a8b4d7..2cc803ac 100644 --- a/Tests/FormbricksSDKTests/FormbricksSDKTests.swift +++ b/Tests/FormbricksSDKTests/FormbricksSDKTests.swift @@ -221,13 +221,10 @@ final class FormbricksSDKTests: XCTestCase { UserDefaults.standard.set(Data([0x00, 0x01]), forKey: "environmentResponseObjectKey") XCTAssertNil(manager.environmentResponse) - // Timer-based refresh (use more generous timeouts) + // Timer-based refresh: wait deterministically for the environment refresh notification + let notificationExpectation = expectation(forNotification: .environmentRefreshed, object: manager, handler: nil) manager.refreshEnvironmentAfter(timeout: 0.1) - let expectation = XCTestExpectation(description: "Timer fired") - DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { - expectation.fulfill() - } - wait(for: [expectation], timeout: 1.0) + wait(for: [notificationExpectation], timeout: 2.0) // getLanguageCode coverage let survey = Survey(