generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,906 additions
and
365 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { CognitoUserHelper, User } from '../helpers/cognito-user-helper'; | ||
import { IamWebAuthSignInPage } from '../pages/iam-webauth-signin-page'; | ||
|
||
test.describe('SignIn', () => { | ||
let user: User; | ||
|
||
const cognitoHelper = new CognitoUserHelper(); | ||
|
||
test.beforeAll(async () => { | ||
user = await cognitoHelper.createUser('playwright-signIn'); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await cognitoHelper.deleteUser(user.userId); | ||
}); | ||
|
||
test('should sign user in, then redirect user to redirect path', async ({ | ||
page, | ||
baseURL, | ||
}) => { | ||
const signInPage = new IamWebAuthSignInPage(page); | ||
|
||
await signInPage.loadPage({ | ||
redirectPath: '/templates/create-and-submit-templates', | ||
}); | ||
|
||
await signInPage.cognitoSignIn(user.email); | ||
|
||
await expect(page).toHaveURL( | ||
`${baseURL}/templates/create-and-submit-templates` | ||
); | ||
}); | ||
|
||
test.describe('Error handling', () => { | ||
test('should not log user in, when email is invalid', async ({ page }) => { | ||
const signInPage = new IamWebAuthSignInPage(page); | ||
|
||
await signInPage.loadPage({ | ||
redirectPath: '/templates/create-and-submit-templates', | ||
}); | ||
|
||
await signInPage.emailInput.fill('[email protected]'); | ||
|
||
await signInPage.passwordInput.fill(process.env.TEMPORARY_USER_PASSWORD); | ||
|
||
await signInPage.clickSubmitButton(); | ||
|
||
await expect(signInPage.errorMessage).toHaveText( | ||
'Incorrect username or password.' | ||
); | ||
}); | ||
|
||
test('should not log user in, when password is invalid', async ({ | ||
page, | ||
}) => { | ||
const signInPage = new IamWebAuthSignInPage(page); | ||
|
||
await signInPage.loadPage({ | ||
redirectPath: '/templates/create-and-submit-templates', | ||
}); | ||
|
||
await signInPage.emailInput.fill(user.email); | ||
|
||
await signInPage.passwordInput.fill('invalid-password'); | ||
|
||
await signInPage.clickSubmitButton(); | ||
|
||
await expect(signInPage.errorMessage).toHaveText( | ||
'Incorrect username or password.' | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { CognitoUserHelper, User } from '../helpers/cognito-user-helper'; | ||
import { IamWebAuthSignInPage } from '../pages/iam-webauth-signin-page'; | ||
|
||
test.describe('SignIn', () => { | ||
let user: User; | ||
|
||
const cognitoHelper = new CognitoUserHelper(); | ||
|
||
test.beforeAll(async () => { | ||
user = await cognitoHelper.createUser('playwright-signout'); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await cognitoHelper.deleteUser(user.userId); | ||
}); | ||
|
||
test('should sign user out, then redirect user to redirect path', async ({ | ||
page, | ||
baseURL, | ||
}) => { | ||
const signInPage = new IamWebAuthSignInPage(page); | ||
|
||
await signInPage.loadPage({ | ||
redirectPath: '/templates/create-and-submit-templates', | ||
}); | ||
|
||
await signInPage.cognitoSignIn(user.email); | ||
|
||
await expect(page).toHaveURL( | ||
`${baseURL}/templates/create-and-submit-templates` | ||
); | ||
|
||
await page.goto( | ||
`${baseURL}/auth/signout?redirect=${encodeURIComponent('/templates/create-and-submit-templates')}` | ||
); | ||
|
||
await expect(page).toHaveURL( | ||
`${baseURL}/templates/create-and-submit-templates` | ||
); | ||
|
||
await signInPage.loadPage({ | ||
redirectPath: '/templates/create-and-submit-templates', | ||
}); | ||
|
||
await expect(signInPage.emailInput).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { FullConfig } from '@playwright/test'; | ||
import { AmplifyConfigurationHelper } from '../helpers/amplify-configuration-helper'; | ||
import generate from 'generate-password'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
async function globalSetup(config: FullConfig) { | ||
const configHelper = new AmplifyConfigurationHelper(); | ||
|
||
const [temporary, password] = generate.generateMultiple(2, { | ||
length: 12, | ||
numbers: true, | ||
uppercase: true, | ||
symbols: true, | ||
strict: true, | ||
}); | ||
|
||
process.env.AWS_COGNITO_USER_POOL_ID = configHelper.getUserPoolId(); | ||
process.env.TEMPORARY_USER_PASSWORD = temporary; | ||
process.env.USER_PASSWORD = password; | ||
process.env.USER_EMAIL_PREFIX = uuidv4().slice(0, 5); | ||
|
||
return config; | ||
} | ||
|
||
export default globalSetup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
import baseConfig from './playwright.config'; | ||
|
||
export default defineConfig({ | ||
...baseConfig, | ||
|
||
timeout: 10000_000, | ||
|
||
projects: [ | ||
{ | ||
name: 'component', | ||
testMatch: '*.component.ts', | ||
use: { | ||
screenshot: 'only-on-failure', | ||
baseURL: 'http://localhost:3000', | ||
...devices['Desktop Chrome'], | ||
headless: false, | ||
}, | ||
}, | ||
{ | ||
name: 'e2e-local', | ||
testMatch: '*.e2e.spec.ts', | ||
use: { | ||
baseURL: 'http://localhost:3000', | ||
...devices['Desktop Chrome'], | ||
}, | ||
}, | ||
], | ||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: 'npm run test:start-local-app', | ||
url: 'http://localhost:3000/auth', | ||
reuseExistingServer: !process.env.CI, | ||
stderr: 'pipe', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { defineConfig } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
testDir: '../', | ||
fullyParallel: false, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
retries: 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 4 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: [ | ||
['line'], | ||
[ | ||
'html', | ||
{ | ||
outputFolder: '../playwright-report', | ||
open: process.env.CI ? 'never' : 'on-failure', | ||
}, | ||
], | ||
], | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
globalSetup: './global.setup.ts', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
declare global { | ||
namespace NodeJS { | ||
interface ProcessEnv { | ||
TEMPORARY_USER_PASSWORD: string; | ||
USER_PASSWORD: string; | ||
AWS_COGNITO_USER_POOL_ID: string; | ||
USER_EMAIL_PREFIX: string; | ||
} | ||
} | ||
} | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as fs from 'node:fs'; | ||
|
||
type AmplifyOutput = { | ||
auth: { | ||
user_pool_id: string; | ||
user_pool_client_id: string; | ||
identity_pool_id: string; | ||
}; | ||
}; | ||
|
||
export class AmplifyConfigurationHelper { | ||
private readonly _configuration: AmplifyOutput; | ||
|
||
constructor() { | ||
this._configuration = JSON.parse( | ||
fs.readFileSync('../../amplify_outputs.json', 'utf8') | ||
); | ||
} | ||
|
||
getUserPoolId() { | ||
return this._configuration.auth.user_pool_id; | ||
} | ||
} |
Oops, something went wrong.