From abe65935dee02f57cf8de37d56593452a85fe77d Mon Sep 17 00:00:00 2001 From: Sergey Konovalov Date: Tue, 22 Apr 2025 10:37:57 +0300 Subject: [PATCH] [tests] Add test for status!=200 --- tests/unit/request.tests.js | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/unit/request.tests.js b/tests/unit/request.tests.js index 355c728b..414c256a 100644 --- a/tests/unit/request.tests.js +++ b/tests/unit/request.tests.js @@ -103,6 +103,10 @@ describe('HTTP Request Unit Tests', () => { return; }); + app.use('/api/status/:code', (req, res) => { + res.status(Number(req.params.code)).send(); + }); + // Endpoint that redirects app.get('/api/redirect', (req, res) => { res.redirect('/api/data'); @@ -828,6 +832,25 @@ describe('HTTP Request Unit Tests', () => { // No need to clean up proxy server here anymore } }); + + test.concurrent('should return 205 status code for /status/205', async () => { + try { + await utils.downloadUrlPromise( + ctx, + `${BASE_URL}/api/status/205`, + { wholeCycle: '5s', connectionAndInactivity: '3s' }, + 1024 * 1024, + null, + false, + null, + null + ) + throw new Error('Expected an error to be thrown'); + } catch (error) { + expect(error.message).toContain('Error response:') + expect(error.statusCode).toBe(205); + } + }); }); test.concurrent('handles binary data correctly', async () => { @@ -1278,5 +1301,27 @@ describe('HTTP Request Unit Tests', () => { // No need to clean up proxy server here anymore } }); + + test.concurrent('should return 205 status code for /status/205', async () => { + try { + const postData = JSON.stringify({ test: 'data' }); + + const result = await utils.postRequestPromise( + ctx, + `${BASE_URL}/api/status/205`, + postData, + null, + postData.length, + { wholeCycle: '5s', connectionAndInactivity: '3s' }, + null, + false, + { 'Content-Type': 'application/json' } + ); + throw new Error('Expected an error to be thrown'); + } catch (error) { + expect(error.message).toContain('Error response:') + expect(error.statusCode).toBe(205); + } + }); }); }); \ No newline at end of file