From 9f1aed32097bcfdaf379cd7d05c58ee0810bd584 Mon Sep 17 00:00:00 2001 From: devendra-bruno Date: Mon, 26 May 2025 16:42:18 +0530 Subject: [PATCH] Refactored fetch-gql-schema-handler.spec.js --- .../network/fetch-gql-schema-handler.spec.js | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/packages/bruno-electron/tests/network/fetch-gql-schema-handler.spec.js b/packages/bruno-electron/tests/network/fetch-gql-schema-handler.spec.js index 3104807e8..250237e32 100644 --- a/packages/bruno-electron/tests/network/fetch-gql-schema-handler.spec.js +++ b/packages/bruno-electron/tests/network/fetch-gql-schema-handler.spec.js @@ -1,3 +1,6 @@ +const prepareGqlIntrospectionRequest = require('../../src/ipc/network/prepare-gql-introspection-request'); +const { fetchGqlSchemaHandler } = require('../../src/ipc/network'); + // Mock the modules first, before requiring them jest.mock('../../src/utils/collection', () => { const original = jest.requireActual('../../src/utils/collection'); @@ -30,15 +33,15 @@ jest.mock('../../src/ipc/network/prepare-gql-introspection-request', () => { }); }); -const prepareGqlIntrospectionRequest = require('../../src/ipc/network/prepare-gql-introspection-request'); -const { fetchGqlSchemaHandler } = require('../../src/ipc/network'); -const { getTreePathFromCollectionToItem } = require('../../src/utils/collection'); - describe('fetchGqlSchemaHandler', () => { beforeEach(() => { jest.clearAllMocks(); }); + afterEach(() => { + jest.restoreAllMocks(); + }); + it('should receive combined variables from fetchGqlSchemaHandler', async () => { const endpoint = 'https://example.com/'; const environment = { @@ -71,9 +74,6 @@ describe('fetchGqlSchemaHandler', () => { } }; - // Set up empty tree path since we don't need it for this test - getTreePathFromCollectionToItem.mockReturnValue([]); - await fetchGqlSchemaHandler(null, endpoint, environment, request, collection); expect(prepareGqlIntrospectionRequest).toHaveBeenCalledWith( @@ -332,26 +332,6 @@ describe('fetchGqlSchemaHandler', () => { } }; - // Make sure our mock properly returns the folder variables with correct precedence - prepareGqlIntrospectionRequest.mockImplementationOnce((endpoint, resolvedVars, req, root) => { - // In a real scenario, the resolvedVars would include the folder variables - // Simulate the correct merge of variables - const combinedVars = { - ...resolvedVars, - SHARED_VAR: 'folder-value' // This simulates the correct precedence - }; - - return { - method: 'POST', - url: endpoint, - headers: {}, - data: JSON.stringify(combinedVars) - }; - }); - - // Set up empty tree path - getTreePathFromCollectionToItem.mockReturnValue([]); - await fetchGqlSchemaHandler(null, endpoint, environment, request, collection); expect(prepareGqlIntrospectionRequest).toHaveBeenCalledWith(