Skip to content

Commit

Permalink
Applications Password: Update client side to use the new '/setup' POS…
Browse files Browse the repository at this point in the history
…T endpoint (#97088)
  • Loading branch information
andregardi authored Dec 5, 2024
1 parent 391441c commit 6ddfd49
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 47 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useSiteIdParam } from 'calypso/landing/stepper/hooks/use-site-id-param'
import { useSiteSlugParam } from 'calypso/landing/stepper/hooks/use-site-slug-param';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import wp from 'calypso/lib/wp';
import { CredentialsFormData, ApplicationPasswordsInfo } from '../types';
import { CredentialsFormData, ApplicationPasswordsInfo, ApiError } from '../types';
import { useFormErrorMapping } from './use-form-error-mapping';
import { useRequestAutomatedMigration } from './use-request-automated-migration';

Expand All @@ -27,14 +27,19 @@ export const getApplicationPasswordsInfo = async (
from: string
): Promise< ApplicationPasswordsInfo | undefined > => {
try {
return await wp.req.get( {
path:
`/sites/${ siteId }/automated-migration/application-passwords/authorization-url?source=${ encodeURIComponent(
from
) }` + encodeURIComponent( from ),
return await wp.req.post( {
path: `/sites/${ siteId }/automated-migration/application-passwords/setup`,
apiNamespace: 'wpcom/v2',
body: {
source: from,
},
} );
} catch ( error ) {
if ( ( error as ApiError )?.code === 'failed_to_get_authorization_path' ) {
return {
application_passwords_enabled: false,
};
}
return undefined;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,9 @@ describe( 'SiteMigrationCredentials', () => {
render( { navigation: { submit } } );
await fillAddressField();
( wp.req.get as jest.Mock ).mockResolvedValueOnce( baseSiteInfo );
( wp.req.get as jest.Mock ).mockResolvedValueOnce( { application_passwords_enabled: false } );
( wp.req.post as jest.Mock ).mockRejectedValueOnce( {
code: 'failed_to_get_authorization_path',
} );
await userEvent.click( continueButton() );

expect( submit ).toHaveBeenCalledWith( {
Expand All @@ -659,7 +661,7 @@ describe( 'SiteMigrationCredentials', () => {
render( { navigation: { submit } } );
await fillAddressField();
( wp.req.get as jest.Mock ).mockResolvedValueOnce( baseSiteInfo );
( wp.req.get as jest.Mock ).mockResolvedValueOnce( {
( wp.req.post as jest.Mock ).mockResolvedValueOnce( {
application_passwords_enabled: true,
authorization_url: 'https://site-url.wordpress.com/wp-admin/authorize-application.php',
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ export interface MigrationError {

export interface ApplicationPasswordsInfo {
application_passwords_enabled: boolean;
authorization_url: string;
authorization_url?: string;
}

0 comments on commit 6ddfd49

Please sign in to comment.