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
57
58
59
60
61
62
63
64
65
66
67
|
import getJobArtifactsQuery from '~/artifacts/graphql/queries/get_job_artifacts.query.graphql';
import { removeArtifactFromStore } from '~/artifacts/graphql/cache_update';
describe('Artifact table cache updates', () => {
let store;
const cacheMock = {
project: {
jobs: {
nodes: [
{ artifacts: { nodes: [{ id: 'foo' }] } },
{ artifacts: { nodes: [{ id: 'bar' }] } },
],
},
},
};
const query = getJobArtifactsQuery;
const variables = { fullPath: 'path/to/project' };
beforeEach(() => {
store = {
readQuery: jest.fn().mockReturnValue(cacheMock),
writeQuery: jest.fn(),
};
});
describe('removeArtifactFromStore', () => {
it('calls readQuery', () => {
removeArtifactFromStore(store, 'foo', query, variables);
expect(store.readQuery).toHaveBeenCalledWith({ query, variables });
});
it('writes the correct result in the cache', () => {
removeArtifactFromStore(store, 'foo', query, variables);
expect(store.writeQuery).toHaveBeenCalledWith({
query,
variables,
data: {
project: {
jobs: {
nodes: [{ artifacts: { nodes: [] } }, { artifacts: { nodes: [{ id: 'bar' }] } }],
},
},
},
});
});
it('does not remove an unknown artifact', () => {
removeArtifactFromStore(store, 'baz', query, variables);
expect(store.writeQuery).toHaveBeenCalledWith({
query,
variables,
data: {
project: {
jobs: {
nodes: [
{ artifacts: { nodes: [{ id: 'foo' }] } },
{ artifacts: { nodes: [{ id: 'bar' }] } },
],
},
},
},
});
});
});
});
|