department-of-veterans-affairs / va.gov-team

Public resources for building on and in support of VA.gov. Visit complete Knowledge Hub:
https://depo-platform-documentation.scrollhelp.site/index.html
283 stars 205 forks source link

When advancing from the download page, make a call to VA Notify endpoint #92783

Closed oddball-lindsay closed 1 month ago

oddball-lindsay commented 2 months ago

Background

When a user clicks "Continue" on the download page, we ned to make a request to VA Notify to send a confirmation email.

Related work:

Tasks

Acceptance Criteria

holdenhinkle commented 1 month ago

PR - https://github.com/department-of-veterans-affairs/vets-website/pull/32029

holdenhinkle commented 1 month ago

@cosu419

Hey Colin - I just added a bunch of unit tests to that PR - https://github.com/department-of-veterans-affairs/vets-website/pull/32029

I moved a bunch of functions from the component pages into the helpers.js file so they can easily be tested (and to dry some things up).

This spec file is failing locally - src/applications/representative-appoint/tests/components/ContactCard.unit.spec.jsx

I think it’s because of that strange issue with this import (we talked about it):

import { parsePhoneNumber } from '../utilities/helpers';

Would you mind handling this for me? I have one more silent failures thing to do, but I want to checkout for my vacation.

Yes, when I create this file - src/applications/representative-appoint/utilities/parsePhoneNumber.js

const parsePhoneNumber = phone => {
  if (!phone) {
    return { contact: null, extension: null };
  }
  let sanitizedNumber = phone
    .replace(/[()\s]/g, '') // remove parentheses
    .replace(/(?<=.)([+.*])/g, '-'); // replace .*+ symbols being used as dashes

  // return null for non-US country codes
  if (sanitizedNumber.match(/\+(\d+)[^\d1]/g)) {
    return { contact: null, extension: null };
  }

  // remove US country codes +1 or 1
  sanitizedNumber = sanitizedNumber.replace(/^(\+1|1)\s*/, '');

  // capture first 10 digits + ext if applicable
  const parserRegex = /^(\d{10})(\D*?(\d+))?/;
  const contact = sanitizedNumber.replace(/-/g, '').replace(parserRegex, '$1');
  const extension =
    sanitizedNumber
      .replace(/-/g, '')
      .replace(parserRegex, '$3')
      .replace(/\D/g, '') || null;

  const isValidContactNumberRegex = /^(?:[2-9]\d{2})[2-9]\d{2}\d{4}$/;

  if (isValidContactNumberRegex.test(contact)) {
    return { contact, extension };
  }
  return { contact: null, extension: null };
};

export default parsePhoneNumber;

And change the import in src/applications/representative-appoint/components/ContactCard.jsx to import parsePhoneNumber from '../utilities/parsePhoneNumber'; the tests pass. So weird.

Thanks!