Skip to content

Commit

Permalink
🧪 chore: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
rezk2ll committed Jan 21, 2025
1 parent 54c11ab commit 92fcc18
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
6 changes: 6 additions & 0 deletions packages/matrix-identity-server/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,9 @@ describe('Use environment variables', () => {
process.env.HASHES_RATE_LIMIT = '4'
idServer = new IdServer()
app = express()
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

idServer.ready
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then(() => {
Expand Down Expand Up @@ -1629,6 +1632,9 @@ describe('_matrix/identity/v2/terms', () => {
}
idServer2 = new IdServer(conf2)
app2 = express()
app2.use(express.json())
app2.use(express.urlencoded({ extended: true }))

idServer2.ready
.then(() => {
Object.keys(idServer2.api.get).forEach((k) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/matrix-identity-server/src/terms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ beforeAll((done) => {
.then(() => {
idServer = new IdServer()
app = express()
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

idServer.ready
.then(() => {
Expand Down
41 changes: 11 additions & 30 deletions packages/utils/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,7 @@ describe('Utility Functions', () => {
it('should parse JSON content and call the callback', (done) => {
const req = {
headers: { 'content-type': 'application/json' },
on: (event: string, callback: any) => {
if (event === 'data') {
callback(JSON.stringify({ key: 'value' }))
}
if (event === 'end') {
callback()
}
}
body: { key: 'value' }
} as unknown as Request

jsonContent(
Expand All @@ -76,14 +69,7 @@ describe('Utility Functions', () => {
it('should handle form-urlencoded content', (done) => {
const req = {
headers: { 'content-type': 'application/x-www-form-urlencoded' },
on: (event: string, callback: any) => {
if (event === 'data') {
callback(querystring.stringify({ key: 'value' }))
}
if (event === 'end') {
callback()
}
}
body: { key: 'value' }
} as unknown as Request

jsonContent(
Expand All @@ -97,7 +83,7 @@ describe('Utility Functions', () => {
)
})

it('should handle JSON parsing errors', (done) => {
it('should handle JSON parsing errors', () => {
const req = {
headers: { 'content-type': 'application/json' },
on: (event: string, callback: any) => {
Expand All @@ -110,20 +96,15 @@ describe('Utility Functions', () => {
}
} as unknown as Request

jsonContent(req, mockResponse as Response, mockLogger, () => {
// No-op
})
jsonContent(req, mockResponse as Response, mockLogger, () => {})

setImmediate(() => {
expect(mockLogger.error).toHaveBeenCalled()
expect(mockResponse.writeHead).toHaveBeenCalledWith(
400,
expect.any(Object)
)
expect(mockResponse.write).toHaveBeenCalled()
expect(mockResponse.end).toHaveBeenCalled()
done()
})
expect(mockLogger.error).toHaveBeenCalled()
expect(mockResponse.writeHead).toHaveBeenCalledWith(
400,
expect.any(Object)
)
expect(mockResponse.write).toHaveBeenCalled()
expect(mockResponse.end).toHaveBeenCalled()
})
})

Expand Down

0 comments on commit 92fcc18

Please sign in to comment.