| | |
| | |
| | |
| |
|
| | import { |
| | getTestAccountByFeature, |
| | envToFeatureKey, |
| | envVariables, |
| | DataHelper, |
| | TestAccount, |
| | RestAPIClient, |
| | PostResponse, |
| | PublishedPostPage, |
| | EmailClient, |
| | SecretsManager, |
| | SubscribersPage, |
| | } from '@automattic/calypso-e2e'; |
| | import { Page, Browser } from 'playwright'; |
| | import { skipDescribeIf } from '../../jest-helpers'; |
| |
|
| | declare const browser: Browser; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | skipDescribeIf( envVariables.ATOMIC_VARIATION === 'private' )( |
| | DataHelper.createSuiteTitle( 'Newsletter: Subscribe and Remove' ), |
| | function () { |
| | |
| | const inboxID = SecretsManager.secrets.mailosaur.manualTesting; |
| | const postTitle = DataHelper.getDateString( 'ISO-8601' ) as string; |
| | const emailClient = new EmailClient(); |
| | const testEmail = emailClient.getTestEmailAddress( inboxID ); |
| |
|
| | let page: Page; |
| | let testAccount: TestAccount; |
| | let restAPIClient: RestAPIClient; |
| | let newPostDetails: PostResponse; |
| | let subscribersPage: SubscribersPage; |
| |
|
| | beforeAll( async function () { |
| | page = await browser.newPage(); |
| |
|
| | const features = envToFeatureKey( envVariables ); |
| | const accountName = getTestAccountByFeature( features ); |
| |
|
| | |
| | |
| | testAccount = new TestAccount( accountName ); |
| |
|
| | |
| | restAPIClient = new RestAPIClient( testAccount.credentials ); |
| | newPostDetails = await restAPIClient.createPost( |
| | testAccount.credentials.testSites?.primary.id as number, |
| | { |
| | title: postTitle, |
| | content: '<!-- wp:jetpack/subscriptions /-->', |
| | } |
| | ); |
| | } ); |
| |
|
| | describe( 'As subscribing user', function () { |
| | it( 'Navigate to published post page', async function () { |
| | await page.goto( newPostDetails.URL ); |
| | } ); |
| |
|
| | it( 'Subscribe to the site', async function () { |
| | const publishedPostPage = new PublishedPostPage( page ); |
| | await publishedPostPage.subscribe( testEmail ); |
| | } ); |
| |
|
| | it( 'Confirm email subscription', async function () { |
| | const message = await emailClient.getLastMatchingMessage( { |
| | inboxId: inboxID, |
| | subject: 'Confirm your subscription', |
| | sentTo: testEmail, |
| | } ); |
| |
|
| | const confirmationURL = |
| | emailClient.getLinkFromMessageByKey( message, 'Confirm email' ) ?? |
| | emailClient.getLinkFromMessageByKey( message, 'Confirm now' ); |
| | expect( confirmationURL ).not.toBe( null ); |
| |
|
| | |
| | |
| | |
| | const pageForConfirming = await browser.newPage(); |
| | const waitForRedirectToOriginalPost = pageForConfirming.waitForURL( |
| | ( url ) => url.href.includes( newPostDetails.URL ), |
| | { |
| | timeout: 45 * 1000, |
| | } |
| | ); |
| | await pageForConfirming.goto( confirmationURL as string ); |
| | await waitForRedirectToOriginalPost; |
| | } ); |
| | } ); |
| |
|
| | describe( 'As publishing user', function () { |
| | beforeAll( async function () { |
| | |
| | await testAccount.authenticate( page ); |
| |
|
| | subscribersPage = new SubscribersPage( page ); |
| | } ); |
| |
|
| | it( 'Navigate to the Subscribers page', async function () { |
| | await subscribersPage.visit( testAccount.getSiteURL( { protocol: false } ) ); |
| | } ); |
| |
|
| | it( 'Search for subscribed user', async function () { |
| | await subscribersPage.validateSubscriber( testEmail ); |
| | } ); |
| |
|
| | it( 'Remove subscribed user', async function () { |
| | await subscribersPage.removeSubscriber( testEmail ); |
| | } ); |
| | } ); |
| |
|
| | afterAll( async function () { |
| | try { |
| | |
| | await restAPIClient.deleteSubscriber( |
| | testAccount.credentials.testSites?.primary.id as number, |
| | testEmail |
| | ); |
| |
|
| | await restAPIClient.deletePost( |
| | testAccount.credentials.testSites?.primary.id as number, |
| | newPostDetails.ID |
| | ); |
| | } catch { |
| | |
| | } |
| | } ); |
| | } |
| | ); |
| |
|