@rocketmakers/api-swr
Version:
Rocketmakers front-end library for parsing a generated Typescript API client into a set of configurable React hooks for fetching and mutating data.
57 lines (56 loc) • 2.55 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("./config");
describe('combineConfigs', () => {
it('should return undefined if both queryConfig and globalFetchConfigs are not provided', () => {
const result = (0, config_1.combineConfigs)(undefined);
expect(result).toBeUndefined();
});
it('should return the queryConfig if no globalFetchConfigs are provided', () => {
const queryConfig = { fetchConfig: { key1: 'value1' } };
const result = (0, config_1.combineConfigs)(queryConfig);
expect(result).toEqual(queryConfig);
});
it('should merge queryConfig.fetchConfig and globalFetchConfigs', () => {
const queryConfig = { fetchConfig: { key1: 'value1' } };
const globalFetchConfig1 = { key2: 'value2' };
const globalFetchConfig2 = { key3: 'value3' };
const result = (0, config_1.combineConfigs)(queryConfig, globalFetchConfig1, globalFetchConfig2);
expect(result).toEqual({
fetchConfig: {
key1: 'value1',
key2: 'value2',
key3: 'value3',
},
});
});
it('should prioritize queryConfig.fetchConfig values over globalFetchConfigs', () => {
const queryConfig = { fetchConfig: { key1: 'queryValue', key2: 'queryValue2' } };
const globalFetchConfig1 = { key1: 'globalValue1' };
const globalFetchConfig2 = { key2: 'globalValue2', key3: 'globalValue3' };
const result = (0, config_1.combineConfigs)(queryConfig, globalFetchConfig1, globalFetchConfig2);
expect(result).toEqual({
fetchConfig: {
key1: 'queryValue',
key2: 'queryValue2',
key3: 'globalValue3',
},
});
});
it('should return the merged globalFetchConfigs if queryConfig is undefined', () => {
const globalFetchConfig1 = { key1: 'value1' };
const globalFetchConfig2 = { key2: 'value2' };
const result = (0, config_1.combineConfigs)(undefined, globalFetchConfig1, globalFetchConfig2);
expect(result).toEqual({
fetchConfig: {
key1: 'value1',
key2: 'value2',
},
});
});
it('should return the queryConfig if globalFetchConfigs are empty', () => {
const queryConfig = { fetchConfig: { key1: 'value1' } };
const result = (0, config_1.combineConfigs)(queryConfig);
expect(result).toEqual(queryConfig);
});
});