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

Kickoff MC and Ads account creation #2618

Conversation

ankitrox
Copy link
Collaborator

@ankitrox ankitrox commented Sep 18, 2024

Changes proposed in this Pull Request:

Closes #2567 .

Replace this with a good description of your changes & reasoning.

Screenshots:

Detailed test instructions

  1. Create a new site and setup the GLA plugin (Make sure you are testing on the feature branch if this is not merged).

  2. Go to Marketing > Google for Woocommerce and start onboarding process.

  3. Connect to the fresh Google account. This account should not have any existing merchant center accounts or Google ads account.

  4. As soon as user sign-in flow is completed and user lands back to onboarding screen, there should be the card status changed to the one which should read You don’t have Merchant Center nor Google Ads accounts, so we’re creating them for you. as per the Figma designs.

  5. Once Merchant Center account and Ads account is created, card state will be changed this. Which will display Merchant Center ID and Google Ads ID (for 1-2 seconds ads ID may be seen as zero because ads request gets resolved later).

  6. Note that there would be some error notices popping up regarding ads account connection and ads connection status, but this can be ignored for this issue and will be handled in Onboarding: Claim New Ads Accounts in the Google Combo Accounts Card #2582

Use custom plugin to test with existing account.

As it is very inconvenient to test with the fresh account everytime; especially in the scenario where Google may not allow more accounts to be created and asks for new mobile number (where we are out of phone numbers). Following method can help us to test with existing Google account.

  1. Following plugin mimics the scenario such that for the first request to MC or Ads, it mocks the request such that there are no MC and Ads account.
<?php
/**
 * Plugin name: 2567 Test
 * Description: A plugin to provide REST API helper utilities.
 */

add_filter('rest_pre_dispatch', function($result, $server, $request) {
    $method = $request->get_method();
    $route  = $request->get_route();

    if ( 'POST' === $method ) {
        switch ($route) {
            case '/wc/gla/ads/accounts':
                $result = [
                    'message' => 'Account must be accepted before completing setup.',
                    'has_access' => false,
                    'step' => 'account_access',
                    'invite_link' => 'https://ads.google.com/nav/startacceptinvite?ivid=202079690&ocid=6741519560&eivid=ARZPQJ79CnAPjRUtJ1N2kGxycD2IjlRsgCNVRdiDRtvIyQRvkslrzx0',
                ];
                break;
            case '/wc/gla/mc/accounts':
                $result = [
                    'id'         => 5432178,
                    'name'       => null,
                    'subaccount' => null,
                    'domain'     => null,
                ];
                break;
        }
    }

    return $result;
}, 10, 3);

/**
 * Filter the response before it is returned to the client.
 * 
 * @param WP_HTTP_Response $response Result to send to the client. Usually a WP_REST_Response.
 * @param WP_REST_Server $server Server instance.
 * @param WP_REST_Request $request Request used to generate the response.
 */
add_filter('rest_post_dispatch', function($response, $server, $request) {

    // Mock accounts endpoints.
    if( '/wc/gla/ads/accounts' === $request->get_route() ) {
        $method = $request->get_method();

        if ( 'POST' === $method ) {
            $response->set_status( 428 );
        }

        if ( 'GET' === $method ) {
            $ads_request_number = get_option('gla_ads_account_request_number', 0);
            update_option('gla_ads_account_request_number', $ads_request_number + 1);

            $data = [];

            if ( $ads_request_number > 0 ) {
               $data[] = [
                'id'   => 78787878,
                'name' => 'gla.instawp.xyz',
               ];
            }

            $response->set_data( $data );
        }
    }

    if( '/wc/gla/mc/accounts' === $request->get_route() ) {
        $method = $request->get_method();

        if ( 'GET' === $method ) {
            $mc_request_number = get_option('gla_mc_account_request_number', 0);
            update_option('gla_mc_account_request_number', $mc_request_number + 1);

            $data = [];
            if ($mc_request_number > 0) {
                $data[] = [
                    'id'         => 5432178,
                    'name'       => null,
                    'subaccount' => null,
                    'domain'     => null,
                ];
            }

            $response->set_data( $data );
        }
    }

    // Mock connections endpoints.
    if( '/wc/gla/ads/connection' === $request->get_route() ) {
        $method = $request->get_method();
        if ( 'GET' === $method ) {
            $ads_request_number = get_option('gla_ads_connection_request_number', 0);
            update_option('gla_ads_connection_request_number', $ads_request_number + 1);

            $data = [
                'id'         => 0,
                'currency'   => 'USD',
                'status'     => 'disconnected',
                'symbol'     => '$',
            ];

            if ($ads_request_number > 0) {
                $data['id']     = 78787878;
                $data['status'] = 'incomplete';
                $data['step']   = 'account_access';
            }

            $response->set_data( $data );
        }
    }

    if( '/wc/gla/mc/connection' === $request->get_route() ) {
        $method = $request->get_method();
        if ( 'GET' === $method ) {
            $ads_request_number = get_option('gla_mc_connection_request_number', 0);
            update_option('gla_mc_connection_request_number', $ads_request_number + 1);

            $data = [
                'id'         => 0,
                'name'       => null,
                'subaccount' => null,
                'domain'     => null,
            ];

            if ($ads_request_number > 0) {
                $data['id']     = 5432178;
                $data['status'] = 'incomplete';
                $data['step']   = 'claim';
            }

            $response->set_data( $data );
        }
    }

    return $response;
}, 10, 3);

