-
Notifications
You must be signed in to change notification settings - Fork 84
SDK-26 Add placement id list as a parameter for syncMessages #985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,33 @@ final class EmbeddedManagerTests: XCTestCase { | |
|
|
||
| wait(for: [syncMessagesExpectation, delegateExpectation, syncSuccessExpectation], timeout: 2) | ||
| } | ||
|
|
||
| func testSyncMessagesWithPlacementIdsDoesNotClearOtherPlacements() { | ||
| let mockApiClient = MockApiClient() | ||
| mockApiClient.populateMessages([ | ||
| 1: [IterableEmbeddedMessage(messageId: "1a", placementId: 1)], | ||
| 2: [IterableEmbeddedMessage(messageId: "2a", placementId: 2)], | ||
| ]) | ||
|
|
||
| let manager = IterableEmbeddedManager(apiClient: mockApiClient, | ||
| urlDelegate: nil, | ||
| customActionDelegate: nil, | ||
| urlOpener: MockUrlOpener(), | ||
| allowedProtocols: [], | ||
| enableEmbeddedMessaging: true) | ||
|
|
||
| manager.syncMessages { } | ||
| XCTAssertEqual(manager.getMessages(for: 2).map { $0.metadata.messageId }, ["2a"]) | ||
|
|
||
| // Update only placement 1 on the "server", then request only that placement. | ||
| mockApiClient.populateMessages([ | ||
| 1: [IterableEmbeddedMessage(messageId: "1b", placementId: 1)], | ||
| ]) | ||
| manager.syncMessages(placementIds: [1]) { } | ||
|
|
||
| XCTAssertEqual(manager.getMessages(for: 1).map { $0.metadata.messageId }, ["1b"]) | ||
| XCTAssertEqual(manager.getMessages(for: 2).map { $0.metadata.messageId }, ["2a"]) | ||
| } | ||
|
|
||
| func testManagerReset() { | ||
| let syncMessagesExpectation = expectation(description: "syncMessages should complete") | ||
|
|
@@ -392,16 +419,19 @@ final class EmbeddedManagerTests: XCTestCase { | |
| invalidApiKey = true | ||
| } | ||
|
|
||
| override func getEmbeddedMessages() -> IterableSDK.Pending<IterableSDK.PlacementsPayload, IterableSDK.SendRequestError> { | ||
| override func getEmbeddedMessages(placementIds: [Int]?) -> IterableSDK.Pending<IterableSDK.PlacementsPayload, IterableSDK.SendRequestError> { | ||
| if invalidApiKey { | ||
| return FailPending(error: IterableSDK.SendRequestError(reason: "Invalid API Key")) | ||
| } | ||
|
|
||
| if newMessages { | ||
| var placements: [Placement] = [] | ||
| let requested = Set(placementIds ?? []) | ||
| for (placementId, messages) in mockMessages { | ||
| let placement = Placement(placementId: placementId, embeddedMessages: messages) | ||
| placements.append(placement) | ||
| if placementIds == nil || requested.contains(placementId) { | ||
| let placement = Placement(placementId: placementId, embeddedMessages: messages) | ||
| placements.append(placement) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not quite understood this part. is it trying to add placement to list of placement once it sees it has new messages for that placement?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, pretty much. It’s not “seeing new messages per placement”—the newMessages boolean gates the whole response. Once newMessages is true, it adds a placement entry for each placementId in mockMessages that was requested (or all of them if placementIds is nil), using whatever messages are stored there. |
||
| } | ||
| } | ||
|
|
||
| let payload = PlacementsPayload(placements: placements) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.