Skip to content

Commit 254e783

Browse files
committed
Merge branch 'develop' into release/3.6.0
2 parents e3e9f29 + 07b3275 commit 254e783

File tree

3 files changed

+150
-15
lines changed

3 files changed

+150
-15
lines changed

tests/e2e/specs/settings/settings.test.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,60 @@ test.describe( 'Settings', () => {
210210
await expect( disconnectButton ).toBeVisible();
211211
} );
212212

213-
test( 'should show a notice if there are no channels when connected', async () => {
214-
await settingsPage.mockYouTubeAccountNoChannels();
213+
test( 'should show a notice if the YouTube account is incomplete', async () => {
214+
await settingsPage.mockYouTubeAccountIncomplete();
215215
await settingsPage.goto();
216216

217217
const notice = settingsPage.youTubeCard.getByText(
218-
'No channels found (or permission not granted).'
218+
'Your YouTube account is connected, but setup isn’t complete yet.'
219219
);
220220

221221
await expect( notice ).toBeVisible();
222222
} );
223+
224+
test( 'should display error message when "Complete setup" fails', async () => {
225+
await settingsPage
226+
.withFulfillTimes( 1 )
227+
.mockNotEligibleYouTubeChannel();
228+
const requestPromise =
229+
settingsPage.registerYouTubeCompleteSetupRequest();
230+
231+
const completeSetupButton =
232+
settingsPage.getYouTubeCompleteSetupButton();
233+
await completeSetupButton.click();
234+
235+
await requestPromise;
236+
237+
await expect(
238+
settingsPage.youTubeCard.getByText(
239+
'The channel is not eligible for the linking program.'
240+
)
241+
).toBeVisible();
242+
} );
243+
244+
test( 'should complete YouTube account setup successfully', async () => {
245+
await settingsPage
246+
.withFulfillTimes( 1 )
247+
.mockYouTubeAccountIncomplete();
248+
await settingsPage.mockEligibleYouTubeChannel();
249+
await settingsPage.goto();
250+
251+
const requestPromise =
252+
settingsPage.registerYouTubeCompleteSetupRequest();
253+
254+
const completeSetupButton =
255+
settingsPage.getYouTubeCompleteSetupButton();
256+
await completeSetupButton.click();
257+
258+
await requestPromise;
259+
260+
// Now mock as connected so re-renders show the channel name
261+
await settingsPage.mockYouTubeAccountConnected();
262+
263+
await expect(
264+
settingsPage.youTubeCard.getByText( 'My YouTube Channel' )
265+
).toBeVisible();
266+
} );
223267
} );
224268

