diff options
Diffstat (limited to 'spec/frontend/packages_and_registries/settings/group/graphl/utils')
2 files changed, 76 insertions, 0 deletions
diff --git a/spec/frontend/packages_and_registries/settings/group/graphl/utils/cache_update_spec.js b/spec/frontend/packages_and_registries/settings/group/graphl/utils/cache_update_spec.js new file mode 100644 index 00000000000..e1a46f97318 --- /dev/null +++ b/spec/frontend/packages_and_registries/settings/group/graphl/utils/cache_update_spec.js @@ -0,0 +1,56 @@ +import expirationPolicyQuery from '~/packages_and_registries/settings/group/graphql/queries/get_group_packages_settings.query.graphql'; +import { updateGroupPackageSettings } from '~/packages_and_registries/settings/group/graphql/utils/cache_update'; + +describe('Package and Registries settings group cache updates', () => { + let client; + + const payload = { + data: { + updateNamespacePackageSettings: { + packageSettings: { + mavenDuplicatesAllowed: false, + mavenDuplicateExceptionRegex: 'latest[master]something', + }, + }, + }, + }; + + const cacheMock = { + group: { + packageSettings: { + mavenDuplicatesAllowed: true, + mavenDuplicateExceptionRegex: '', + }, + }, + }; + + const queryAndVariables = { + query: expirationPolicyQuery, + variables: { fullPath: 'foo' }, + }; + + beforeEach(() => { + client = { + readQuery: jest.fn().mockReturnValue(cacheMock), + writeQuery: jest.fn(), + }; + }); + describe('updateGroupPackageSettings', () => { + it('calls readQuery', () => { + updateGroupPackageSettings('foo')(client, payload); + expect(client.readQuery).toHaveBeenCalledWith(queryAndVariables); + }); + + it('writes the correct result in the cache', () => { + updateGroupPackageSettings('foo')(client, payload); + expect(client.writeQuery).toHaveBeenCalledWith({ + ...queryAndVariables, + data: { + group: { + ...payload.data.updateNamespacePackageSettings, + }, + }, + }); + }); + }); +}); diff --git a/spec/frontend/packages_and_registries/settings/group/graphl/utils/optimistic_responses_spec.js b/spec/frontend/packages_and_registries/settings/group/graphl/utils/optimistic_responses_spec.js new file mode 100644 index 00000000000..a3c53d5768a --- /dev/null +++ b/spec/frontend/packages_and_registries/settings/group/graphl/utils/optimistic_responses_spec.js @@ -0,0 +1,20 @@ +import { updateGroupPackagesSettingsOptimisticResponse } from '~/packages_and_registries/settings/group/graphql/utils/optimistic_responses'; + +describe('Optimistic responses', () => { + describe('updateGroupPackagesSettingsOptimisticResponse', () => { + it('returns the correct structure', () => { + expect(updateGroupPackagesSettingsOptimisticResponse({ foo: 'bar' })).toMatchInlineSnapshot(` + Object { + "__typename": "Mutation", + "updateNamespacePackageSettings": Object { + "__typename": "UpdateNamespacePackageSettingsPayload", + "errors": Array [], + "packageSettings": Object { + "foo": "bar", + }, + }, + } + `); + }); + }); +}); |