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
|
import { addInProgressImportToStore } from '~/jira_import/utils/cache_update';
import { IMPORT_STATE } from '~/jira_import/utils/jira_import_utils';
import {
fullPath,
queryDetails,
jiraImportDetailsQueryResponse,
jiraImportMutationResponse,
} from '../mock_data';
describe('addInProgressImportToStore', () => {
const store = {
readQuery: jest.fn(() => jiraImportDetailsQueryResponse),
writeQuery: jest.fn(),
};
describe('when updating the cache', () => {
beforeEach(() => {
addInProgressImportToStore(store, jiraImportMutationResponse.jiraImportStart, fullPath);
});
it('reads the cache with the correct query', () => {
expect(store.readQuery).toHaveBeenCalledWith(queryDetails);
});
it('writes to the cache with the expected arguments', () => {
const expected = {
...queryDetails,
data: {
project: {
...jiraImportDetailsQueryResponse.project,
jiraImportStatus: IMPORT_STATE.SCHEDULED,
jiraImports: {
...jiraImportDetailsQueryResponse.project.jiraImports,
nodes: jiraImportDetailsQueryResponse.project.jiraImports.nodes.concat(
jiraImportMutationResponse.jiraImportStart.jiraImport,
),
},
},
},
};
expect(store.writeQuery).toHaveBeenCalledWith(expected);
});
});
describe('when there are errors', () => {
beforeEach(() => {
const jiraImportStart = {
...jiraImportMutationResponse.jiraImportStart,
errors: ['There was an error'],
};
addInProgressImportToStore(store, jiraImportStart, fullPath);
});
it('does not read from the store', () => {
expect(store.readQuery).not.toHaveBeenCalled();
});
it('does not write to the store', () => {
expect(store.writeQuery).not.toHaveBeenCalled();
});
});
});
|