From abfe58551fb7c0f9bc6434f2683a7c3dc6b3b7a0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 7 Jul 2026 16:23:29 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20[testing=20improvement]=20Add=20?= =?UTF-8?q?missing=20error=20path=20tests=20for=20products=20list\n\n-=20A?= =?UTF-8?q?dd=20missing=20error=20path=20tests=20for=20various=20list=20op?= =?UTF-8?q?erations=20in=20`lib/commands/products-actions.js`=20where=20`h?= =?UTF-8?q?andleError`=20is=20called.\n-=20Ensure=20`expect(console.error)?= =?UTF-8?q?.toHaveBeenCalled()`=20is=20used=20instead=20of=20the=20flawed?= =?UTF-8?q?=20`expect(jest.spyOn(console,=20'error')).toBeDefined()`=20ass?= =?UTF-8?q?ertion.\n-=20Add=20a=20missing=20test=20case=20for=20`formatOut?= =?UTF-8?q?put`=20early=20exit=20in=20`listProductLinkTypesAction`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: cmuench <211294+cmuench@users.noreply.github.com> --- tests/products.test.js | 45 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/tests/products.test.js b/tests/products.test.js index 96aecfa..b621a3f 100644 --- a/tests/products.test.js +++ b/tests/products.test.js @@ -197,7 +197,7 @@ describe('Product Commands', () => { await program.parseAsync(['node', 'test', 'product', 'list']); - expect(jest.spyOn(console, 'error')).toBeDefined(); + expect(console.error).toHaveBeenCalled(); }); it('show: should output json format', async () => { @@ -281,7 +281,7 @@ describe('Product Commands', () => { await program.parseAsync(['node', 'test', 'product', 'show', 'NOTEXIST']); - expect(jest.spyOn(console, 'error')).toBeDefined(); + expect(console.error).toHaveBeenCalled(); }); it('media list: should show "no media" message when empty', async () => { @@ -348,7 +348,7 @@ describe('Product Commands', () => { await program.parseAsync(['node', 'test', 'product', 'attribute', 'show', 'nonexistent']); - expect(jest.spyOn(console, 'error')).toBeDefined(); + expect(console.error).toHaveBeenCalled(); }); it('attribute show: should display attribute without options', async () => { @@ -387,4 +387,43 @@ describe('Product Commands', () => { expect(mockClient.get).toHaveBeenCalledWith('V1/products/attributes/types'); expect(consoleLogSpy).toHaveBeenCalledWith('MOCK_TABLE'); }); + + it('media list: should handle errors', async () => { + mockClient.get.mockRejectedValue(new Error('Network Error')); + await program.parseAsync(['node', 'test', 'product', 'media', 'list', 'TS123']); + expect(console.error).toHaveBeenCalled(); + }); + + it('type list: should handle errors', async () => { + mockClient.get.mockRejectedValue(new Error('Network Error')); + await program.parseAsync(['node', 'test', 'product', 'type', 'list']); + expect(console.error).toHaveBeenCalled(); + }); + + it('attribute list: should handle errors', async () => { + mockClient.get.mockRejectedValue(new Error('Network Error')); + await program.parseAsync(['node', 'test', 'product', 'attribute', 'list']); + expect(console.error).toHaveBeenCalled(); + }); + + it('attribute type list: should handle errors', async () => { + mockClient.get.mockRejectedValue(new Error('Network Error')); + await program.parseAsync(['node', 'test', 'product', 'attribute', 'type', 'list']); + expect(console.error).toHaveBeenCalled(); + }); + + it('link-type list: should output json format via formatOutput', async () => { + mockClient.get.mockResolvedValue([ + { code: 1, name: 'related' } + ]); + await program.parseAsync(['node', 'test', 'product', 'link-type', 'list', '--format', 'json']); + expect(mockClient.get).toHaveBeenCalled(); + expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('"name"')); + }); + + it('link-type list: should handle errors', async () => { + mockClient.get.mockRejectedValue(new Error('Network Error')); + await program.parseAsync(['node', 'test', 'product', 'link-type', 'list']); + expect(console.error).toHaveBeenCalled(); + }); });