All files / ee/app/assets/javascripts/admin/subscriptions/show/graphql utils.js

94.12% Statements 16/17
83.33% Branches 5/6
100% Functions 5/5
93.33% Lines 14/15

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      11x 10x   7x 3x 3x     3x 3x 3x 3x   3x 3x 3x 3x         3x    
import produce from 'immer';
import { subscriptionHistoryQueries, subscriptionQueries } from '../constants';
 
export const getLicenseFromData = ({ data } = {}) => data?.gitlabSubscriptionActivate?.license;
export const getErrorsAsData = ({ data } = {}) => data?.gitlabSubscriptionActivate?.errors || [];
 
export const updateSubscriptionAppCache = (cache, mutation) => {
  const license = getLicenseFromData(mutation);
  Iif (!license) {
    return;
  }
  const { query } = subscriptionQueries;
  const { query: historyQuery } = subscriptionHistoryQueries;
  const data = produce({}, (draftData) => {
    draftData.currentLicense = license;
  });
  cache.writeQuery({ query, data });
  const subscriptionsList = cache.readQuery({ query: historyQuery });
  const subscriptionListData = produce(subscriptionsList, (draftData) => {
    draftData.licenseHistoryEntries.nodes = [
      license,
      ...subscriptionsList.licenseHistoryEntries.nodes,
    ];
  });
  cache.writeQuery({ query: historyQuery, data: subscriptionListData });
};