225269
test.describe( 'No connected Google Merchant Center account', () => {

tests/e2e/utils/mock-requests.js

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,22 +1162,102 @@ export default class MockRequests {
11621162
}
11631163

11641164
/**
1165-
* Mock a connected YouTube account that has no channels.
1165+
* Mock helper that simulates an incomplete YouTube account connection by calling
1166+
* `fulfillYouTubeAccountConnection` with a predefined payload.
1167+
*
1168+
* The payload sets `status` to `'incomplete'` while still providing channel metadata
1169+
* (`id` and `label`), which may be used by consumers to determine that the account
1170+
* connection process has been started but not completed.
11661171
*
1167-
* This asynchronous helper fulfills the YouTube account connection with a
1168-
* status of "connected" and an explicit null channel value, simulating a
1169-
* scenario where the account is connected but no channels are available or
1170-
* accessible.
1172+
* This method is asynchronous and awaits the underlying fulfillment call.
11711173
*
1172-
* @return {Promise<void>} Resolves once the mock connection has been fulfilled.
1174+
* @return {Promise<*>} Resolves with whatever value `fulfillYouTubeAccountConnection` returns.
11731175
*/
1174-
async mockYouTubeAccountNoChannels() {
1176+
async mockYouTubeAccountIncomplete() {
11751177
await this.fulfillYouTubeAccountConnection( {
1176-
status: 'connected',
1177-
channel: [],
1178+
status: 'incomplete',
1179+
channel: {
1180+
id: 'a89ahifdaffe234',
1181+
label: 'My YouTube Channel',
1182+
},
11781183
} );
11791184
}
11801185

1186+
/**
1187+
* Mock helper that simulates a YouTube account connection with an ineligible channel by calling
1188+
* `fulfillYouTubeAccountConnection` with a predefined payload.
1189+
* The payload includes an error message and code indicating that the channel is not eligible for the linking program.
1190+
*
1191+
* This method is asynchronous and awaits the underlying fulfillment call.
1192+
*
1193+
* @return {Promise<*>} Resolves with whatever value `fulfillYouTubeAccountConnection` returns.
1194+
*/
1195+
async mockNotEligibleYouTubeChannel() {
1196+
await this.fulfillYouTubeCompleteSetup(
1197+
{
1198+
message: 'The channel is not eligible for the linking program.',
1199+
error: {
1200+
code: 403,
1201+
message:
1202+
'The channel is not eligible for the linking program.',
1203+
errors: [
1204+
{
1205+
message:
1206+
'The channel is not eligible for the linking program.',
1207+
domain: 'youtube.thirdPartyLink',
1208+
reason: 'CHANNEL_NOT_ELIGIBLE',
1209+
},
1210+
],
1211+
},
1212+
},
1213+
403
1214+
);
1215+
}
1216+
1217+
/**
1218+
* Mock helper that simulates a YouTube account connection with an eligible channel by calling
1219+
* `fulfillYouTubeAccountConnection` with a predefined payload.
1220+
* The payload includes a message indicating that the channel is eligible for the linking program.
1221+
*
1222+
* This method is asynchronous and awaits the underlying fulfillment call.
1223+
*
1224+
* @return {Promise<*>} Resolves with whatever value `fulfillYouTubeAccountConnection` returns.
1225+
*/
1226+
async mockEligibleYouTubeChannel() {
1227+
await this.fulfillYouTubeCompleteSetup( {
1228+
message: 'The channel is eligible for the linking program.',
1229+
} );
1230+
}
1231+
1232+
/**
1233+
* Fulfills a mock request for the YouTube complete setup endpoint, simulating the completion of the YouTube setup process.
1234+
*
1235+
* @param {Object} payload - The mock response payload to be returned, which may include details about the completed setup.
1236+
* @param {number} [status=200] - The HTTP status code to be returned. Defaults to 200.
1237+
* @return {Promise<void>} A promise that resolves when the request is fulfilled.
1238+
*/
1239+
async fulfillYouTubeCompleteSetup( payload, status = 200 ) {
1240+
await this.fulfillRequest(
1241+
/\/wc\/gla\/youtube\/setup\/complete\b/,
1242+
payload,
1243+
status,
1244+
[ 'POST' ]
1245+
);
1246+
}
1247+
1248+
/**
1249+
* Registers a wait for a request to the YouTube complete setup endpoint, allowing tests to wait until this specific request is made before proceeding.
1250+
*
1251+
* @return {Promise<import('playwright').Request>} A promise that resolves with the intercepted request object when a request matching the criteria is made.
1252+
*/
1253+
async registerYouTubeCompleteSetupRequest() {
1254+
return this.page.waitForRequest(
1255+
( request ) =>
1256+
request.url().includes( '/gla/youtube/setup/complete' ) &&
1257+
request.method() === 'POST'
1258+
);
1259+
}
1260+
11811261
/**
11821262
* Fulfills a mock request for the final URL suggestions endpoint for campaign assets.
11831263
*

tests/e2e/utils/pages/settings.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export default class SettingsPage extends MockRequests {
1313
constructor( page ) {
1414
super( page );
1515
this.page = page;
16-
this.youTubeCard = this.page.locator(
17-
'.gla-account-card:nth-child(4)'
18-
);
16+
this.youTubeCard = this.page
17+
.locator( '.gla-account-card' )
18+
.filter( { hasText: 'YouTube' } );
1919
}
2020

2121
/**
@@ -95,6 +95,17 @@ export default class SettingsPage extends MockRequests {
9595
} );
9696
}
9797

98+
/**
99+
* Get the Complete YouTube Setup button.
100+
*
101+
* @return {Promise<import('@playwright/test').Locator>} The Complete YouTube Setup button
102+
*/
103+
getYouTubeCompleteSetupButton() {
104+
return this.youTubeCard.getByRole( 'button', {
105+
name: 'Complete setup',
106+
} );
107+
}
108+
98109
/**
99110
* Register the request when the enhanced conversions checkbox is checked or unchecked.
100111
*

0 commit comments

Comments
 (0)