Skip to content

Commit

Permalink
Fix testMatch on e2e-js (#713)
Browse files Browse the repository at this point in the history
* remove testMatch from playwright config and remove the ignore

* fix roomSessionPromoteParticipant.spec.ts to check for 202 instead of 403

* accept 202 as valid response code

* update check on promote

* changeset
  • Loading branch information
Edoardo Gallo authored Jan 10, 2023
1 parent 3d1b455 commit e1e1e33
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-pets-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/core': patch
---

Accept 202 as valid response code
1 change: 0 additions & 1 deletion internal/e2e-js/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const config: PlaywrightTestConfig = {
globalSetup: require.resolve('./global-setup'),
// testMatch: ['roomSessionStreamingAPI.spec.ts'],
testIgnore: [
'roomSessionPromoteParticipant.spec.ts',
// 'roomSessionStreaming.spec.ts',
],
timeout: 120_000,
Expand Down
15 changes: 7 additions & 8 deletions internal/e2e-js/tests/roomSessionPromoteParticipant.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
SERVER_URL,
} from '../utils'

test.describe('RoomSession promote method', () => {
test('should not be able to promote participant', async ({ context }) => {
test.describe('RoomSession promote myself', () => {
test('should get 202 on trying to promote a member', async ({ context }) => {
const pageOne = await context.newPage()
enablePageLogs(pageOne, '[pageOne]')

Expand Down Expand Up @@ -47,21 +47,20 @@ test.describe('RoomSession promote method', () => {
await pageOne.waitForTimeout(2000)

// --------------- Promote participant from pageOne and resolve on error ---------------
const errorCode: any = await pageOne.evaluate(async () => {
const promoteResponse: any = await pageOne.evaluate(() => {
// @ts-expect-error
const roomObj: Video.RoomSession = window._roomObj

const error = await roomObj
return roomObj
.promote({
memberId: roomObj.memberId,
permissions: ['room.member.promote', 'room.member.demote'],
})
.catch((error) => error)
console.log('promote error', error.jsonrpc.code, error.jsonrpc.message)
return error.jsonrpc.code
.then(() => true)
.catch(() => false)
})

expect(errorCode).toBe('403')
expect(promoteResponse).toBe(true)

// --------------- Leaving the rooms ---------------
// @ts-expect-error
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/utils/parseRPCResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const parseRPCResponse = ({
}
}

const SUCCESS_CODES = ['200', '202']

/**
* From the socket we can get:
* - JSON-RPC msg with 1 level of 'result' or 'error'
Expand All @@ -40,7 +42,7 @@ const parseResponse = (
return { error }
}
const { code, node_id, result: nestedResult = null } = result
if (code && code !== '200') {
if (code && !SUCCESS_CODES.includes(code)) {
return { error: result }
}
if (nestedResult === null) {
Expand Down

0 comments on commit e1e1e33

Please sign in to comment.