-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools/risk-form-filler): create script
- Loading branch information
1 parent
e93e90d
commit 06e2389
Showing
18 changed files
with
1,171 additions
and
0 deletions.
There are no files selected for viewing
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,15 @@ | ||
# Workflow Execution Guide | ||
|
||
To run the script, use either one of these commands in the CLI to run a specific workflow: | ||
|
||
1. `pnpm nx run risk-form-filler:online` --> for submitting online events | ||
2. `pnpm nx run risk-form-filler:in-person` --> for submitting in-person events | ||
3. `pnpm nx run risk-form-filler:hybrid` --> for submitting hybrid events | ||
|
||
This will compile and automatically run a workflow for that specifc type of form. | ||
|
||
Be sure to change the input for that according workflow (for instance, change your hybrid input answers in src/input/hybrid-input.ts to something that is to your liking) | ||
|
||
Note that although these forms automate answers, please make a review to ensure that all the information on the form is filled completely and accurate before submission. | ||
|
||
Don't forget to end your session by pressing `CTRL C`. |
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,16 @@ | ||
import playwright from 'eslint-plugin-playwright' | ||
import baseConfigPromise from '../../eslint.config.js' | ||
|
||
export default (async () => { | ||
const baseConfig = await baseConfigPromise | ||
|
||
return [ | ||
playwright.configs['flat/recommended'], | ||
...baseConfig, | ||
{ | ||
files: ['**/*.ts', '**/*.js'], | ||
// Override or add rules here | ||
rules: {}, | ||
}, | ||
] | ||
})() |
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,19 @@ | ||
import process from 'node:process' | ||
|
||
import readline from 'node:readline' | ||
|
||
export async function getUserConfirmation(prompt: string): Promise<boolean> { | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}) | ||
|
||
const answer = await new Promise<string>((resolve) => { | ||
rl.question(prompt, (response) => { | ||
rl.close() | ||
resolve(response.trim().toLowerCase()) | ||
}) | ||
}) | ||
|
||
return answer === 'yes' || answer === 'y' | ||
} |
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 @@ | ||
export function validateDate(date: string): boolean { | ||
const dateRegex = /^\d{4}\/\d{2}\/\d{2}$/ | ||
if (!dateRegex.test(date)) { | ||
return false | ||
} | ||
|
||
const [year, month, day] = date.split('/').map(Number) | ||
if (year < 1900 || year > 2100 || month < 1 || month > 12 || day < 1 || day > 31) { | ||
return false | ||
} | ||
if (month === 2) { | ||
const isLeapYear = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0 | ||
if (day > 29 || (day === 29 && !isLeapYear)) { | ||
return false | ||
} | ||
} | ||
if ([4, 6, 9, 11].includes(month) && day > 30) { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
export function validateTime(time: string): boolean { | ||
const timeRegex = /^(?:[01]\d|2[0-3]):[0-5]\d (?:AM|PM)$/ | ||
return timeRegex.test(time) | ||
} | ||
|
||
export function validateStudentID(studentId: number): boolean { | ||
return studentId >= 100000000 && studentId <= 111111111 | ||
} | ||
|
||
export function validateCarletonEmail(email: string): boolean { | ||
const emailParts = email.split('@') | ||
return emailParts.length === 2 && emailParts[1] === 'cmail.carleton.ca' | ||
} |
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,8 @@ | ||
{ | ||
"name": "risk-form-filler", | ||
"type": "module", | ||
"description": "", | ||
"license": "", | ||
"sideEffects": false, | ||
"scripts": {} | ||
} |
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,45 @@ | ||
// TODO: Investigate node global process usage | ||
|
||
import { fileURLToPath } from 'node:url' | ||
import { nxE2EPreset } from '@nx/playwright/preset' | ||
|
||
import { defineConfig, devices } from '@playwright/test' | ||
|
||
const __filename = fileURLToPath(import.meta.url) | ||
|
||
// // For CI, you may want to set BASE_URL to the deployed application. | ||
// const baseURL = process.env.BASE_URL || 'http://127.0.0.1:3000' | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
...nxE2EPreset(__filename, { testDir: './src' }), | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
retries: 2, | ||
use: { | ||
// baseURL, | ||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'pnpm nx start risk-form-filler', | ||
// // url: 'http://127.0.0.1:3000', | ||
// // reuseExistingServer: !process.env.CI, | ||
// cwd: workspaceRoot, | ||
// timeout: 120 * 1000, | ||
// }, | ||
projects: [ | ||
{ | ||
name: 'chromium (desktop)', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
], | ||
}) |
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 @@ | ||
{ | ||
"name": "risk-form-filler", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "tools/risk-form-filler", | ||
"projectType": "application", | ||
"tags": [], | ||
"// targets": "to see all targets run: nx show project risk-form-filler --web", | ||
"targets": { | ||
"online": { | ||
"command": "npx tsx src/input/online-input.ts", | ||
"options": { | ||
"cwd": "tools/risk-form-filler" | ||
} | ||
}, | ||
"in-person": { | ||
"command": "npx tsx src/input/in-person-input.ts", | ||
"options": { | ||
"cwd": "tools/risk-form-filler" | ||
} | ||
}, | ||
"hybrid": { | ||
"command": "npx tsx src/input/hybrid-input.ts", | ||
"options": { | ||
"cwd": "tools/risk-form-filler" | ||
} | ||
} | ||
} | ||
} |
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,45 @@ | ||
export interface ScheduleHybridParams { | ||
primaryOrganizer: { | ||
firstName: string | ||
lastName: string | ||
studentID: number | ||
email: string | ||
phone: string | ||
} | ||
|
||
secondaryOrganizer: { | ||
firstName: string | ||
lastName: string | ||
studentID: number | ||
email: string | ||
phone: string | ||
} | ||
|
||
eventDetails: { | ||
title: string | ||
date: string // Format: 'YYYY/MM/DD' | ||
startTime: string // Format: 'HH:MM AM/PM' | ||
endTime: string // Format: 'HH:MM AM/PM' | ||
description: string | ||
location: string | ||
expectedAttendees: number | ||
} | ||
|
||
onlineInformation: { | ||
platform: string | ||
topics: string | ||
location: string | ||
numberOfOrganizers: number | ||
organizersAttendingOnline: number | ||
} | ||
|
||
riskManagement: { | ||
speakerTopics: string | ||
speakers: string | ||
speakerSites: string | ||
specialCircumstances: string | ||
risks: string | ||
cleanUpCrew: string | ||
additionalRemarks: string | ||
} | ||
} |
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,37 @@ | ||
export interface ScheduleInPersonParams { | ||
primaryOrganizer: { | ||
firstName: string | ||
lastName: string | ||
studentID: number | ||
email: string | ||
phone: string | ||
} | ||
|
||
secondaryOrganizer: { | ||
firstName: string | ||
lastName: string | ||
studentID: number | ||
email: string | ||
phone: string | ||
} | ||
|
||
eventDetails: { | ||
title: string | ||
date: string // Format: 'YYYY/MM/DD' | ||
startTime: string // Format: 'HH:MM AM/PM' | ||
endTime: string // Format: 'HH:MM AM/PM' | ||
description: string | ||
location: string | ||
expectedAttendees: string | ||
} | ||
|
||
riskManagement: { | ||
speakerTopics: string | ||
speakers: string | ||
speakerSites: string | ||
specialCircumstances: string | ||
risks: string | ||
cleanUpCrew: string | ||
additionalRemarks: string | ||
} | ||
} |
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,41 @@ | ||
export interface ScheduleOnlineParams { | ||
primaryOrganizer: { | ||
firstName: string | ||
lastName: string | ||
studentID: number | ||
email: string | ||
phone: string | ||
} | ||
|
||
secondaryOrganizer: { | ||
firstName: string | ||
lastName: string | ||
studentID: number | ||
email: string | ||
phone: string | ||
} | ||
|
||
eventDetails: { | ||
title: string | ||
date: string // Format: 'YYYY/MM/DD' | ||
startTime: string // Format: 'HH:MM AM/PM' | ||
endTime: string // Format: 'HH:MM AM/PM' | ||
description: string | ||
expectedAttendees: number | ||
} | ||
|
||
onlineInformation: { | ||
platform: string | ||
topics: string | ||
location: string | ||
numberOfOrganizers: number | ||
organizersAttendingOnline: number | ||
} | ||
|
||
speakerAndResources: { | ||
topics: string | ||
speakers: string | ||
speakerSites: string | ||
additionalRemarks: string | ||
} | ||
} |
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,37 @@ | ||
import type { ScheduleHybridParams } from './input/schedule-hybrid-params' | ||
|
||
import type { HybridFormLayout } from './pom' | ||
|
||
export async function scheduleHybrid(params: ScheduleHybridParams, formLayout: HybridFormLayout) { | ||
await formLayout.goto() | ||
await formLayout.hybridButton.click() | ||
|
||
await formLayout.fillContacts(formLayout, params.primaryOrganizer.firstName, params.primaryOrganizer.lastName, params.primaryOrganizer.studentID.toString(), params.primaryOrganizer.email, params.primaryOrganizer.phone, params.secondaryOrganizer.firstName, params.secondaryOrganizer.lastName, params.secondaryOrganizer.studentID.toString(), params.secondaryOrganizer.email, params.secondaryOrganizer.phone) | ||
|
||
await formLayout.eventLocationTextBox.fill(params.eventDetails.location) | ||
await formLayout.eventLocationRadioButton.check() | ||
await formLayout.expectedAttendeesTextBox.fill(params.eventDetails.expectedAttendees.toString()) | ||
await formLayout.hybridRegistrationRadioButton.check() | ||
await formLayout.foodRadioButton.check() | ||
await formLayout.healthInsuranceRadioButton.check() | ||
await formLayout.photoIdRadioButton.check() | ||
|
||
await formLayout.fillEventDetails(formLayout, params.eventDetails.title, params.eventDetails.date, params.eventDetails.startTime, params.eventDetails.endTime, params.eventDetails.description, params.eventDetails.expectedAttendees.toString()) | ||
await formLayout.fillOnlineInformation(formLayout, params.onlineInformation.platform, params.onlineInformation.topics, params.onlineInformation.location, params.onlineInformation.numberOfOrganizers.toString(), params.onlineInformation.organizersAttendingOnline.toString()) | ||
|
||
await formLayout.alcoholRadioButton.check() | ||
|
||
await formLayout.fillRiskManagement(formLayout, params.riskManagement.speakerTopics, params.riskManagement.speakers, params.riskManagement.speakerSites) | ||
await formLayout.fillEmergencyResponse(formLayout, params.riskManagement.specialCircumstances, params.riskManagement.risks) | ||
|
||
await formLayout.transportationRadioButton.check() | ||
await formLayout.outOfProvinceRadioButton.check() | ||
await formLayout.garbageRadioButton.check() | ||
await formLayout.cleanupRadioButton.check() | ||
await formLayout.cleanupTextBox.fill(params.riskManagement.cleanUpCrew) | ||
await formLayout.overnightRadioButton.check() | ||
|
||
await formLayout.fillLogistics(formLayout) | ||
|
||
await formLayout.rightsTextBox.fill(params.riskManagement.additionalRemarks) | ||
} |
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,34 @@ | ||
import type { ScheduleInPersonParams } from './input/schedule-in-person-params' | ||
import type { InPersonFormLayout } from './pom' | ||
|
||
export async function scheduleInPerson(params: ScheduleInPersonParams, formLayout: InPersonFormLayout) { | ||
await formLayout.goto() | ||
await formLayout.inPersonButton.click() | ||
|
||
await formLayout.fillContacts(formLayout, params.primaryOrganizer.firstName, params.primaryOrganizer.lastName, params.primaryOrganizer.studentID.toString(), params.primaryOrganizer.email, params.primaryOrganizer.phone, params.secondaryOrganizer.firstName, params.secondaryOrganizer.lastName, params.secondaryOrganizer.studentID.toString(), params.secondaryOrganizer.email, params.secondaryOrganizer.phone) | ||
|
||
await formLayout.eventLocationTextBox.fill(params.eventDetails.location) | ||
await formLayout.eventLocationRadioButton.check() | ||
await formLayout.expectedAttendeesTextBox.fill(params.eventDetails.expectedAttendees.toString()) | ||
await formLayout.foodRadioButton.check() | ||
await formLayout.healthInsuranceRadioButton.check() | ||
await formLayout.photoIdRadioButton.check() | ||
|
||
await formLayout.fillEventDetails(formLayout, params.eventDetails.title, params.eventDetails.date, params.eventDetails.startTime, params.eventDetails.endTime, params.eventDetails.description, params.eventDetails.expectedAttendees.toString()) | ||
|
||
await formLayout.alcoholRadioButton.check() | ||
|
||
await formLayout.fillRiskManagement(formLayout, params.riskManagement.speakerTopics, params.riskManagement.speakers, params.riskManagement.speakerSites) | ||
await formLayout.fillEmergencyResponse(formLayout, params.riskManagement.specialCircumstances, params.riskManagement.risks) | ||
|
||
await formLayout.transportationRadioButton.check() | ||
await formLayout.outOfProvinceRadioButton.check() | ||
await formLayout.garbageRadioButton.check() | ||
await formLayout.cleanupRadioButton.check() | ||
await formLayout.cleanupTextBox.fill(params.riskManagement.cleanUpCrew) | ||
await formLayout.overnightRadioButton.check() | ||
|
||
await formLayout.fillLogistics(formLayout) | ||
|
||
await formLayout.rightsTextBox.fill(params.riskManagement.additionalRemarks) | ||
} |
Oops, something went wrong.