Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e/email): add form auth tests #5876

Merged
merged 12 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Build
env:
NODE_OPTIONS: '--max-old-space-size=4096'
NODE_OPTIONS: '--max-old-space-size=4096 --openssl-legacy-provider'
run: npm run build
- name: Run Playwright tests
run: npx playwright test
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
unsafe-perm=true
legacy-peer-deps=true
KenLSM marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Install [docker and docker-compose](https://docs.docker.com/get-docker/).
To install the relevant npm packages, run the following in the root direcory:

```bash
npm install --legacy-peer-deps
npm install
```

To prevent breaking changes to webpack4 introduced in node 17 and above, enable the `--openssl-legacy-provider` flag:
Expand Down Expand Up @@ -99,7 +99,7 @@ only takes ~15 seconds to finish starting up the image.

### Adding dependencies

Run `npm install --legacy-peer-deps` as per usual.
Run `npm install` as per usual.

For backend, run

Expand Down
33 changes: 24 additions & 9 deletions __tests__/e2e/constants/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ImageFieldBase,
LongTextFieldBase,
MobileFieldBase,
MyInfoAttribute,
NricFieldBase,
NumberFieldBase,
RadioFieldBase,
Expand Down Expand Up @@ -43,6 +44,10 @@ type E2ePickFieldMetadata<T extends FieldBase, K extends keyof T> = Pick<
> &
Partial<Pick<T, 'description' | 'required'>>

type E2eFieldMyInfoable = {
myInfo?: { attr: MyInfoAttribute; verified: boolean }
}

// Field filling data
type E2eFieldSingleValue = { val: string }
type E2eFieldMultiValue = { val: string[] }
Expand All @@ -67,7 +72,8 @@ export type E2eFieldMetadata =
E2eFieldHidden)
| (E2ePickFieldMetadata<DateFieldBase, 'dateValidation'> &
E2eFieldSingleValue &
E2eFieldHidden)
E2eFieldHidden &
E2eFieldMyInfoable)
| (E2ePickFieldMetadata<
DecimalFieldBase,
'ValidationOptions' | 'validateByValue'
Expand All @@ -76,7 +82,8 @@ export type E2eFieldMetadata =
E2eFieldHidden)
| (E2ePickFieldMetadata<DropdownFieldBase, 'fieldOptions'> &
E2eFieldSingleValue &
E2eFieldHidden)
E2eFieldHidden &
E2eFieldMyInfoable)
| (E2ePickFieldMetadata<
EmailFieldBase,
| 'isVerifiable'
Expand All @@ -95,9 +102,13 @@ export type E2eFieldMetadata =
| (E2ePickFieldMetadata<LongTextFieldBase, 'ValidationOptions'> &
E2eFieldSingleValue &
E2eFieldHidden)
| (E2ePickFieldMetadata<MobileFieldBase, 'allowIntlNumbers'> & // Omit 'isVerfiable', since we can't test that.
| (E2ePickFieldMetadata<
MobileFieldBase,
'allowIntlNumbers' | 'isVerifiable'
> &
E2eFieldSingleValue &
E2eFieldHidden)
E2eFieldHidden &
E2eFieldMyInfoable)
| (E2ePickFieldMetadata<NricFieldBase, never> &
E2eFieldSingleValue &
E2eFieldHidden)
Expand All @@ -119,7 +130,8 @@ export type E2eFieldMetadata =
'ValidationOptions' | 'allowPrefill'
> &
E2eFieldSingleValue &
E2eFieldHidden)
E2eFieldHidden &
E2eFieldMyInfoable)
| (E2ePickFieldMetadata<StatementFieldBase, never> & E2eFieldHidden)
| (E2ePickFieldMetadata<
TableFieldBase,
Expand Down Expand Up @@ -182,10 +194,12 @@ export const ALL_FIELDS: E2eFieldMetadata[] = [
fieldType: BasicField.Email,
isVerifiable: true,
autoReplyOptions: {
hasAutoReply: false,
autoReplyMessage: '',
autoReplySender: '',
autoReplySubject: '',
hasAutoReply: true,
autoReplyMessage:
'Thank you for your submission. We will reach out to you in 3 working days.',
autoReplySender: 'GovTech Singapore',
autoReplySubject: 'Thanks for submitting',
// TODO: Save to pdf doesn't work.
includeFormSummary: false,
},
hasAllowedEmailDomains: false,
Expand Down Expand Up @@ -217,6 +231,7 @@ export const ALL_FIELDS: E2eFieldMetadata[] = [
{
title: 'Mobile',
fieldType: BasicField.Mobile,
isVerifiable: false, // Always has to be false, since we can't really test for mobile verification.
allowIntlNumbers: true,
// Number should start with +(country code), if allowIntlNumbers. Otherwise, just the 8 digit input.
val: '+6598889999',
Expand Down
5 changes: 5 additions & 0 deletions __tests__/e2e/constants/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ export type E2eSettingsOptions = {
closedFormMessage?: string
emails?: string[]
authType: FormAuthType
/** If authType is SPCP/MyInfo, eserviceId is required. */
esrvcId?: string
/** If authType is non-NIL, nric is required. */
nric?: string
/** If authType is CP, uen is required */
uen?: string
}
117 changes: 72 additions & 45 deletions __tests__/e2e/email-submission.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Page } from '@playwright/test'
import mongoose from 'mongoose'
import { BasicField, LogicConditionState, LogicType } from 'shared/types'
import {
BasicField,
FormAuthType,
LogicConditionState,
LogicType,
MyInfoAttribute,
} from 'shared/types'

import { IFormModel } from 'src/types'

Expand All @@ -15,9 +21,10 @@ import {
} from './constants'
import { createForm, fillForm, submitForm, verifySubmission } from './helpers'
import {
createBlankVersion,
createMyInfoField,
createOptionalVersion,
deleteDocById,
getBlankVersion,
getOptionalVersion,
getSettings,
makeModel,
makeMongooseFixtures,
Expand Down Expand Up @@ -55,7 +62,7 @@ test.describe('Email form submission', () => {
}) => {
// Define
const formFields = ALL_FIELDS.map((ff) =>
getBlankVersion(getOptionalVersion(ff)),
createBlankVersion(createOptionalVersion(ff)),
)
const formLogics = NO_LOGIC
const formSettings = getSettings()
Expand Down Expand Up @@ -98,7 +105,7 @@ test.describe('Email form submission', () => {
val: '1-test-att.txt',
} as E2eFieldMetadata,
{
...getBlankVersion(getOptionalVersion(baseField)),
...createBlankVersion(createOptionalVersion(baseField)),
title: 'Attachment 1',
} as E2eFieldMetadata,
{
Expand All @@ -115,52 +122,72 @@ test.describe('Email form submission', () => {
await runTest(page, { formFields, formLogics, formSettings })
})

// TODO: Uncomment these tests when mockpass has been fixed.
// test('Create and submit email mode form with Singpass authentication', async ({
// page,
// }) => {
// // Define
// const formFields = ALL_FIELDS
// const formLogics = NO_LOGIC
// const formSettings = getSettings({
// authType: FormAuthType.SP,
// esrvcId: process.env.SINGPASS_ESRVC_ID,
// })
test('Create and submit email mode form with Singpass authentication', async ({
page,
}) => {
// Define
const formFields = ALL_FIELDS
const formLogics = NO_LOGIC
const formSettings = getSettings({
authType: FormAuthType.SP,
})

// // Test
// await runTest(page, { formFields, formLogics, formSettings })
// })
// Test
await runTest(page, { formFields, formLogics, formSettings })
})

// test('Create and submit email mode form with Corppass authentication', async ({
// page,
// }) => {
// // Define
// const formFields = ALL_FIELDS
// const formLogics = NO_LOGIC
// const formSettings = getSettings({
// authType: FormAuthType.CP,
// esrvcId: process.env.CORPPASS_ESRVC_ID,
// })
test('Create and submit email mode form with Corppass authentication', async ({
page,
}) => {
// Define
const formFields = ALL_FIELDS
const formLogics = NO_LOGIC
const formSettings = getSettings({
authType: FormAuthType.CP,
})

// // Test
// await runTest(page, { formFields, formLogics, formSettings })
// })
// Test
await runTest(page, { formFields, formLogics, formSettings })
})

// test('Create and submit email mode form with SGID authentication', async ({
// page,
// }) => {
// // Define
// const formFields = ALL_FIELDS
// const formLogics = NO_LOGIC
// const formSettings = getSettings({
// authType: FormAuthType.SGID,
// })
test('Create and submit email mode form with SGID authentication', async ({
page,
}) => {
// Define
const formFields = ALL_FIELDS
const formLogics = NO_LOGIC
const formSettings = getSettings({
authType: FormAuthType.SGID,
})

// // Test
// await runTest(page, { formFields, formLogics, formSettings })
// })
// Test
await runTest(page, { formFields, formLogics, formSettings })
})

// TODO: Add test for MyInfo when mockpass has been fixed.
test('Create and submit email mode form with MyInfo fields', async ({
page,
}) => {
// Define
const formFields = [
// Short answer
createMyInfoField(MyInfoAttribute.Name, 'LIM YONG XIANG', true),
// Dropdown
createMyInfoField(MyInfoAttribute.Sex, 'MALE', true),
// Date
createMyInfoField(MyInfoAttribute.DateOfBirth, '06/10/1980', true),
// Mobile
createMyInfoField(MyInfoAttribute.MobileNo, '97399245', false),
// Unverified
createMyInfoField(MyInfoAttribute.WorkpassStatus, 'Live', false),
]
const formLogics = NO_LOGIC
const formSettings = getSettings({
authType: FormAuthType.MyInfo,
})

// Test
await runTest(page, { formFields, formLogics, formSettings })
})

test('Create and submit email mode form with all fields shown by logic', async ({
page,
Expand Down
Loading