Skip to content

Commit

Permalink
testNotifyServerSubscribeAndNotifies refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
flypaper0 committed Nov 7, 2023
1 parent 5076c9c commit 790f8b4
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Example/IntegrationTests/Push/NotifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,11 @@ final class NotifyTests: XCTestCase {
let expectation = expectation(description: "expects client B to receive subscription after both clients are registered and client A creates one")
expectation.assertForOverFulfill = false

var subscription: NotifySubscription!
var subscription: NotifySubscription?

let clientB = makeWalletClient(prefix: "👐🏼 Wallet B: ")
clientB.subscriptionsPublisher.sink { subscriptions in
guard let newSubscription = subscriptions.first else { return }
subscription = newSubscription
subscription = subscriptions.first
expectation.fulfill()
}.store(in: &publishers)

Expand All @@ -161,7 +160,9 @@ final class NotifyTests: XCTestCase {

await fulfillment(of: [expectation], timeout: InputConfig.defaultTimeout)

try await clientB.deleteSubscription(topic: subscription.topic)
if let subscription {
try await clientB.deleteSubscription(topic: subscription.topic)
}
}

func testWalletCreatesAndUpdatesSubscription() async throws {
Expand Down Expand Up @@ -207,6 +208,7 @@ final class NotifyTests: XCTestCase {
let messageExpectation = expectation(description: "receives a notify message")

var notifyMessage: NotifyMessage!
var notifyMessageRecord: NotifyMessageRecord?

var didNotify = false
walletNotifyClientA.subscriptionsPublisher
Expand All @@ -231,19 +233,20 @@ final class NotifyTests: XCTestCase {
}.store(in: &publishers)

walletNotifyClientA.notifyMessagePublisher
.sink { [unowned self] notifyMessageRecord in
XCTAssertEqual(notifyMessageRecord.message, notifyMessage)

Task(priority: .high) {
try await walletNotifyClientA.deleteSubscription(topic: notifyMessageRecord.topic)
messageExpectation.fulfill()
}
.sink { newNotifyMessageRecord in
XCTAssertEqual(newNotifyMessageRecord.message, notifyMessage)
notifyMessageRecord = newNotifyMessageRecord
messageExpectation.fulfill()
}.store(in: &publishers)

try! await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign)
try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account)

await fulfillment(of: [subscribeExpectation, messageExpectation], timeout: InputConfig.defaultTimeout)

if let notifyMessageRecord {
try await walletNotifyClientA.deleteSubscription(topic: notifyMessageRecord.topic)
}
}

}
Expand Down

0 comments on commit 790f8b4

Please sign in to comment.