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

Site Migration: Remove migration instruction i2 flag code #90663

Merged
merged 1 commit into from
May 13, 2024
Merged
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
65 changes: 4 additions & 61 deletions client/landing/stepper/declarative-flow/site-migration-flow.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { isEnabled } from '@automattic/calypso-config';
import { PLAN_MIGRATION_TRIAL_MONTHLY } from '@automattic/calypso-products';
import { useSelect } from '@wordpress/data';
import { useEffect } from 'react';
import { HOSTING_INTENT_MIGRATE } from 'calypso/data/hosting/use-add-hosting-trial-mutation';
import { useIsSiteOwner } from 'calypso/landing/stepper/hooks/use-is-site-owner';
import { useQuery } from 'calypso/landing/stepper/hooks/use-query';
import { addQueryArgs } from 'calypso/lib/url';
import wpcom from 'calypso/lib/wp';
import { useSiteData } from '../hooks/use-site-data';
import { useSiteSlugParam } from '../hooks/use-site-slug-param';
import { useStartUrl } from '../hooks/use-start-url';
Expand All @@ -29,12 +27,8 @@ const siteMigration: Flow = {
return [
STEPS.SITE_MIGRATION_IDENTIFY,
STEPS.SITE_MIGRATION_IMPORT_OR_MIGRATE,
STEPS.BUNDLE_TRANSFER,
STEPS.SITE_MIGRATION_PLUGIN_INSTALL,
STEPS.PROCESSING,
STEPS.SITE_MIGRATION_UPGRADE_PLAN,
STEPS.SITE_MIGRATION_ASSIGN_TRIAL_PLAN,
STEPS.SITE_MIGRATION_INSTRUCTIONS,
STEPS.SITE_MIGRATION_INSTRUCTIONS_I2,
STEPS.ERROR,
STEPS.SITE_MIGRATION_ASSISTED_MIGRATION,
Expand Down Expand Up @@ -98,28 +92,12 @@ const siteMigration: Flow = {
window.location.assign( to );
};

const saveSiteSettings = async ( siteSlug: string, settings: Record< string, unknown > ) => {
return wpcom.req.post(
`/sites/${ siteSlug }/settings`,
{
apiVersion: '1.4',
},
{
...settings,
}
);
};

// TODO - We may need to add `...params: string[]` back once we start adding more steps.
async function submit( providedDependencies: ProvidedDependencies = {} ) {
recordSubmitStep( providedDependencies, intent, flowName, currentStep );
const siteSlug = ( providedDependencies?.siteSlug as string ) || siteSlugParam || '';
const siteId = getSiteIdBySlug( siteSlug );

const transferStepSlug = isEnabled( 'migration-flow/remove-processing-step' )
? STEPS.SITE_MIGRATION_INSTRUCTIONS_I2.slug
: STEPS.BUNDLE_TRANSFER.slug;

switch ( currentStep ) {
case STEPS.SITE_MIGRATION_IDENTIFY.slug: {
const { from, platform, action } = providedDependencies as {
Expand Down Expand Up @@ -167,56 +145,25 @@ const siteMigration: Flow = {

// Take the user to the upgrade plan step.
if ( providedDependencies?.destination === 'upgrade' ) {
// TODO - Once the upgrade plan step is available, we'll want to change this to use the slug constant.
return navigate( 'site-migration-upgrade-plan', {
return navigate( STEPS.SITE_MIGRATION_UPGRADE_PLAN.slug, {
siteId,
siteSlug,
} );
}

// Continue with the migration flow.
return navigate( transferStepSlug, {
return navigate( STEPS.SITE_MIGRATION_INSTRUCTIONS_I2.slug, {
siteId,
siteSlug,
} );
}

case STEPS.BUNDLE_TRANSFER.slug: {
return navigate( STEPS.PROCESSING.slug, { bundleProcessing: true } );
}

case STEPS.SITE_MIGRATION_PLUGIN_INSTALL.slug: {
return navigate( STEPS.PROCESSING.slug, { pluginInstall: true } );
}

case STEPS.PROCESSING.slug: {
// Any process errors go to the error step.
if ( providedDependencies?.error ) {
return navigate( STEPS.ERROR.slug );
}

// If the plugin was installed successfully, go to the migration instructions.
if ( providedDependencies?.pluginInstall ) {
if ( siteSlug ) {
// Remove the in_site_migration_flow option at the end of the flow.
await saveSiteSettings( siteSlug, {
in_site_migration_flow: '',
} );
}

return navigate( STEPS.SITE_MIGRATION_INSTRUCTIONS.slug );
}

// Otherwise processing has finished from the BundleTransfer step and we need to install the plugin.
return navigate( STEPS.SITE_MIGRATION_PLUGIN_INSTALL.slug );
}

case STEPS.SITE_MIGRATION_ASSIGN_TRIAL_PLAN.slug: {
if ( providedDependencies?.error ) {
return navigate( STEPS.ERROR.slug );
}

return navigate( transferStepSlug, {
return navigate( STEPS.SITE_MIGRATION_INSTRUCTIONS_I2.slug, {
siteId,
siteSlug,
} );
Expand All @@ -226,7 +173,7 @@ const siteMigration: Flow = {
if ( providedDependencies?.goToCheckout ) {
const redirectAfterCheckout = providedDependencies?.userAcceptedDeal
? STEPS.SITE_MIGRATION_ASSISTED_MIGRATION.slug
: transferStepSlug;
: STEPS.SITE_MIGRATION_INSTRUCTIONS_I2.slug;

const destination = addQueryArgs(
{
Expand Down Expand Up @@ -258,10 +205,6 @@ const siteMigration: Flow = {
return;
}
}

case STEPS.SITE_MIGRATION_INSTRUCTIONS.slug: {
return exitFlow( `/home/${ siteSlug }` );
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* @jest-environment jsdom
*/
import config from '@automattic/calypso-config';
import { PLAN_MIGRATION_TRIAL_MONTHLY } from '@automattic/calypso-products';
import { isCurrentUserLoggedIn } from '@automattic/data-stores/src/user/selectors';
import { waitFor } from '@testing-library/react';
Expand All @@ -15,7 +14,6 @@ import siteMigrationFlow from '../site-migration-flow';
import { getAssertionConditionResult, getFlowLocation, renderFlow } from './helpers';
// we need to save the original object for later to not affect tests from other files
const originalLocation = window.location;
const originalIsEnabled = config.isEnabled;

jest.mock( '../../utils/checkout' );
jest.mock( '@automattic/data-stores/src/user/selectors' );
Expand Down Expand Up @@ -43,11 +41,6 @@ describe( 'Site Migration Flow', () => {
const testSettingsEndpoint = '/rest/v1.4/sites/example.wordpress.com/settings';
nock( apiBaseUrl ).get( testSettingsEndpoint ).reply( 200, {} );
nock( apiBaseUrl ).post( testSettingsEndpoint ).reply( 200, {} );
jest
.spyOn( config, 'isEnabled' )
.mockImplementation( ( key ) =>
key === 'migration-flow/remove-processing-step' ? false : originalIsEnabled( key )
);
} );

afterEach( () => {
Expand Down Expand Up @@ -172,31 +165,9 @@ describe( 'Site Migration Flow', () => {
} );
} );

it( 'migrate redirects from the import-from page to bundleTransfer step if new instructions not enabled', () => {
const { runUseStepNavigationSubmit } = renderFlow( siteMigrationFlow );

runUseStepNavigationSubmit( {
currentStep: STEPS.BUNDLE_TRANSFER.slug,
dependencies: {
destination: 'migrate',
},
} );

expect( getFlowLocation() ).toEqual( {
path: `/${ STEPS.PROCESSING.slug }`,
state: {
bundleProcessing: true,
},
} );
} );

it( 'migrate redirects from the import-from page to new instructions if flag enabled', () => {
const { runUseStepNavigationSubmit } = renderFlow( siteMigrationFlow );

( config.isEnabled as jest.Mock ).mockImplementation( ( key: string ) =>
key === 'migration-flow/remove-processing-step' ? true : originalIsEnabled( key )
);

runUseStepNavigationSubmit( {
currentStep: STEPS.SITE_MIGRATION_IMPORT_OR_MIGRATE.slug,
} );
Expand Down Expand Up @@ -224,7 +195,7 @@ describe( 'Site Migration Flow', () => {
} );

expect( goToCheckout ).toHaveBeenCalledWith( {
destination: `/setup/site-migration/${ STEPS.BUNDLE_TRANSFER.slug }?siteSlug=example.wordpress.com&from=https%3A%2F%2Fsite-to-be-migrated.com`,
destination: `/setup/site-migration/${ STEPS.SITE_MIGRATION_INSTRUCTIONS_I2.slug }?siteSlug=example.wordpress.com&from=https%3A%2F%2Fsite-to-be-migrated.com`,
extraQueryParams: { hosting_intent: HOSTING_INTENT_MIGRATE },
flowName: 'site-migration',
siteSlug: 'example.wordpress.com',
Expand Down Expand Up @@ -258,7 +229,7 @@ describe( 'Site Migration Flow', () => {
} );

expect( getFlowLocation() ).toEqual( {
path: '/bundleTransfer',
path: `/${ STEPS.SITE_MIGRATION_INSTRUCTIONS_I2.slug }`,
state: { siteSlug: 'example.wordpress.com' },
} );
} );
Expand Down
1 change: 0 additions & 1 deletion config/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
"me/account-close": true,
"me/account/color-scheme-picker": true,
"me/vat-details": true,
"migration-flow/remove-processing-step": true,
"my-sites/add-ons": true,
"network-connection": true,
"oauth": false,
Expand Down
1 change: 0 additions & 1 deletion config/horizon.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"marketplace-test": false,
"me/account/color-scheme-picker": true,
"me/vat-details": true,
"migration-flow/remove-processing-step": true,
"my-sites/add-ons": true,
"network-connection": true,
"onboarding/design-choices": true,
Expand Down
1 change: 0 additions & 1 deletion config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
"me/account-close": true,
"me/account/color-scheme-picker": true,
"me/vat-details": true,
"migration-flow/remove-processing-step": true,
"my-sites/add-ons": true,
"onboarding/design-choices": true,
"onboarding/import": true,
Expand Down
1 change: 0 additions & 1 deletion config/stage.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
"me/account-close": true,
"me/account/color-scheme-picker": true,
"me/vat-details": true,
"migration-flow/remove-processing-step": true,
"my-sites/add-ons": true,
"onboarding/design-choices": true,
"onboarding/import": true,
Expand Down
1 change: 0 additions & 1 deletion config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"marketplace-personal-premium": false,
"me/account-close": true,
"me/vat-details": true,
"migration-flow/remove-processing-step": true,
"my-sites/add-ons": true,
"network-connection": true,
"p2-enabled": false,
Expand Down
1 change: 0 additions & 1 deletion config/wpcalypso.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"me/account-close": true,
"me/account/color-scheme-picker": true,
"me/vat-details": true,
"migration-flow/remove-processing-step": true,
"my-sites/add-ons": true,
"network-connection": true,
"onboarding/design-choices": true,
Expand Down
Loading