Skip to content

Commit

Permalink
add tests for it
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Feb 19, 2024
1 parent 010b9b3 commit d3cfc01
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import CryptoKit
import XCTest
@testable import XMTPiOS
import LibXMTP
import XMTPTestHelpers

func assertThrowsAsyncError<T>(
Expand Down Expand Up @@ -83,11 +84,63 @@ class GroupTests: XCTestCase {
)
}

func testCanCreateGroups() async throws {
func testCanCreateAGroupWithDefaultPermissions() async throws {
let fixtures = try await localFixtures()
let group = try await fixtures.aliceClient.conversations.newGroup(with: [fixtures.bob.address])
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.address])
try await fixtures.aliceClient.conversations.sync()
let aliceGroup = try await fixtures.aliceClient.conversations.groups().first!
XCTAssert(!bobGroup.id.isEmpty)
XCTAssert(!aliceGroup.id.isEmpty)


try await aliceGroup.addMembers(addresses: [fixtures.fred.address])
try await bobGroup.sync()
XCTAssertEqual(aliceGroup.memberAddresses.count, 3)
XCTAssertEqual(bobGroup.memberAddresses.count, 3)

try await aliceGroup.removeMembers(addresses: [fixtures.fred.address])
try await bobGroup.sync()
XCTAssertEqual(aliceGroup.memberAddresses.count, 2)
XCTAssertEqual(bobGroup.memberAddresses.count, 2)

XCTAssert(!group.id.isEmpty)
try await bobGroup.addMembers(addresses: [fixtures.fred.address])
try await aliceGroup.sync()
XCTAssertEqual(aliceGroup.memberAddresses.count, 3)
XCTAssertEqual(bobGroup.memberAddresses.count, 3)
}

func testCanCreateAGroupWithAdminPermissions() async throws {
let fixtures = try await localFixtures()
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.address], permissions: GroupPermissions.groupCreatorIsAdmin)
try await fixtures.aliceClient.conversations.sync()
let aliceGroup = try await fixtures.aliceClient.conversations.groups().first!
XCTAssert(!bobGroup.id.isEmpty)
XCTAssert(!aliceGroup.id.isEmpty)


try await bobGroup.addMembers(addresses: [fixtures.fred.address])
try await aliceGroup.sync()
XCTAssertEqual(aliceGroup.memberAddresses.count, 3)
XCTAssertEqual(bobGroup.memberAddresses.count, 3)

await assertThrowsAsyncError(
try await aliceGroup.removeMembers(addresses: [fixtures.fred.address])
)
try await bobGroup.sync()
XCTAssertEqual(aliceGroup.memberAddresses.count, 3)
XCTAssertEqual(bobGroup.memberAddresses.count, 3)

try await bobGroup.removeMembers(addresses: [fixtures.fred.address])
try await aliceGroup.sync()
XCTAssertEqual(aliceGroup.memberAddresses.count, 2)
XCTAssertEqual(bobGroup.memberAddresses.count, 2)

await assertThrowsAsyncError(
try await aliceGroup.addMembers(addresses: [fixtures.fred.address])
)
try await bobGroup.sync()
XCTAssertEqual(aliceGroup.memberAddresses.count, 2)
XCTAssertEqual(bobGroup.memberAddresses.count, 2)
}

func testCanListGroups() async throws {
Expand Down

0 comments on commit d3cfc01

Please sign in to comment.