From 6d9ec6c0245d3660af8d7fdf80deff4ce7e40407 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 | 4 ++-- 2 files changed, 8 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..5c449742 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?