All files / app/assets/javascripts/jira_import/utils cache_update.js

100% Statements 8/8
100% Branches 2/2
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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        3x 4x 2x     2x             2x       2x     2x 2x                      
import produce from 'immer';
import getJiraImportDetailsQuery from '../queries/get_jira_import_details.query.graphql';
import { IMPORT_STATE } from './jira_import_utils';
 
export const addInProgressImportToStore = (store, jiraImportStart, fullPath) => {
  if (jiraImportStart.errors.length) {
    return;
  }
 
  const queryDetails = {
    query: getJiraImportDetailsQuery,
    variables: {
      fullPath,
    },
  };
 
  const sourceData = store.readQuery({
    ...queryDetails,
  });
 
  store.writeQuery({
    ...queryDetails,
    data: produce(sourceData, (draftData) => {
      draftData.project.jiraImportStatus = IMPORT_STATE.SCHEDULED;
      draftData.project.jiraImports.nodes = [
        ...sourceData.project.jiraImports.nodes,
        jiraImportStart.jiraImport,
      ];
    }),
  });
};
 
export default {
  addInProgressImportToStore,
};