From 65649cd53fe00eddf2297959061c98917346d835 Mon Sep 17 00:00:00 2001 From: Nicky Bondarenko Date: Wed, 7 Feb 2024 15:56:59 +0100 Subject: [PATCH] fix: change STALE reason in case of context change --- .../ConfidenceProvider/ConfidenceFeatureProvider.swift | 8 ++++++-- .../ConfidenceFeatureProviderTest.swift | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift b/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift index be8016e2..c47dc44f 100644 --- a/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift +++ b/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift @@ -251,8 +251,12 @@ public class ConfidenceFeatureProvider: FeatureProvider { ) return evaluationResult } catch ConfidenceError.cachedValueExpired { - return ProviderEvaluation(value: defaultValue, variant: nil, reason: Reason.stale.rawValue) - } catch { + return ProviderEvaluation(value: defaultValue, + variant: nil, + reason: Reason.error.rawValue, + errorCode: ErrorCode.providerNotReady + )} + catch { throw error } } diff --git a/Tests/ConfidenceProviderTests/ConfidenceFeatureProviderTest.swift b/Tests/ConfidenceProviderTests/ConfidenceFeatureProviderTest.swift index e0fa5bee..e42d45c0 100644 --- a/Tests/ConfidenceProviderTests/ConfidenceFeatureProviderTest.swift +++ b/Tests/ConfidenceProviderTests/ConfidenceFeatureProviderTest.swift @@ -347,10 +347,10 @@ class ConfidenceFeatureProviderTest: XCTestCase { context: MutableContext(targetingKey: "user1")) XCTAssertEqual(evaluation.value, 0) - XCTAssertNil(evaluation.errorCode) XCTAssertNil(evaluation.errorMessage) XCTAssertNil(evaluation.variant) - XCTAssertEqual(evaluation.reason, Reason.stale.rawValue) + XCTAssertEqual(evaluation.errorCode, ErrorCode.providerNotReady) + XCTAssertEqual(evaluation.reason, Reason.error.rawValue) XCTAssertEqual(MockedConfidenceClientURLProtocol.resolveStats, 1) // TODO: Check this - how do we check for something not called? @@ -719,6 +719,7 @@ class ConfidenceFeatureProviderTest: XCTestCase { defaultValue: 0, context: MutableContext(targetingKey: "user1")) + XCTAssertNil(evaluation.errorCode) XCTAssertEqual(evaluation.variant, "control") XCTAssertEqual(evaluation.reason, Reason.staticReason.rawValue) XCTAssertEqual(evaluation.value, 4)