Skip to content

Commit

Permalink
♻️ Update tests to account for changes in QualifyResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
iujames committed Dec 5, 2022
1 parent 7bd134a commit 8252687
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
13 changes: 13 additions & 0 deletions Sources/AppcuesKit/Data/Models/Experience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,16 @@ extension Experience.Action: Decodable {
}

}

// utility to quickly extract the list of valid Experiences from an array of
// LossyExperience values
extension Array where Element == LossyExperience {
func parsed() -> [Experience] {
return self.compactMap {
if case let .decoded(experience) = $0 {
return experience
}
return nil
}
}
}
11 changes: 0 additions & 11 deletions Sources/AppcuesKit/Data/Models/QualifyResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,3 @@ extension QualifyResponse: Decodable {
experiences = decodedExperiences
}
}

extension Array where Element == LossyExperience {
func parsed() -> [Experience] {
return self.compactMap {
if case let .decoded(experience) = $0 {
return experience
}
return nil
}
}
}
18 changes: 9 additions & 9 deletions Tests/AppcuesKitTests/Analytics/ActivityProcessorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ActivityProcessorTests: XCTestCase {
let data = try NetworkClient.encoder.encode(activity)
XCTAssertEqual(data, body)
onPostExpectation.fulfill()
completion(.success(QualifyResponse(experiences: [self.mockExperience], performedQualification: true, qualificationReason: nil, experiments: nil)))
completion(.success(QualifyResponse(experiences: [.decoded(self.mockExperience)], performedQualification: true, qualificationReason: nil, experiments: nil)))
} catch {
XCTFail()
}
Expand All @@ -58,7 +58,7 @@ class ActivityProcessorTests: XCTestCase {
guard case let .success(taco) = result else { return XCTFail() }
XCTAssertEqual(true, taco.performedQualification)
XCTAssertEqual(1, taco.experiences.count)
XCTAssertEqual(self.mockExperience.name, taco.experiences.first?.name)
XCTAssertEqual(self.mockExperience.name, taco.experiences.parsed().first?.name)
resultCallbackExpectation.fulfill()
}

Expand Down Expand Up @@ -104,7 +104,7 @@ class ActivityProcessorTests: XCTestCase {
XCTAssertEqual("user2", userID)
let data = try NetworkClient.encoder.encode(activity2)
XCTAssertEqual(data, body)
completion(.success(QualifyResponse(experiences: [self.mockExperience], performedQualification: true, qualificationReason: nil, experiments: nil)))
completion(.success(QualifyResponse(experiences: [.decoded(self.mockExperience)], performedQualification: true, qualificationReason: nil, experiments: nil)))
onPostExpectation2.fulfill()
} else {
XCTFail()
Expand All @@ -123,7 +123,7 @@ class ActivityProcessorTests: XCTestCase {
guard case let .success(taco) = result else { return XCTFail() }
XCTAssertEqual(true, taco.performedQualification)
XCTAssertEqual(1, taco.experiences.count)
XCTAssertEqual(self.mockExperience.name, taco.experiences.first?.name)
XCTAssertEqual(self.mockExperience.name, taco.experiences.parsed().first?.name)
resultCallbackExpectation2.fulfill()

}
Expand Down Expand Up @@ -159,7 +159,7 @@ class ActivityProcessorTests: XCTestCase {
XCTAssertEqual("user2", userID)
let data = try NetworkClient.encoder.encode(activity2)
XCTAssertEqual(data, body)
completion(.success(QualifyResponse(experiences: [self.mockExperience], performedQualification: true, qualificationReason: nil, experiments: nil)))
completion(.success(QualifyResponse(experiences: [.decoded(self.mockExperience)], performedQualification: true, qualificationReason: nil, experiments: nil)))
onPostExpectation2.fulfill()
} else {
XCTFail()
Expand All @@ -179,7 +179,7 @@ class ActivityProcessorTests: XCTestCase {
guard case let .success(taco) = result else { return XCTFail() }
XCTAssertEqual(true, taco.performedQualification)
XCTAssertEqual(1, taco.experiences.count)
XCTAssertEqual(self.mockExperience.name, taco.experiences.first?.name)
XCTAssertEqual(self.mockExperience.name, taco.experiences.parsed().first?.name)
XCTAssertEqual(0, self.mockStorage.count) // all cleared out
resultCallbackExpectation2.fulfill()

Expand Down Expand Up @@ -266,7 +266,7 @@ class ActivityProcessorTests: XCTestCase {
XCTAssertEqual("user2", userID)
let data = try NetworkClient.encoder.encode(activity2)
XCTAssertEqual(data, body)
completion(.success(QualifyResponse(experiences: [self.mockExperience], performedQualification: true, qualificationReason: nil, experiments: nil)))
completion(.success(QualifyResponse(experiences: [.decoded(self.mockExperience)], performedQualification: true, qualificationReason: nil, experiments: nil)))
onPostExpectation2.fulfill()
} else {
XCTFail()
Expand All @@ -287,7 +287,7 @@ class ActivityProcessorTests: XCTestCase {
guard case let .success(taco) = result else { return XCTFail() }
XCTAssertEqual(true, taco.performedQualification)
XCTAssertEqual(1, taco.experiences.count)
XCTAssertEqual(self.mockExperience.name, taco.experiences.first?.name)
XCTAssertEqual(self.mockExperience.name, taco.experiences.parsed().first?.name)
XCTAssertEqual(0, self.mockStorage.count) // all cleared out
resultCallbackExpectation2.fulfill()

Expand All @@ -307,7 +307,7 @@ class ActivityProcessorTests: XCTestCase {
let activity = generateMockActivity(userID: "user1", event: Event(name: "event1", attributes: ["my_key": "my_value1", "another_key": 33]))

appcues.networking.onPost = { endpoint, body, requestId, completion in
completion(.success(QualifyResponse(experiences: [self.mockExperience], performedQualification: true, qualificationReason: nil, experiments: nil)))
completion(.success(QualifyResponse(experiences: [.decoded(self.mockExperience)], performedQualification: true, qualificationReason: nil, experiments: nil)))
onPostExpectation.fulfill()
}

Expand Down

0 comments on commit 8252687

Please sign in to comment.