1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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[main]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,
},
},
});
});
});
});
|