-
Notifications
You must be signed in to change notification settings - Fork 2k
/
authentication__magic-link.ts
59 lines (48 loc) · 1.7 KB
/
authentication__magic-link.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @group authentication
*/
import { DataHelper, EmailClient, LoginPage, SecretsManager } from '@automattic/calypso-e2e';
import { Page, Browser } from 'playwright';
import type { Message } from 'mailosaur/lib/models';
declare const browser: Browser;
describe( DataHelper.createSuiteTitle( 'Authentication: Magic Link' ), function () {
const credentials = SecretsManager.secrets.testAccounts.defaultUser;
let page: Page;
let loginPage: LoginPage;
let emailClient: EmailClient;
let magicLinkURL: URL;
let magicLinkEmail: Message;
beforeAll( async () => {
page = await browser.newPage();
} );
it( 'Navigate to Magic Link screen from /login', async function () {
loginPage = new LoginPage( page );
await loginPage.visit();
await loginPage.clickSendMagicLink();
} );
it( 'Request magic link', async function () {
// It is safe to add type assertion here, since the email
// field is defined for `defaultUser`.
await loginPage.fillUsername( credentials.email as string );
await loginPage.clickSubmit();
emailClient = new EmailClient();
magicLinkEmail = await emailClient.getLastMatchingMessage( {
inboxId: SecretsManager.secrets.mailosaur.defaultUserInboxId,
sentTo: credentials.email as string,
subject: 'Log in to WordPress.com',
} );
magicLinkURL = emailClient.getMagicLink( magicLinkEmail );
expect( magicLinkURL.href ).toBeDefined();
} );
it( 'Open the magic link', async function () {
await page.goto( magicLinkURL.href );
} );
it( 'Redirected to Home dashboard', async function () {
await page.waitForURL( /home/, { timeout: 15 * 1000 } );
} );
afterAll( async () => {
if ( magicLinkEmail ) {
await emailClient.deleteMessage( magicLinkEmail );
}
} );
} );