Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonar reportportal integration #41

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: test-results
path: lib/test-results/junit/results.xml
path: lib/junit.xml

- name: Publish test results
if: always()
uses: dorny/test-reporter@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: 'Test results'
path: 'lib/test-results/junit/results.xml'
path: 'lib/junit.xml'
reporter: 'jest-junit'
21 changes: 20 additions & 1 deletion lib/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
module.exports = {
bail: true,
preset: "ts-jest",
testEnvironment: "node",
setupFiles: ["./test-setup.js"],
reporters: [
"default",
[
"@reportportal/agent-js-jest",
{
token: "b5acac03-2d5a-40f8-91c3-789e31c35a9e",
endpoint: "http://localhost:8080/api/v1",
project: "superadmin_personal",
launch: "superadmin_TEST_EXAMPLE",
description: "some Description",
logLaunchLink: true,
attributes: [
{
key: "YourKey",
value: "YourValue",
},
{
value: "YourValue",
},
],
},
"jest-junit",
{
outputDirectory: "./lib/test-results/junit",
outputDirectory: "lib/test-results/junit",
outputName: "results.xml",
},
],
Expand Down
5 changes: 3 additions & 2 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
},
"devDependencies": {
"@jest/globals": "29.4.3",
"@reportportal/agent-js-jest": "^5.0.5",
"@types/jest": "29.4.0",
"@types/pubnub": "7.2.0",
"buffer": "5.5.0",
"dotenv": "^16.0.3",
"jest": "29.4.3",
"jest-junit": "^16.0.0",
"nanoid": "^4.0.2",
"ts-jest": "29.0.5",
"typescript": "4.9.5",
"nanoid": "^4.0.2"
"typescript": "4.9.5"
}
}
10 changes: 10 additions & 0 deletions lib/reportportal.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
token: "b5acac03-2d5a-40f8-91c3-789e31c35a9e",
endpoint: "http://localhost:8080/api/v1",
project: "superadmin_personal",
launch: "superadmin_TEST_EXAMPLE",
description: "chat-js-contract",
debug: false,
attributes: [],
mode: "DEFAULT",
}
19 changes: 0 additions & 19 deletions lib/test-results/junit/results.xml

This file was deleted.

110 changes: 110 additions & 0 deletions lib/tests/channel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { Chat, Channel } from "../src"
import * as dotenv from "dotenv"
import { initTestChannel, initTestChat, createRandomUserId } from "./testUtils"

dotenv.config()

describe("Channel test", () => {
let chat: Chat
let channel: Channel | null

beforeEach(async () => {
chat = initTestChat()
channel = await initTestChannel(chat)
})

beforeEach(() => {
jest.resetAllMocks()
})

afterEach(async () => {
await channel?.disconnect()
})

test("should create a channel", async () => {
const channelId = createRandomUserId()
const channelName = "Test Channel"
const channelDescription = "This is a test channel"

const channelData = {
name: channelName,
description: channelDescription,
}

const createdChannel = await chat.createChannel(channelId, channelData)

expect(createdChannel).toBeDefined()
expect(createdChannel.id).toEqual(channelId)
expect(createdChannel.name).toEqual(channelName)
expect(createdChannel.description).toEqual(channelDescription)
})

test("should soft delete a channel", async () => {
const channelId = createRandomUserId()
const channelName = "Test Channel"
const channelDescription = "This is a test channel"

const channelData = {
name: channelName,
description: channelDescription,
}

const createdChannel = await chat.createChannel(channelId, channelData)

const deleteOptions = {
soft: true,
}

const isDeleted = await createdChannel.delete(deleteOptions)

expect(isDeleted).toBeTruthy()
})

test("should get channel history", async () => {
const messageText1 = "Test message 1"
const messageText2 = "Test message 2"

if (channel) {
await channel.sendText(messageText1)
await channel.sendText(messageText2)

const history = await channel.getHistory()

const message1InHistory = history.messages.some(
(message) => message.content.text === messageText1
)
const message2InHistory = history.messages.some(
(message) => message.content.text === messageText2
)

expect(message1InHistory).toBeTruthy()
expect(message2InHistory).toBeTruthy()
} else {
fail("Channel is null")
}
})

test("should get channel history with pagination", async () => {
const messageText1 = "Test message 1"
const messageText2 = "Test message 2"
const messageText3 = "Test message 3"

if (channel) {
const result1 = await channel.sendText(messageText1)
const result2 = await channel.sendText(messageText2)
const result3 = await channel.sendText(messageText3)

const history = await channel.getHistory({ count: 2 })

expect(history.messages.length).toBe(2)

expect(history.isMore).toBeTruthy()

const secondPage = await channel.getHistory({ startTimetoken: history.messages[0].timetoken })

expect(secondPage.messages.length).toBeGreaterThanOrEqual(1)
} else {
fail("Channel is null")
}
})
})
4 changes: 3 additions & 1 deletion lib/tests/typing-indicator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe("Typing indicator test", () => {
let chat: Chat
let channel: Channel | null

jest.setTimeout(10000)
beforeEach(async () => {
chat = initTestChat()
channel = await initTestChannel(chat)
Expand All @@ -25,7 +26,8 @@ describe("Typing indicator test", () => {
const callback = jest.fn()
await channel?.getTyping(callback)
await channel?.startTyping()
await new Promise((resolve) => setTimeout(resolve, 2000))
await new Promise((resolve) => setTimeout(resolve, 5000))
expect(callback).toHaveBeenCalledWith(["test-user"])
})
jest.retryTimes(4)
})
2 changes: 1 addition & 1 deletion lib/tests/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("User test", () => {
fail("User to delete is null")
}
if (userToDelete) {
const deleteResult = await userToDelete.delete(false)
const deleteResult = await chat.deleteUser(userId, { soft: false })
expect(deleteResult).toBe(true)
}

Expand Down
Loading