From dfd37b00867363cfb60b27f06d276608766c2bfe Mon Sep 17 00:00:00 2001 From: lenkan Date: Thu, 25 Jan 2024 15:42:37 +0100 Subject: [PATCH] add unit test for http status info --- test/app/clienting.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/app/clienting.test.ts b/test/app/clienting.test.ts index 1506b4c8..ede08d6f 100644 --- a/test/app/clienting.test.ts +++ b/test/app/clienting.test.ts @@ -377,4 +377,29 @@ describe('SignifyClient', () => { 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK' ); }); + + test('includes HTTP status info in error message', async () => { + await libsodium.ready; + const bran = '0123456789abcdefghijk'; + const client = new SignifyClient(url, bran, Tier.low, boot_url); + + await client.connect(); + + fetchMock.mockResolvedValue( + new Response('Error info', { + status: 400, + statusText: 'Bad Request', + }) + ); + + const error = await client + .fetch('/somepath', 'GET', undefined) + .catch((e) => e); + + assert(error instanceof Error); + assert.equal( + error.message, + 'HTTP GET /somepath - 400 Bad Request - Error info' + ); + }); });