Refactored fetch-gql-schema-handler.spec.js

This commit is contained in:
devendra-bruno
2025-05-26 16:42:18 +05:30
parent ce1110bdd4
commit 9f1aed3209

View File

@@ -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(