All files / actions/transforms user.js

84% Statements 21/25
50% Branches 12/24
66.66% Functions 4/6
84% Lines 21/25

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 63 64 65 66 67 68 69 70 71 72 73 74 75 761x 2x 2x     2x 2x                       2x     1x                         1x 1x 1x         1x     1x 1x 1x                                 1x 1x 1x 1x 1x 1x     1x        
const userTransform = (data) => {
  const user = data.user;
  Iif (!user) {
    return {};
  }
  const userRef = user.id || user.userRef || data.userRef;
  const userProfile = {
    userRef,
    email: user.email,
    firstName: user.first_name || user.firstName,
    lastName: user.last_name || user.lastName,
    prefix: user.prefix,
    isGuest: user.guest,
    phoneNumber: user.phone_number || user.phoneNumber,
    lastLogin: user.last_login || user.lastLogin,
    dob: user.birthday || user.dob,
    emailOptIn: user.aux_data?.thirstieaccess_email_opt_in || false
  };
  return userProfile;
};
 
const paymentMethodTransform = (data) => {
  const billing = data.billing_address;
  return {
    cardType: data.card_type,
    expirationMonth: data.expiration_month,
    expirationYear: data.expiration_year,
    lastFour: data.last_four,
    paymentType: data.payment_type,
    billingZipcode: billing.zipcode,
    fingerprint: data.payment_method_fingerprint
  };
};
 
const walletTransform = (data) => {
  const { items } = data.items;
  const transformedItems = (items && items.length > 0)
    ? items.map((pmtItem) => {
      return paymentMethodTransform(pmtItem);
    })
    : [];
  return { paymentMethods: transformedItems };
};
 
const userAddressTransform = (data, label = null) => {
  const { city, country, latitude, longitude, state, zipcode, company } = data;
  return {
    label,
    city,
    company,
    country,
    latitude,
    longitude,
    state,
    zipcode,
    street1: data.street_1,
    street2: data.street_2,
    street3: data.street_3,
    deliveryInstructions: data.delivery_instructions,
    isDefault: data.is_default
  };
};
 
const addressBookTransform = (data) => {
  const { addresses } = data;
  const userAddressBook = [];
  for (const addressLabel in addresses) {
    Eif (Object.hasOwn(addresses, addressLabel)) {
      userAddressBook.push(userAddressTransform(addresses[addressLabel], addressLabel));
    }
  }
  return { userAddressBook };
};
 
export { userTransform, paymentMethodTransform, walletTransform, addressBookTransform };