add_filter( 'woocommerce_gla_ads_billing_setup_status', function( $status ) {
	return 'approved';
} );
  1. Once the test is run, you will need to clear following options from *_options table.
  • gla_ads_account_request_number
  • gla_mc_account_request_number
  • gla_ads_connection_request_number
  • gla_mc_connection_request_number

These options can also be cleared using following npm command in local setup.

npm run wp-env run cli wp option delete gla_ads_account_request_number && npm run wp-env run cli wp option delete gla_mc_account_request_number && npm run wp-env run cli wp option delete gla_ads_connection_request_number && npm run wp-env run cli wp option delete gla_mc_connection_request_number
  1. Once above command ran successfully, the test can again be performed with given steps.

Additional details:

Changelog entry

Add - During onboarding, automatically create Google Merchant Center or Google Ads accounts when the connected Google account doesn't have a respective existing one.

@ankitrox ankitrox changed the base branch from develop to feature/2458-streamline-onboarding September 18, 2024 15:27
@ankitrox ankitrox changed the base branch from feature/2458-streamline-onboarding to feature/2458-consolidate-google-account-cards September 18, 2024 15:29
Copy link

codecov bot commented Sep 18, 2024

Codecov Report

Attention: Patch coverage is 80.64516% with 12 lines in your changes missing coverage. Please review.

Please upload report for BASE (feature/2509-consolidate-google-account-cards@7d31e5c). Learn more about missing BASE report.
Report is 94 commits behind head on feature/2509-consolidate-google-account-cards.

Files with missing lines Patch % Lines
js/src/hooks/useGoogleMCAccount.js 12.5% 6 Missing and 1 partial ⚠️
js/src/hooks/useAutoCreateAdsMCAccounts.js 93.8% 3 Missing ⚠️
js/src/hooks/useExistingGoogleAdsAccounts.js 0.0% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                               Coverage Diff                               @@
##             feature/2509-consolidate-google-account-cards   #2618   +/-   ##
===============================================================================
  Coverage                                                 ?   62.7%           
===============================================================================
  Files                                                    ?     324           
  Lines                                                    ?    5153           
  Branches                                                 ?    1259           
===============================================================================
  Hits                                                     ?    3232           
  Misses                                                   ?    1744           
  Partials                                                 ?     177           
Flag Coverage Δ
js-unit-tests 62.7% <80.6%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../components/google-combo-account-card/constants.js 100.0% <100.0%> (ø)
js/src/constants.js 100.0% <100.0%> (ø)
js/src/hooks/useCreateMCAccount.js 6.7% <ø> (ø)
js/src/hooks/useExistingGoogleAdsAccounts.js 16.7% <0.0%> (ø)
js/src/hooks/useAutoCreateAdsMCAccounts.js 93.8% <93.8%> (ø)
js/src/hooks/useGoogleMCAccount.js 13.3% <12.5%> (ø)

