From cc0267582ad84603f7cfdbbb2922b72278b89b3d Mon Sep 17 00:00:00 2001 From: Sepehr Safari Date: Wed, 24 Jan 2024 14:17:32 +0330 Subject: [PATCH] add more test cases to reach 90 percent coverage --- nip96.test.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/nip96.test.ts b/nip96.test.ts index 60ea31a..7830abd 100644 --- a/nip96.test.ts +++ b/nip96.test.ts @@ -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 @@ -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', @@ -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',