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 c8ee2cf
Showing 1 changed file with 11 additions and 30 deletions.
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 c8ee2cf

Please sign in to comment.