@ankitrox ankitrox changed the base branch from feature/2458-consolidate-google-account-cards to feature/2590-consolidate-google-account-cards September 18, 2024 15:40
Copy link
Collaborator

@asvinb asvinb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ankitrox I left a few comments on the PR. Can you kindly check them out please? Also most importantly I think we should implement the useCreateAccounts hook in such a way that when we need to implement the other features, we can easily tweak/update it. Right now the hook is too rigid 😁 I suggest the following changes:

  • The hook returns additional properties:
    • description: for the You don’t have Merchant Center nor Google Ads accounts, so we’re creating them for you. text
    • helperText: for the Merchant Center is required to sync products so they show on Google. Google Ads is required to set up conversion measurement for your store.
      • The text above will be set when we need to create both accounts (which is the case for this ticket).
    • adsAccountCreated: boolean to indicate that an ads account has been created
    • mcAccountCreated : boolean to indicate that MC account has been created
      • From the 2 properties above, we can deduce accountsCreated.
    • isCreatingAdsAccount: boolean to indicate that ads account creation is in progress.
    • isCreatingMCAccount: boolean to indicate that MC account creation is in progress.
      • From the 2 properties above, we can deduce isCreatingAccounts

js/src/hooks/useCreateAccounts.js Outdated Show resolved Hide resolved
js/src/hooks/useCreateAccounts.js Outdated Show resolved Hide resolved
js/src/hooks/useCreateAccounts.js Outdated Show resolved Hide resolved
js/src/hooks/useCreateAccounts.js Outdated Show resolved Hide resolved
js/src/hooks/useCreateAccounts.js Outdated Show resolved Hide resolved
js/src/hooks/useCreateAccounts.js Outdated Show resolved Hide resolved
js/src/hooks/useCreateAccounts.js Outdated Show resolved Hide resolved
@joemcgill joemcgill changed the base branch from feature/2590-consolidate-google-account-cards to feature/2509-consolidate-google-account-cards September 30, 2024 19:34
@joemcgill
Copy link
Collaborator

We had a typo in the feature branch for #2509. I've updated the branch and am changing the base of this PR to merge into the correct branch now.

Copy link
Collaborator

@asvinb asvinb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ankitrox I left some comments. Can you kindly check them out and let me know what you think please?
Thanks!

Copy link
Collaborator

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've given this a look and given a bit of feedback inline. I do think it's important to resolve the hook dependencies conversation here before sending this to QA. There also seems to be some ESLint and Unit test issues to resolve before this is ready.

Copy link
Collaborator

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice updates! Some small suggestions about the new useGoogleMCAccountReady() hook inline

js/src/hooks/useGoogleMCAccountReady.js Outdated Show resolved Hide resolved
js/src/setup-mc/setup-stepper/setup-accounts/index.js Outdated Show resolved Hide resolved
joemcgill and others added 3 commits October 23, 2024 14:34
This removes the unnecessary `SetupAdsAccountPage` from the E2E tests, since they were only being used for mocking and both `SetupAdsAccountPage` and `SetUpAccountsPage` extend the same mocking library.
Copy link
Collaborator

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking much better to me, and i've been able to test several of the different connected states. I think we can improve some of the E2E test structure some more as the rest of the component gets filled out.

@eason9487 can you give this another look?

Copy link
Member

@eason9487 eason9487 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't view the code changes related to e2e testing in detail since they were continuously pushed commits while I was reviewing.

Due to #2618 (comment) and the following UI errors in one of the e2e test cases, I guess the e2e testing probably still needs to be adjusted accordingly, so I would like to submit the current feedback for this round.

image

);
[ '', 'billing', 'link_merchant' ].includes( step );

return isReady !== null ? isReady : null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ternary here seems redundant because it means:

If isReady is !== null, return isReady
If isReady is === null, return null

This can be simplified to:

Suggested change
return isReady !== null ? isReady : null;
return isReady;

However, it seems this all be simplified to a boolean return value by wrapping the expression in parenthesis like this (and updating the docblock):

	const isReady = (
		hasGoogleAdsConnection &&
		hasAccess &&
		[ '', 'billing', 'link_merchant' ].includes( step )
	);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ankitrox I see you updated this slightly in 7f20af7 but still think the suggestions here would be better, unless there is some reason to retain the null return value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joemcgill This has been addressed here:

