Skip to content

Commit

Permalink
Merge pull request #55 from mgratzer/fix-encrypted-features-decoding
Browse files Browse the repository at this point in the history
Enable path to decode encrypted features
  • Loading branch information
vazarkevych authored Apr 18, 2024
2 parents 5cb9410 + 14f81c1 commit 0ec3552
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions GrowthBookTests/FeaturesViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import XCTest
class FeaturesViewModelTests: XCTestCase, FeaturesFlowDelegate {
var isSuccess: Bool = false
var isError: Bool = false
var hasFeatures: Bool = false

override func setUp() {
super.setUp()

isSuccess = false
isError = true
hasFeatures = false
}

func testSuccess() throws {
isSuccess = false
Expand All @@ -16,6 +25,7 @@ class FeaturesViewModelTests: XCTestCase, FeaturesFlowDelegate {

XCTAssertTrue(isSuccess)
XCTAssertFalse(isError)
XCTAssertTrue(hasFeatures)
}

func testSuccessForEncryptedFeatures() throws {
Expand All @@ -29,6 +39,7 @@ class FeaturesViewModelTests: XCTestCase, FeaturesFlowDelegate {

XCTAssertTrue(isSuccess)
XCTAssertFalse(isError)
XCTAssertTrue(hasFeatures)
}

func testGetDataFromCache() throws {
Expand All @@ -54,6 +65,7 @@ class FeaturesViewModelTests: XCTestCase, FeaturesFlowDelegate {

XCTAssertTrue(isSuccess)
XCTAssertFalse(isError)
XCTAssertTrue(hasFeatures)
}

func testWithEncryptGetDataFromCache() throws {
Expand All @@ -80,6 +92,7 @@ class FeaturesViewModelTests: XCTestCase, FeaturesFlowDelegate {

XCTAssertTrue(isSuccess)
XCTAssertFalse(isError)
XCTAssertTrue(hasFeatures)
}

func testError() throws {
Expand All @@ -91,6 +104,7 @@ class FeaturesViewModelTests: XCTestCase, FeaturesFlowDelegate {

XCTAssertFalse(isSuccess)
XCTAssertTrue(isError)
XCTAssertFalse(hasFeatures)
}

func testInvalid() throws {
Expand All @@ -101,16 +115,19 @@ class FeaturesViewModelTests: XCTestCase, FeaturesFlowDelegate {

XCTAssertFalse(isSuccess)
XCTAssertTrue(isError)
XCTAssertFalse(hasFeatures)
}

func featuresFetchedSuccessfully(features: Features, isRemote: Bool) {
isSuccess = true
isError = false
hasFeatures = !features.isEmpty
}

func featuresFetchFailed(error: SDKError, isRemote: Bool) {
isSuccess = false
isError = true
hasFeatures = false
}

func featuresAPIModelSuccessfully(model: FeaturesDataModel) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/CommonMain/Features/FeaturesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class FeaturesViewModel {
let decoder = JSONDecoder()
if let jsonPetitions = try? decoder.decode(FeaturesDataModel.self, from: data) {
delegate?.featuresAPIModelSuccessfully(model: jsonPetitions)
if let features = jsonPetitions.features {
if let features = jsonPetitions.features, !features.isEmpty {
if let featureData = try? JSONEncoder().encode(features) {
manager.putData(fileName: Constants.featureCache, content: featureData)
}
Expand Down

0 comments on commit 0ec3552

Please sign in to comment.