Skip to content

Commit

Permalink
correctly parsing permissionPolicySet
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Jul 2, 2024
1 parent 67c0113 commit 04bd171
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions example/src/tests/groupPermissionsTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ test('group with All Members policy has remove function that is admin only', asy
try {
await alixGroup.removeMembers([caro.address])
assert(false, 'Alix should not be able to remove a member')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
// expected
}
Expand Down
22 changes: 13 additions & 9 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ test('can find a group by id', async () => {
test('can find a message by id', async () => {
const [alixClient, boClient] = await createClients(2)
const alixGroup = await alixClient.conversations.newGroup([boClient.address])
const alixMessageId = await alixGroup.send("Hello")
const alixMessageId = await alixGroup.send('Hello')

await boClient.conversations.syncGroups()
const boGroup = await boClient.conversations.findGroup(alixGroup.id)
Expand Down Expand Up @@ -1094,7 +1094,7 @@ test('can make a group with metadata', async () => {
)

assert(
groupDescription2 === 'a fun description',
groupDescription2 === 'a new group description',
`the group should start with a name of a new group description not ${groupDescription2}`
)

Expand All @@ -1116,11 +1116,16 @@ test('can make a group with metadata', async () => {
'Unexpected message content ' + JSON.stringify(boMessages[0].contentTypeId)
)

const message = boMessages[0].content() as GroupUpdatedContent
const message = boMessages[1].content() as GroupUpdatedContent
assert(
message.metadataFieldsChanged[0].fieldName === 'group_image_url_square',
`the metadata field changed should be group_image_url_square but was ${message.metadataFieldsChanged[0].fieldName}`
)
const message2 = boMessages[0].content() as GroupUpdatedContent
assert(
message2.metadataFieldsChanged[0].fieldName === 'description',
`the metadata field changed should be description but was ${message2.metadataFieldsChanged[0].fieldName}`
)
return true
})

Expand All @@ -1132,15 +1137,15 @@ test('can make a group with admin permissions', async () => {
{ permissionLevel: 'admin_only' }
)

if (group.permissionLevel !== 'admin_only') {
if (group.permissionPolicySet.addMemberPolicy !== 'admin') {
throw Error(
`Group permission level should be admin_only but was ${group.permissionLevel}`
`Group permission level should be admin but was ${group.permissionPolicySet.addMemberPolicy}`
)
}

const isAdmin = await group.isAdmin(adminClient.inboxId)
if (!isAdmin) {
throw Error(`adminClient should be the admin`)
const isSuperAdmin = await group.isSuperAdmin(adminClient.inboxId)
if (!isSuperAdmin) {
throw Error(`adminClient should be the super admin`)
}

// Creator id not working, see https://github.com/xmtp/libxmtp/issues/788
Expand Down Expand Up @@ -1784,7 +1789,6 @@ test('can list groups does not fork', async () => {
return true
})


// Commenting this out so it doesn't block people, but nice to have?
// test('can stream messages for a long time', async () => {
// const bo = await Client.createRandom({ env: 'local', enableV3: true })
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Group<
createdAt: number
peerInboxIds: InboxId[]
creatorInboxId: InboxId
permissionPolicySet: PermissionPolicySet
permissionPolicySet: string
topic: string
name: string
isGroupActive: boolean
Expand All @@ -49,7 +49,7 @@ export class Group<
this.peerInboxIds = params.peerInboxIds
this.topic = params.topic
this.creatorInboxId = params.creatorInboxId
this.permissionPolicySet = params.permissionPolicySet
this.permissionPolicySet = JSON.parse(params.permissionPolicySet)
this.name = params.name
this.isGroupActive = params.isGroupActive
this.imageUrlSquare = params.imageUrlSquare
Expand Down

0 comments on commit 04bd171

Please sign in to comment.