Skip to content

Commit

Permalink
add more test cases to reach 90 percent coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sepehr-safari committed Jan 24, 2024
1 parent edbc862 commit cc02675
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions nip96.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ describe('readServerConfig', () => {
server.close()
})

it('should throw an error if response is not proper json', async () => {
// setup mock server
const HTTPROUTE = '/.well-known/nostr/nip96.json' as const
const handler = http.get(`http://example.com${HTTPROUTE}`, () => {
return HttpResponse.json(null)
})
const server = setupServer(handler)
server.listen()

expect(readServerConfig('http://example.com/')).rejects.toThrow()

// cleanup mock server
server.resetHandlers()
server.close()
})

it('should throw an error if response status is not 200', async () => {
// setup mock server
const HTTPROUTE = '/.well-known/nostr/nip96.json' as const
Expand Down Expand Up @@ -153,6 +169,17 @@ describe('validateFileUploadResponse', () => {
expect(result).toBe(false)
})

it('should return false if "message" is not a string', () => {
const mockResponse = {
status: 'error',
message: 123,
}

const result = validateFileUploadResponse(mockResponse)

expect(result).toBe(false)
})

it('should return false if status is "processing" and "processing_url" is undefined', () => {
const mockResponse = {
status: 'processing',
Expand All @@ -164,6 +191,18 @@ describe('validateFileUploadResponse', () => {
expect(result).toBe(false)
})

it('should return false if status is "processing" and "processing_url" is not a string', () => {
const mockResponse = {
status: 'processing',
message: 'message',
processing_url: 123,
}

const result = validateFileUploadResponse(mockResponse)

expect(result).toBe(false)
})

it('should return false if status is "success" and "nip94_event" is undefined', () => {
const mockResponse = {
status: 'success',
Expand Down

0 comments on commit cc02675

Please sign in to comment.