mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-22 04:05:42 +00:00
Refactored fetch-gql-schema-handler.spec.js
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user