Skip to content

Commit

Permalink
SwiftFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub committed Jan 28, 2025
1 parent 856ed18 commit 06defcd
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 153 deletions.
208 changes: 104 additions & 104 deletions Tests/AsyncAwait/ChatAsyncIntegrationTests.swift

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Tests/AsyncAwait/MembershipAsyncIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ class MembershipAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
let unreadMessagesCount = try await membership.getUnreadMessagesCount()
XCTAssertEqual(unreadMessagesCount, 3)
}

func testMembershipAsync_GetUnreadMessagesCountForEmptyChannel() async throws {
let someMembership = MembershipImpl(
chat: chat,
channel: channel,
user: UserImpl(chat: chat, id: randomString())
)

let unreadMessagesCount = try await someMembership.getUnreadMessagesCount()
XCTAssertNil(unreadMessagesCount)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/AsyncAwait/MessageAsyncIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MessageAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
testMessage = nil
channel = nil
}

func testMessageAsync_HasNoUserReaction() async throws {
let someMessage = MessageImpl(
chat: chat,
Expand Down
10 changes: 5 additions & 5 deletions Tests/AsyncAwait/MessageDraftAsyncIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class MessageDraftIntegrationTests: BaseAsyncIntegrationTestCase {
override func customSetup() async throws {
let channelId = "cchnl\(randomString())"
let userId = "uuser\(randomString())"

channel = try await chat.createChannel(id: channelId, name: channelId)
user = try await chat.createUser(user: UserImpl(chat: chat, id: userId, name: userId))

try await channel.invite(user: user)
}

override func customTearDown() async throws {
_ = try? await chat.deleteUser(id: user.id)
_ = try? await chat.deleteChannel(id: channel.id)
Expand Down Expand Up @@ -60,7 +60,7 @@ class MessageDraftIntegrationTests: BaseAsyncIntegrationTestCase {
messageDraft.update(text: "This is a @uuser")

await fulfillment(of: [expectation], timeout: 6)

let timetoken = try await messageDraft.send()
try await Task.sleep(nanoseconds: 3_000_000_000)
let message = try await channel.getMessage(timetoken: timetoken)
Expand Down Expand Up @@ -104,7 +104,7 @@ class MessageDraftIntegrationTests: BaseAsyncIntegrationTestCase {
messageDraft.update(text: "This is a #cchnl")

await fulfillment(of: [expectation], timeout: 6)

let timetoken = try await messageDraft.send()
try await Task.sleep(nanoseconds: 3_000_000_000)
let message = try await channel.getMessage(timetoken: timetoken)
Expand Down
14 changes: 7 additions & 7 deletions Tests/AsyncAwait/ThreadChannelAsyncIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ class ThreadChannelAsyncIntegrationTests: BaseAsyncIntegrationTestCase {

override func customSetup() async throws {
parentChannel = try await chat.createChannel(id: randomString())

let timetoken = try await parentChannel.sendText(text: "Message")
try await Task.sleep(nanoseconds: 3_000_000_000)

let testMessage = try await parentChannel.getMessage(timetoken: timetoken)
let unwrappedTestMessage = try XCTUnwrap(testMessage)

threadChannel = try await unwrappedTestMessage.createThread()

try await threadChannel.sendText(text: "Reply in a thread")
}

override func customTearDown() async throws {
_ = try? await parentChannel.delete()
_ = try? await threadChannel.delete()
Expand All @@ -42,10 +42,10 @@ class ThreadChannelAsyncIntegrationTests: BaseAsyncIntegrationTestCase {

let message = try await threadChannel.getHistory().messages.first
let unwrappedMessage = try XCTUnwrap(message)

let updatedChannel = try await threadChannel.pinMessageToParentChannel(message: unwrappedMessage)
let pinnedMessage = try await updatedChannel.getPinnedMessage()

XCTAssertNotNil(pinnedMessage)
}
}
2 changes: 1 addition & 1 deletion Tests/AsyncAwait/ThreadMessageAsyncIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ThreadMessageaAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
func testThreadMessageAsync_HasNoUserReactions() throws {
XCTAssertFalse(threadMessage.hasUserReaction(reaction: "someReaction"))
}

func testThreadMessageAsync_EditText() async throws {
let currentMessageText = threadMessage.text
let newText = "NewTextValue"
Expand Down
46 changes: 23 additions & 23 deletions Tests/AsyncAwait/UserAsyncIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
type: "admin"
)
}

func testUserAsync_CreateUser() async throws {
let user = testableUser()
let createdUser = try await chat.createUser(user: user)
Expand Down Expand Up @@ -70,7 +70,7 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
XCTAssertEqual(updatedUser.status, "inactive")
XCTAssertEqual(updatedUser.type, "regular")
}

func testUserAsync_UpdateUserCallback() async throws {
try await chat.currentUser.update(
name: "Markus Koller",
Expand All @@ -83,7 +83,7 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {

// Simulates updating an outdated version of the User object.
// We expect the fresh object from the server to be returned first, and then subsequent updates to be applied on top of it
let updateResult = try await chat.currentUser.update() {
let updateResult = try await chat.currentUser.update {
[
.stringOptional(\.name, $0.name?.uppercased()),
.stringOptional(\.status, $0.status?.uppercased())
Expand All @@ -98,23 +98,23 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
let errorExpectation = XCTestExpectation(description: "ErrorExpectation")
errorExpectation.assertForOverFulfill = true
errorExpectation.expectedFulfillmentCount = 1

let someUser = testableUser()

do {
try await someUser.update(name: "NewName", externalId: "NewExternalId")
} catch {
XCTAssertEqual((error as? ChatError)?.message, "User does not exist")
errorExpectation.fulfill()
}

await fulfillment(of: [errorExpectation], timeout: 4)
}

func testUserAsync_IsPresentOn() async throws {
let channelId = randomString()
let createdChannel = try await chat.createChannel(id: channelId, name: channelId)

// Keeping a strong reference to this object for test purposes to simulate that someone is already present on the given channel.
// If this object is not retained, it will be deallocated, resulting in no subscription to the channel,
// which would cause the behavior being tested to fail.
Expand All @@ -124,7 +124,7 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
try await Task.sleep(nanoseconds: 4_000_000_000)
let isPresent = try await chat.currentUser.isPresentOn(channelId: createdChannel.id)
XCTAssertTrue(isPresent)

addTeardownBlock { [unowned self] in
_ = try? await chat.deleteChannel(id: channelId)
}
Expand All @@ -140,7 +140,7 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
func testUserAsync_SoftDelete() async throws {
let createdUser = try await chat.createUser(user: testableUser())
let deletedUser = try await createdUser.delete(soft: true)

XCTAssertFalse(
deletedUser?.active ?? true
)
Expand All @@ -154,41 +154,41 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
func testUserAsync_DeleteNotExistingUser() async throws {
let someUser = testableUser()
let resultValue = try await someUser.delete(soft: false)

XCTAssertNil(resultValue)
}

func testUserAsync_WherePresent() async throws {
let channelId = randomString()
let channel = try await chat.createChannel(id: channelId, name: channelId)

// Keeping a strong reference to this object for test purposes to simulate that someone is already present on the given channel.
// If this object is not retained, it will be deallocated, resulting in no subscription to the channel,
// which would cause the behavior being tested to fail.
let connectResult = channel.connect()
debugPrint(connectResult)

try await Task.sleep(nanoseconds: 5_000_000_000)

let channelIdentifiers = try await chat.currentUser.wherePresent()
let expectedChannelIdentifiers = [channelId]

XCTAssertEqual(
expectedChannelIdentifiers,
channelIdentifiers
)

addTeardownBlock { [unowned self] in
_ = try? await chat.deleteChannel(id: channel.id)
}
}

func testUserAsync_GetMemberships() async throws {
let channel = try await chat.createChannel(id: randomString())

try await channel.invite(user: chat.currentUser)
let getMembershipsValue = try await chat.currentUser.getMemberships()

XCTAssertEqual(try (XCTUnwrap(getMembershipsValue.memberships.first)).user.id, chat.currentUser.id)
XCTAssertEqual(try (XCTUnwrap(getMembershipsValue.memberships.first)).channel.id, channel.id)

Expand All @@ -201,9 +201,9 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
let expectation = expectation(description: "StreamUpdates")
expectation.assertForOverFulfill = true
expectation.expectedFulfillmentCount = 1

let createdUser = try await chat.createUser(user: testableUser())

let task = Task {
for await updatedUser in createdUser.streamUpdates() {
XCTAssertEqual(updatedUser?.name, "NewName")
Expand All @@ -216,7 +216,7 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
expectation.fulfill()
}
}

try await Task.sleep(nanoseconds: 3_000_000_000)
try await createdUser.update(
name: "NewName",
Expand All @@ -227,9 +227,9 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
status: "NewStatus",
type: "NewType"
)

await fulfillment(of: [expectation], timeout: 6)

addTeardownBlock { [unowned self] in
task.cancel()
_ = try? await chat.deleteUser(id: createdUser.id)
Expand All @@ -255,7 +255,7 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
}
}
}

for user in [firstUser, secondUser] {
try await Task.sleep(nanoseconds: 3_000_000_000)
try await user.update(
Expand All @@ -273,7 +273,7 @@ class UserAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
of: [expectation],
timeout: 6
)

addTeardownBlock { [unowned self] in
task.cancel()
_ = try? await chat.deleteUser(id: firstUser.id)
Expand Down
2 changes: 1 addition & 1 deletion Tests/BaseClosureIntegrationTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension BaseClosureIntegrationTestCase {
// This extension uses `XCTestExpectation` to flatten the structure of closure-based tests,
// reducing the need for nested closures. It allows tests to appear sequential and easier
// to follow without changing the underlying closure-based behavior.
///
//
// This is not a replacement for Swift's native `async-await` but rather a way to improve
// the readability of tests that involve multiple asynchronous calls with completion handlers.
extension BaseClosureIntegrationTestCase {
Expand Down
14 changes: 7 additions & 7 deletions Tests/ChatIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ class ChatIntegrationTests: BaseClosureIntegrationTestCase {
}
}
}

func testChat_UpdateUser() throws {
let newCustom: [String: JSONCodableScalar] = [
"someValue": 17_253_575_019_298_112,
"someStr": "str"
]

let userId = randomString()

try awaitResultValue {
chat.createUser(
id: userId,
completion: $0
)
}

let updatedUser = try awaitResultValue {
chat.updateUser(
id: userId,
Expand All @@ -116,7 +116,7 @@ class ChatIntegrationTests: BaseClosureIntegrationTestCase {
XCTAssertEqual(updatedUser.custom?.mapValues { $0.scalarValue }, newCustom.mapValues { $0.scalarValue })
XCTAssertEqual(updatedUser.status, "offline")
XCTAssertEqual(updatedUser.type, "regular")

addTeardownBlock { [unowned self] in
try awaitResult {
chat.deleteUser(
Expand Down Expand Up @@ -868,14 +868,14 @@ class ChatIntegrationTests: BaseClosureIntegrationTestCase {
completion: $0
)
}

let tt = try awaitResultValue {
channel.sendText(
text: "Some text",
completion: $0
)
}

try awaitResultValue(delay: 2) {
chat.emitEvent(
channelId: chat.currentUser.id,
Expand Down
4 changes: 2 additions & 2 deletions Tests/UserIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class UserIntegrationTests: BaseClosureIntegrationTestCase {
try awaitResult { chat.deleteUser(
id: user.id,
completion: $0
)}
) }
}
}

Expand Down Expand Up @@ -170,7 +170,7 @@ final class UserIntegrationTests: BaseClosureIntegrationTestCase {
completion: $0
)
}

XCTAssertFalse(
deletedUser?.active ?? true
)
Expand Down

0 comments on commit 06defcd

Please sign in to comment.