Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support ref in object root and not return 500 #41

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/configs/models/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ export class ConfigManager {
replacementValue = { ...prevValue, ...config.config };
}

if (path === '') {
Object.assign(obj, replacementValue);
return;
}

pointer.set(obj, path, replacementValue);
}
}
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/configs/configs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,23 @@ describe('config', function () {
expect(response.status).toBe(httpStatusCodes.CREATED);
expect(response).toSatisfyApiSpec();
});

it('should return 201 and create a config that is a root ref to another config', async function () {
const response = await requestSender.postConfig({
configName: 'config-root-ref',
schemaId: 'https://mapcolonies.com/simpleSchema/v1',
version: 1,
config: {
$ref: {
configName: 'config1',
version: 'latest',
},
},
});

expect(response.status).toBe(httpStatusCodes.CREATED);
expect(response).toSatisfyApiSpec();
});
});

describe('Bad Path', function () {
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/config/configManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ describe('ConfigManager', () => {
expect(result).toStrictEqual({ ...config, config: { avi: { test: 'test' } } });
});

it('should return the config with it being dereferenced when the ref is in the root of the object', async () => {
// @ts-expect-error ts wants this to be a predicate
configValidator.validateRef = jest.fn().mockResolvedValue(true);
const config = {
config: { $ref: { configName: 'refName', version: 1 } },
};
const refs: ConfigRefResponse[] = [{ config: { test: 'test' }, configName: 'refName', version: 1, isMaxVersion: false }];
configRepository.getConfigRecursive = jest.fn().mockResolvedValue([config, refs]);

const result = await configManager.getConfig('configName', 1, true);

expect(result).toStrictEqual({ ...config, config: { test: 'test' } });
});

it('should throw ConfigNotFoundError when the config does not exist', async () => {
configRepository.getConfig = jest.fn().mockResolvedValue(null);

Expand Down
Loading