Skip to content

Commit

Permalink
ci: put encrypt-submission playwright tests back
Browse files Browse the repository at this point in the history
  • Loading branch information
LinHuiqing committed May 3, 2023
1 parent e35d60c commit f6d4eff
Showing 1 changed file with 137 additions and 0 deletions.
137 changes: 137 additions & 0 deletions __tests__/e2e/encrypt-submission.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import mongoose from 'mongoose'
import { BasicField, FormResponseMode } from 'shared/types'

import { IFormModel } from 'src/types'

import {
ALL_FIELDS as _ALL_FIELDS,
NO_LOGIC,
TEST_ALL_FIELDS_SHOWN_BY_LOGIC,
TEST_FIELD_HIDDEN_BY_LOGIC,
TEST_SUBMISSION_DISABLED_BY_CHAINED_LOGIC,
} from './constants'
import { test } from './fixtures'
import {
createForm,
createSubmissionTestRunnerForResponseMode,
verifySubmissionDisabled,
} from './helpers'
import {
createBlankVersion,
createOptionalVersion,
deleteDocById,
getSettings,
makeModel,
makeMongooseFixtures,
} from './utils'

// TODO: Attachment fields don't work on storage mode unless we spin up localstack.
const ALL_FIELDS = _ALL_FIELDS.filter(
(field) => field.fieldType !== BasicField.Attachment,
)

const runEncryptSubmissionTest = createSubmissionTestRunnerForResponseMode(
FormResponseMode.Encrypt,
)

let db: mongoose.Connection
let Form: IFormModel

test.describe('Storage form submission', () => {
test.beforeAll(async () => {
// Create models
db = await makeMongooseFixtures()
Form = makeModel(db, 'form.server.model', 'Form')
})
test.afterAll(async () => {
// Clean up db
db.models = {}
await db.close()
})

test('Create and submit storage mode form with all fields', async ({
page,
}) => {
// Define
const formFields = ALL_FIELDS
const formLogics = NO_LOGIC
const formSettings = getSettings()

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

test('Create and submit storage mode form with all fields optional', async ({
page,
}) => {
// Define
const formFields = ALL_FIELDS.map((ff) =>
createBlankVersion(createOptionalVersion(ff)),
)
const formLogics = NO_LOGIC
const formSettings = getSettings()

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

test('Create and submit storage mode form with all fields shown by logic', async ({
page,
}) => {
// Define
const { formFields, formLogics } = TEST_ALL_FIELDS_SHOWN_BY_LOGIC
const formSettings = getSettings()

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

test('Create and submit storage mode form with a field hidden by logic', async ({
page,
}) => {
// Define
const { formFields, formLogics } = TEST_FIELD_HIDDEN_BY_LOGIC
const formSettings = getSettings()

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

test('Create storage mode form with submission disabled by chained logic', async ({
page,
}) => {
// Define
const { formFields, formLogics, preventSubmitMessage } =
TEST_SUBMISSION_DISABLED_BY_CHAINED_LOGIC
const formSettings = getSettings()

// Test
const { form } = await createForm(page, Form, FormResponseMode.Encrypt, {
formFields,
formLogics,
formSettings,
})
await verifySubmissionDisabled(
page,
{ form, formFields, formSettings },
preventSubmitMessage,
)
await deleteDocById(Form, form._id)
})
})

0 comments on commit f6d4eff

Please sign in to comment.