Skip to content

Commit

Permalink
write a test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed May 23, 2024
1 parent 5b8fcdd commit 9d826c1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Sources/XMTPiOS/ApiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ extension GenericErrorDescribing {
let .GroupMetadata(message),
let .Generic(message):
return message
case .GroupMutablePermissions(message: let message):
return message
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public struct Group: Identifiable, Equatable, Hashable {
return try metadata().creatorAccountAddress().lowercased() == client.address.lowercased()
}

public func permissionLevel() throws -> GroupPermissions {
return try metadata().policyType()
}
// public func permissionLevel() throws -> GroupPermissions {
// return try metadata().policyType()
// }

public func adminAddress() throws -> String {
return try metadata().creatorAccountAddress()
Expand Down
35 changes: 35 additions & 0 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,41 @@ class ClientTests: XCTestCase {
groupCount = try await boClient.conversations.groups().count
XCTAssertEqual(groupCount, 0)
}

func testCanDropReconnectDatabase() async throws {
let bo = try PrivateKey.generate()
let alix = try PrivateKey.generate()
var boClient = try await Client.create(
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true
)
)

let alixClient = try await Client.create(
account: alix,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true
)
)

_ = try await boClient.conversations.newGroup(with: [alixClient.address])
try await boClient.conversations.sync()

var groupCount = try await boClient.conversations.groups().count
XCTAssertEqual(groupCount, 1)

try boClient.dropLocalDatabaseConnection()

await assertThrowsAsyncError(try await boClient.conversations.groups())

try await boClient.reconnectLocalDatabase()

groupCount = try await boClient.conversations.groups().count
XCTAssertEqual(groupCount, 1)
}

func testCanMessage() async throws {
let fixtures = await fixtures()
Expand Down
8 changes: 4 additions & 4 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class GroupTests: XCTestCase {
XCTAssertEqual(aliceGroup.memberAddresses.count, 3)
XCTAssertEqual(bobGroup.memberAddresses.count, 3)

XCTAssertEqual(try bobGroup.permissionLevel(), .everyoneIsAdmin)
XCTAssertEqual(try aliceGroup.permissionLevel(), .everyoneIsAdmin)
// XCTAssertEqual(try bobGroup.permissionLevel(), .everyoneIsAdmin)
// XCTAssertEqual(try aliceGroup.permissionLevel(), .everyoneIsAdmin)
XCTAssertEqual(try bobGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased())
XCTAssertEqual(try aliceGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased())
XCTAssert(try bobGroup.isAdmin())
Expand Down Expand Up @@ -156,8 +156,8 @@ class GroupTests: XCTestCase {
XCTAssertEqual(aliceGroup.memberAddresses.count, 2)
XCTAssertEqual(bobGroup.memberAddresses.count, 2)

XCTAssertEqual(try bobGroup.permissionLevel(), .groupCreatorIsAdmin)
XCTAssertEqual(try aliceGroup.permissionLevel(), .groupCreatorIsAdmin)
// XCTAssertEqual(try bobGroup.permissionLevel(), .groupCreatorIsAdmin)
// XCTAssertEqual(try aliceGroup.permissionLevel(), .groupCreatorIsAdmin)
XCTAssertEqual(try bobGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased())
XCTAssertEqual(try aliceGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased())
XCTAssert(try bobGroup.isAdmin())
Expand Down

0 comments on commit 9d826c1

Please sign in to comment.