Skip to content

Commit

Permalink
more socket ticket tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tudddorrr committed Dec 28, 2024
1 parent aa0b147 commit 91468e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/services/_api/socket-ticket-api/post.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import request from 'supertest'
import createAPIKeyAndToken from '../../../utils/createAPIKeyAndToken'

describe('Socket ticket API service - post', () => {
it('should return a valid socket ticket', async () => {
const [, token] = await createAPIKeyAndToken([])

const res = await request(global.app)
.post('/v1/socket-tickets')
.auth(token, { type: 'bearer' })
.expect(200)

expect(res.body.ticket).toHaveLength(36)
})
})
17 changes: 17 additions & 0 deletions tests/socket/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Redis } from 'ioredis'
import redisConfig from '../../src/config/redis.config'
import { createSocketTicket } from '../../src/services/api/socket-ticket-api.service'
import createTestSocket from '../utils/createTestSocket'
import { EntityManager } from '@mikro-orm/mysql'

describe('Socket server', () => {
it('should send a connected message when sending an auth ticket', async () => {
Expand Down Expand Up @@ -37,4 +38,20 @@ describe('Socket server', () => {
waitForReady: false
})
})

it('should close connections where the socket ticket has a revoked api key', async () => {
const [apiKey] = await createAPIKeyAndToken([])
apiKey.revokedAt = new Date()
await (<EntityManager>global.em).flush()

const redis = new Redis(redisConfig)
const ticket = await createSocketTicket(redis, apiKey, false)
await redis.quit()

await createTestSocket(`/?ticket=${ticket}`, async (client) => {
await client.expectClosed(3000)
}, {
waitForReady: false
})
})
})

0 comments on commit 91468e7

Please sign in to comment.