Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Jun 15, 2024
1 parent c9a6a3f commit 9000781
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/mls-client/test/Conversation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ describe('Conversation', () => {
expect(conversation2.messages().length).toBe(1)
})

it('should update conversation image URL', async () => {
const user1 = createUser()
const user2 = createUser()
const client1 = await createRegisteredClient(user1)
const client2 = await createRegisteredClient(user2)
const conversation = await client1.conversations.newConversation([
user2.account.address,
])
const imageUrl = 'https://foo/bar.jpg'
await conversation.updateImageUrl(imageUrl)
expect(conversation.imageUrl).toBe(imageUrl)
const messages = conversation.messages()
expect(messages.length).toBe(2)

await client2.conversations.sync()
const conversations = await client2.conversations.list()
expect(conversations.length).toBe(1)

const conversation2 = conversations[0]
expect(conversation2).toBeDefined()
await conversation2.sync()
expect(conversation2.id).toBe(conversation.id)
expect(conversation2.imageUrl).toBe(imageUrl)
expect(conversation2.messages().length).toBe(1)
})

it('should add and remove members', async () => {
const user1 = createUser()
const user2 = createUser()
Expand Down
58 changes: 58 additions & 0 deletions packages/mls-client/test/Conversations.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContentTypeText } from '@xmtp/content-type-text'
import { GroupPermissions } from '@xmtp/mls-client-bindings-node'
import { describe, expect, it } from 'vitest'
import { createRegisteredClient, createUser } from '@test/helpers'

Expand All @@ -25,6 +26,9 @@ describe('Conversations', () => {
expect(conversation.createdAtNs).toBeDefined()
expect(conversation.isActive).toBe(true)
expect(conversation.name).toBe('')
expect(conversation.permissions.policyType).toBe(
GroupPermissions.EveryoneIsAdmin
)
expect(conversation.addedByInboxId).toBe(client1.inboxId)
expect(conversation.messages().length).toBe(1)
expect(conversation.members.length).toBe(2)
Expand All @@ -49,6 +53,60 @@ describe('Conversations', () => {
expect(conversations2[0].id).toBe(conversation.id)
})

it('should create a new conversation with options', async () => {
const user1 = createUser()
const user2 = createUser()
const user3 = createUser()
const user4 = createUser()
const user5 = createUser()
const client1 = await createRegisteredClient(user1)
await createRegisteredClient(user2)
await createRegisteredClient(user3)
await createRegisteredClient(user4)
await createRegisteredClient(user5)
const groupWithName = await client1.conversations.newConversation(
[user2.account.address],
{
groupName: 'foo',
}
)
expect(groupWithName).toBeDefined()
expect(groupWithName.name).toBe('foo')
expect(groupWithName.imageUrl).toBe('')

const groupWithImageUrl = await client1.conversations.newConversation(
[user3.account.address],
{
groupImageUrlSquare: 'https://foo/bar.png',
}
)
expect(groupWithImageUrl).toBeDefined()
expect(groupWithImageUrl.name).toBe('')
expect(groupWithImageUrl.imageUrl).toBe('https://foo/bar.png')

const groupWithNameAndImageUrl =
await client1.conversations.newConversation([user4.account.address], {
groupImageUrlSquare: 'https://foo/bar.png',
groupName: 'foo',
})
expect(groupWithNameAndImageUrl).toBeDefined()
expect(groupWithNameAndImageUrl.name).toBe('foo')
expect(groupWithNameAndImageUrl.imageUrl).toBe('https://foo/bar.png')

const groupWithPermissions = await client1.conversations.newConversation(
[user4.account.address],
{
permissions: GroupPermissions.GroupCreatorIsAdmin,
}
)
expect(groupWithPermissions).toBeDefined()
expect(groupWithPermissions.name).toBe('')
expect(groupWithPermissions.imageUrl).toBe('')
expect(groupWithPermissions.permissions.policyType).toBe(
GroupPermissions.GroupCreatorIsAdmin
)
})

it('should stream new conversations', async () => {
const user1 = createUser()
const user2 = createUser()
Expand Down

0 comments on commit 9000781

Please sign in to comment.