diff options
Diffstat (limited to 'spec/frontend/jira_import/utils/cache_update_spec.js')
-rw-r--r-- | spec/frontend/jira_import/utils/cache_update_spec.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/frontend/jira_import/utils/cache_update_spec.js b/spec/frontend/jira_import/utils/cache_update_spec.js new file mode 100644 index 00000000000..4812510f9b8 --- /dev/null +++ b/spec/frontend/jira_import/utils/cache_update_spec.js @@ -0,0 +1,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(); + }); + }); +}); |