if ( ! adsAccountResolved || ! adsAccountStatusResolved ) {
return null;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also:

return (
hasGoogleAdsConnection &&
hasAccess &&
[ '', 'billing', 'link_merchant' ].includes( step )
);

@@ -60,6 +64,12 @@ const useGoogleMCAccount = () => {
GOOGLE_MC_ACCOUNT_STATUS.INCOMPLETE,
].includes( acc?.status );

const isReady =
hasGoogleMCConnection &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be omitted since you are checking for the same account statuses below

Suggested change
hasGoogleMCConnection &&

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upvote this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been removed:

const isReady =
acc?.status === GOOGLE_MC_ACCOUNT_STATUS.CONNECTED ||
( acc?.status === GOOGLE_MC_ACCOUNT_STATUS.INCOMPLETE &&
acc?.step === 'link_ads' );

await setUpAccountsPage.fulfillAdsAccountStatus( {
has_access: true,
invite_link: '',
step: 'link_merchant',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very similar to the response from mockAdsStatusClaimed() except for the step that is returned. This matches what the API returns from the ads/account-status endpoint:

image

However, when the the Ads account is in this state, the ads/connections response would look something like this:

image

Making these two responses consistent would make for a more robust test, I think.

@joemcgill
Copy link
Collaborator

I've left a bit of feedback, but would appreciate if @eason9487 could give the latest iteration another look.

js/src/hooks/useGoogleAdsAccountReady.js Outdated Show resolved Hide resolved
@@ -60,6 +64,12 @@ const useGoogleMCAccount = () => {
GOOGLE_MC_ACCOUNT_STATUS.INCOMPLETE,
].includes( acc?.status );

const isReady =
hasGoogleMCConnection &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upvote this.

tests/e2e/utils/mock-requests.js Outdated Show resolved Hide resolved
tests/e2e/specs/setup-mc/step-1-accounts.test.js Outdated Show resolved Hide resolved
tests/e2e/specs/setup-mc/step-1-accounts.test.js Outdated Show resolved Hide resolved
tests/e2e/specs/setup-mc/step-1-accounts.test.js Outdated Show resolved Hide resolved
tests/e2e/specs/setup-mc/step-1-accounts.test.js Outdated Show resolved Hide resolved
tests/e2e/utils/mock-requests.js Outdated Show resolved Hide resolved
tests/e2e/utils/mock-requests.js Outdated Show resolved Hide resolved
@@ -11,31 +11,50 @@ export default class MockRequests {
this.page = page;
}

fulfillTimes( times ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a docblock

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been updated.

@@ -129,7 +148,6 @@ export default class MockRequests {
* Fulfill the MC connection request.
*
* @param {Object} payload
* @return {Promise<void>}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this return docs should be removed here or for fulfillAdsConnection

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted this one.

@@ -189,7 +207,6 @@ export default class MockRequests {
* Fulfill the Ads Connection request.
*
* @param {Object} payload
* @return {Promise<void>}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep (see above)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted this one.

@ankitrox
Copy link
Collaborator Author

Thanks for your valuable suggestion on E2E @eason9487. I have addressed these changes and left response to your comments. Assigning this to you for another pass.

Copy link
Member

@eason9487 eason9487 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work. LGTM.

Left a few comments and I believe it won't need another round of code reviews. I'll be approving in advance.

tests/e2e/specs/setup-mc/step-1-accounts.test.js Outdated Show resolved Hide resolved
tests/e2e/utils/mock-requests.js Outdated Show resolved Hide resolved
tests/e2e/utils/mock-requests.js Outdated Show resolved Hide resolved
@ankitrox
Copy link
Collaborator Author

Thanks for your review and valuable suggestions @eason9487 .

I've made the changes and merging the PR.

@ankitrox ankitrox merged commit 7ceffde into feature/2509-consolidate-google-account-cards Oct 28, 2024
7 of 8 checks passed
@ankitrox ankitrox deleted the feature/2567-kickoff-mc-ads-account-creation branch October 28, 2024 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: add A new feature, function, or functionality was added.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Onboarding: Automatically kick off MC & Ads accounts creation
5 participants