All files / ee/app/assets/javascripts/api subscriptions_api.js

52.38% Statements 11/21
0% Branches 0/2
20% Functions 1/5
52.38% Lines 11/21

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 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      13x 13x 13x   13x                               13x                           13x       13x       13x 1x 1x                       1x    
import { buildApiUrl } from '~/api/api_utils';
import axios from '~/lib/utils/axios_utils';
 
const SUBSCRIPTIONS_PATH = '/api/:version/subscriptions';
const EXTEND_REACTIVATE_TRIAL_PATH = '/-/trials/extend_reactivate';
const CREATE_HAND_RAISE_LEAD_PATH = '/-/trials/create_hand_raise_lead';
 
const TRIAL_EXTENSION_TYPE = Object.freeze({
  extended: 1,
  reactivated: 2,
});
 
export function createSubscription(groupId, customer, subscription) {
  const url = buildApiUrl(SUBSCRIPTIONS_PATH);
  const params = {
    selectedGroup: groupId,
    customer,
    subscription,
  };
 
  return axios.post(url, { params });
}
 
const updateTrial = async (namespaceId, trialExtensionType) => {
  if (!Object.values(TRIAL_EXTENSION_TYPE).includes(trialExtensionType)) {
    throw new TypeError('The "trialExtensionType" argument is invalid.');
  }
 
  const url = buildApiUrl(EXTEND_REACTIVATE_TRIAL_PATH);
  const params = {
    namespace_id: namespaceId,
    trial_extension_type: trialExtensionType,
  };
 
  return axios.put(url, params);
};
 
export const extendTrial = async (namespaceId) => {
  return updateTrial(namespaceId, TRIAL_EXTENSION_TYPE.extended);
};
 
export const reactivateTrial = async (namespaceId) => {
  return updateTrial(namespaceId, TRIAL_EXTENSION_TYPE.reactivated);
};
 
export const sendHandRaiseLead = async (params) => {
  const url = buildApiUrl(CREATE_HAND_RAISE_LEAD_PATH);
  const formParams = {
    namespace_id: params.namespaceId,
    company_name: params.companyName,
    company_size: params.companySize,
    first_name: params.firstName,
    last_name: params.lastName,
    phone_number: params.phoneNumber,
    country: params.country,
    state: params.state,
    comment: params.comment,
  };
 
  return axios.post(url, formParams);
};