Skip to content

Commit

Permalink
pr updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tudddorrr committed Dec 29, 2024
1 parent 91468e7 commit 46e0f34
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/docs/socket-tickets-api.docs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SocketTicketAPIService from '../services/api/socket-ticket-api.service'
import APIDocs from './api-docs'

const SocketTicketsAPIDocs: APIDocs<SocketTicketAPIService> = {
const SocketTicketAPIDocs: APIDocs<SocketTicketAPIService> = {
post: {
description: 'Create a socket ticket (expires after 5 minutes)',
samples: [
Expand All @@ -15,4 +15,4 @@ const SocketTicketsAPIDocs: APIDocs<SocketTicketAPIService> = {
}
}

export default SocketTicketsAPIDocs
export default SocketTicketAPIDocs
4 changes: 2 additions & 2 deletions src/services/api/socket-ticket-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createRedisConnection } from '../../config/redis.config'
import { v4 } from 'uuid'
import Redis from 'ioredis'
import APIKey from '../../entities/api-key'
import SocketTicketsAPIDocs from '../../docs/socket-tickets-api.docs'
import SocketTicketAPIDocs from '../../docs/socket-tickets-api.docs'

export async function createSocketTicket(redis: Redis, key: APIKey, devBuild: boolean): Promise<string> {
const ticket = v4()
Expand All @@ -15,7 +15,7 @@ export async function createSocketTicket(redis: Redis, key: APIKey, devBuild: bo
}

export default class SocketTicketAPIService extends APIService {
@Docs(SocketTicketsAPIDocs.post)
@Docs(SocketTicketAPIDocs.post)
async post(req: Request): Promise<Response> {
const redis = createRedisConnection(req.ctx)

Expand Down
2 changes: 0 additions & 2 deletions tests/services/api-key/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ describe('API key service - delete', () => {
await redis.quit()

await createTestSocket(`/?ticket=${ticket}`, async (client) => {
await client.expectReady()

await request(global.app)
.delete(`/games/${game.id}/api-keys/${key.id}`)
.auth(token, { type: 'bearer' })
Expand Down
23 changes: 11 additions & 12 deletions tests/socket/messages/socketLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Socket logger', () => {
vi.unstubAllEnvs()
})

async function createSocketConnection(): Promise<[TaloSocket, SocketConnection, () => void]> {
async function createSocketConnection(): Promise<[SocketConnection, () => void]> {
const [apiKey] = await createAPIKeyAndToken([])
await (<EntityManager>global.em).persistAndFlush(apiKey)

Expand All @@ -40,16 +40,15 @@ describe('Socket logger', () => {
const conn = new SocketConnection(wss, ws, ticket, '0.0.0.0')

return [
wss,
conn,
() => {
wss.getServer().close()
server.close()
}
]
}

it('should log requests', async () => {
const [, conn, cleanup] = await createSocketConnection()
const [conn, cleanup] = await createSocketConnection()

logRequest(conn, JSON.stringify({ req: 'v1.fake', data: {} }))

Expand All @@ -60,7 +59,7 @@ describe('Socket logger', () => {
})

it('should log requests with aliases', async () => {
const [, conn, cleanup] = await createSocketConnection()
const [conn, cleanup] = await createSocketConnection()
conn.playerAliasId = 2

logRequest(conn, JSON.stringify({ req: 'v1.fake', data: {} }))
Expand All @@ -72,7 +71,7 @@ describe('Socket logger', () => {
})

it('should log requests without valid json', async () => {
const [, conn, cleanup] = await createSocketConnection()
const [conn, cleanup] = await createSocketConnection()

logRequest(conn, 'v1.fake')

Expand All @@ -83,7 +82,7 @@ describe('Socket logger', () => {
})

it('should log requests without a req', async () => {
const [, conn, cleanup] = await createSocketConnection()
const [conn, cleanup] = await createSocketConnection()

logRequest(conn, JSON.stringify({ wrong: 'v1.fake' }))

Expand All @@ -94,7 +93,7 @@ describe('Socket logger', () => {
})

it('should log responses', async () => {
const [, conn, cleanup] = await createSocketConnection()
const [conn, cleanup] = await createSocketConnection()

logResponse(conn, 'v1.players.identify.success', JSON.stringify({ res: 'v1.players.identify.success', data: {} }))

Expand All @@ -112,7 +111,7 @@ describe('Socket logger', () => {
})

it('should log pre-closed connections', async () => {
const [, conn, cleanup] = await createSocketConnection()
const [conn, cleanup] = await createSocketConnection()

logConnectionClosed(conn, true, 3000)

Expand All @@ -123,7 +122,7 @@ describe('Socket logger', () => {
})

it('should log manually-closed connections', async () => {
const [, conn, cleanup] = await createSocketConnection()
const [conn, cleanup] = await createSocketConnection()

logConnectionClosed(conn, false, 3000, 'Unauthorised')

Expand All @@ -134,7 +133,7 @@ describe('Socket logger', () => {
})

it('should log manually-closed connections without a reason', async () => {
const [, conn, cleanup] = await createSocketConnection()
const [conn, cleanup] = await createSocketConnection()

logConnectionClosed(conn, false, 3000)

Expand All @@ -152,7 +151,7 @@ describe('Socket logger', () => {
})

it('should log pre-closed connection with aliases', async () => {
const [, conn, cleanup] = await createSocketConnection()
const [conn, cleanup] = await createSocketConnection()
conn.playerAliasId = 2

logConnectionClosed(conn, true, 3000)
Expand Down

0 comments on commit 46e0f34

Please sign in to comment.