From 88c62ae708b38c407677e27937f7f3a18f64b19a Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 6 Jul 2021 11:19:09 -0600 Subject: [PATCH] Code review feedback --- tests/e2e/env/utils/update-ready-page.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/e2e/env/utils/update-ready-page.js b/tests/e2e/env/utils/update-ready-page.js index 219f2f8c6fc..a3b49d4659f 100644 --- a/tests/e2e/env/utils/update-ready-page.js +++ b/tests/e2e/env/utils/update-ready-page.js @@ -24,11 +24,15 @@ const updateReadyPageStatus = async ( status ) => { // The page will be in a draft state, so we need to filter on that status statusFilter = 'draft'; } - const getPostsResponse = await client.get(`${wpPagesEndpoint}?search=ready&status=${statusFilter}`); - const pageId = getPostsResponse.data[0].id; - // Update the page to the new status - await client.post(`${wpPagesEndpoint}/${pageId}`, { 'status': status }); + const getPostsResponse = await client.get(`${wpPagesEndpoint}?search=ready&status=${statusFilter}`); + if ( getPostsResponse.data && getPostsResponse.data.length > 0) { + const pageId = getPostsResponse.data[0].id; + // Update the page to the new status + await client.post(`${wpPagesEndpoint}/${pageId}`, { 'status': status }); + } else { + throw new Error('Ready page not found.'); + } } module.exports = updateReadyPageStatus;