Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tax ID validation error messages to use terminology not specific to VAT/EU #10420

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import React from 'react';
* Internal dependencies
*/
import VatFormModal from '..';
import VatForm from '../../form';
import TaxDetailsForm from '../../form';

jest.mock( '../../form', () => jest.fn() );

describe( 'Tax details modal', () => {
beforeEach( () => {
jest.mocked( VatForm ).mockReturnValue( <p>VAT Form</p> );
jest.mocked( TaxDetailsForm ).mockReturnValue( <p>VAT Form</p> );
} );

it( 'should render when isModalOpen is true', () => {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ import apiFetch from '@wordpress/api-fetch';
import CollapsibleBody from 'wcpay/additional-methods-setup/wizard/collapsible-body';
import WizardTaskItem from 'wcpay/additional-methods-setup/wizard/task-item';
import WizardTaskContext from 'wcpay/additional-methods-setup/wizard/task/context';
import {
VatError,
VatFormOnCompleted,
VatSaveDetails,
VatSaveDetailsResult,
} from '../../types';
import { VatError, VatFormOnCompleted } from '../../types';

export const CompanyDataTask = ( {
onCompleted,
Expand Down Expand Up @@ -60,16 +55,17 @@ export const CompanyDataTask = ( {
try {
setLoading( true );

const details: VatSaveDetails = {
const details = {
name: companyName,
address: companyAddress,
vat_number: vatNumber ?? undefined,
};

if ( vatNumber !== null ) {
details.vat_number = vatNumber;
}

const savedDetails = await apiFetch< VatSaveDetailsResult >( {
const savedDetails = await apiFetch< {
vat_number: string | null;
name: string;
address: string;
} >( {
path: '/wc/v3/payments/vat',
method: 'POST',
data: details,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import apiFetch from '@wordpress/api-fetch';
import CollapsibleBody from 'wcpay/additional-methods-setup/wizard/collapsible-body';
import WizardTaskItem from 'wcpay/additional-methods-setup/wizard/task-item';
import WizardTaskContext from 'wcpay/additional-methods-setup/wizard/task/context';
import { VatError, VatFormOnCompleted, VatValidationResult } from '../../types';
import { VatError, VatFormOnCompleted } from '../../types';
import '../style.scss';

/**
Expand Down Expand Up @@ -123,13 +123,17 @@ export const VatNumberTask = ( {
if ( null !== normalizedVatNumber ) {
setLoading( true );

const validationResult = await apiFetch< VatValidationResult >(
{
path: `/wc/v3/payments/vat/${ encodeURI(
normalizedVatNumber
) }`,
}
);
const validationResult = await apiFetch< {
address: string | null;
country_code: string;
name: string | null;
valid: boolean;
vat_number: string;
} >( {
path: `/wc/v3/payments/vat/${ encodeURI(
normalizedVatNumber
) }`,
} );

setLoading( false );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import apiFetch from '@wordpress/api-fetch';
/**
* Internal dependencies
*/
import VatForm from '..';
import TaxDetailsForm from '..';

jest.mock( '@wordpress/api-fetch', () => jest.fn() );

Expand Down Expand Up @@ -67,7 +67,7 @@ describe( 'VAT form', () => {
accountStatus: { country: country },
};

render( <VatForm onCompleted={ mockOnCompleted } /> );
render( <TaxDetailsForm onCompleted={ mockOnCompleted } /> );

user.click(
screen.getByLabelText(
Expand Down Expand Up @@ -99,7 +99,7 @@ describe( 'VAT form', () => {
accountStatus: { country: 'GB' },
};

render( <VatForm onCompleted={ mockOnCompleted } /> );
render( <TaxDetailsForm onCompleted={ mockOnCompleted } /> );
} );

afterEach( () => {
Expand Down
2 changes: 1 addition & 1 deletion client/documents/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import './style.scss';
import DocumentsFilters from '../filters';
import Page from '../../components/page';
import { getDocumentUrl } from 'wcpay/utils';
import VatFormModal from 'wcpay/vat/form-modal';
import VatFormModal from '../form-modal';
import { formatDateTimeFromString } from 'wcpay/utils/date-time';
import { usePersistedColumnVisibility } from 'wcpay/hooks/use-persisted-table-column-visibility';

Expand Down
8 changes: 5 additions & 3 deletions client/documents/list/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import { useUserPreferences } from '@woocommerce/data';
import { DocumentsList } from '../';
import { useDocuments, useDocumentsSummary } from 'data/index';
import type { Document } from 'data/documents/hooks';
import VatForm from 'wcpay/vat/form';
import TaxDetailsForm from 'wcpay/documents/form';

jest.mock( 'data/index', () => ( {
useDocuments: jest.fn(),
useDocumentsSummary: jest.fn(),
} ) );

jest.mock( 'wcpay/vat/form', () => jest.fn() );
jest.mock( 'wcpay/documents/vat/form', () => jest.fn() );

jest.mock( '@woocommerce/data', () => {
const actualModule = jest.requireActual( '@woocommerce/data' );
Expand Down Expand Up @@ -207,7 +207,9 @@ describe( 'Document download button', () => {
documentsError: undefined,
} );

jest.mocked( VatForm ).mockImplementation( ( { onCompleted } ) => (
jest.mocked(
TaxDetailsForm
).mockImplementation( ( { onCompleted } ) => (
<button
onClick={ () =>
onCompleted(
Expand Down
10 changes: 10 additions & 0 deletions client/documents/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type VatFormOnCompleted = (
vatNumber: string | null,
companyName: string,
companyAddress: string
) => void;

export interface VatError {
code: string;
message: string;
}
30 changes: 0 additions & 30 deletions client/vat/types.d.ts

This file was deleted.

Loading