Skip to content

Commit

Permalink
feat(lib): revert tests
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-suwala committed Jun 18, 2024
1 parent 8381bb0 commit 661ef59
Showing 1 changed file with 48 additions and 70 deletions.
118 changes: 48 additions & 70 deletions lib/tests/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { createChatInstance, createRandomUser, sleep } from "./utils"
import { INTERNAL_ADMIN_CHANNEL } from "../src"

describe("User test", () => {
jest.retryTimes(3)

let chat: Chat
let user: User

Expand Down Expand Up @@ -63,82 +61,62 @@ describe("User test", () => {
stopUpdates()
})

test("should update the user even if they're a member of a particular channel", (done) => {
async function prep() {
let someUser = await chat.getUser("test-user-chatsdk0")
if (!someUser) {
someUser = await chat.createUser("test-user-chatsdk0", { name: "Chat SDK user 0" })
}
let someChannel = await chat.getChannel("some-public-channel")
if (!someChannel) {
someChannel = await chat.createPublicConversation({
channelId: "some-public-channel",
channelData: { name: "Public channel test" },
})
}
await chat.sdk.objects.setChannelMembers({
channel: someChannel.id,
uuids: [someUser.id],
})

return someUser
test("should update the user even if they're a member of a particular channel", async () => {
let someUser = await chat.getUser("test-user-chatsdk0")
if (!someUser) {
someUser = await chat.createUser("test-user-chatsdk0", { name: "Chat SDK user 0" })
}
const updatedNames: string[] = []
let stopUpdatedFunc = () => null

prep().then((someUser) => {
const stopUpdates = User.streamUpdatesOn([someUser], (updatedUsers) => {
someUser = updatedUsers[0]
updatedNames.push(someUser.name)
const joinedNames = updatedNames.join(",")
if (joinedNames === "update number 1,update number 2") {
stopUpdatedFunc()
done()
}
let someChannel = await chat.getChannel("some-public-channel")
if (!someChannel) {
someChannel = await chat.createPublicConversation({
channelId: "some-public-channel",
channelData: { name: "Public channel test" },
})
someUser.update({ name: "update number 1" })
someUser.update({ name: "update number 2" })
stopUpdatedFunc = stopUpdates
})
})

test("should update the user even if they're not a member of a particular channel", (done) => {
async function prep() {
let someUser = await chat.getUser("test-user-chatsdk1")
if (!someUser) {
someUser = await chat.createUser("test-user-chatsdk1", { name: "Chat SDK user 1" })
}
let someChannel = await chat.getChannel("some-public-channel-2")
if (!someChannel) {
someChannel = await chat.createPublicConversation({
channelId: "some-public-channel-2",
channelData: { name: "Public channel test 2" },
})
}
const { members } = await someChannel.getMembers()

return { someUser, members }
}
await chat.sdk.objects.setChannelMembers({
channel: someChannel.id,
uuids: [someUser.id],
})

const updatedNames: string[] = []
let stopUpdatedFunc = () => null
const stopUpdates = User.streamUpdatesOn([someUser], (updatedUsers) => {
someUser = updatedUsers[0]
})
await someUser.update({ name: "update number 1" })
await sleep(1000)
expect(someUser.name).toBe("update number 1")
await someUser.update({ name: "update number 2" })
await sleep(1000)
expect(someUser.name).toBe("update number 2")

prep().then(({ members, someUser }) => {
expect(members.length).toBe(0)
stopUpdates()
})

const stopUpdates = User.streamUpdatesOn([someUser], (updatedUsers) => {
someUser = updatedUsers[0]
updatedNames.push(someUser.name)
const joinedNames = updatedNames.join(",")
if (joinedNames === "update number 1,update number 2") {
stopUpdatedFunc()
done()
}
test("should update the user even if they're not a member of a particular channel", async () => {
let someUser = await chat.getUser("test-user-chatsdk1")
if (!someUser) {
someUser = await chat.createUser("test-user-chatsdk1", { name: "Chat SDK user 1" })
}
let someChannel = await chat.getChannel("some-public-channel-2")
if (!someChannel) {
someChannel = await chat.createPublicConversation({
channelId: "some-public-channel-2",
channelData: { name: "Public channel test 2" },
})
someUser.update({ name: "update number 1" })
someUser.update({ name: "update number 2" })
stopUpdatedFunc = stopUpdates
}
const { members } = await someChannel.getMembers()

expect(members.length).toBe(0)
const stopUpdates = User.streamUpdatesOn([someUser], (updatedUsers) => {
someUser = updatedUsers[0]
})
await someUser.update({ name: "update number 1" })
await sleep(1000)
expect(someUser.name).toBe("update number 1")
await someUser.update({ name: "update number 2" })
await sleep(1000)
expect(someUser.name).toBe("update number 2")

stopUpdates()
})

test("should report a user", async () => {
Expand Down

0 comments on commit 661ef59

Please sign in to comment.