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

feat: implement report problem with form submission API path #36

Merged
merged 13 commits into from
Sep 5, 2024

Conversation

craigzour
Copy link
Contributor

@craigzour craigzour commented Aug 27, 2024

Summary | Résumé

Linked with:

====

  • Adds new /problem API path to report problem with form submission
  • Introduces express-validator package to validate the JSON payload required by the new /problem POST operation
  • Introduces a new EnvironmentMode variable. For this feature it is used to add custom tags to the Freshdesk ticket and make sure we are not trying to create ticket in local mode.

@craigzour craigzour self-assigned this Aug 27, 2024
@craigzour craigzour force-pushed the feature/report-problem-with-submission branch from 6427f25 to 863e57c Compare August 29, 2024 19:14
type Location,
validationResult,
type Schema,
} from "express-validator";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selected https://express-validator.github.io/docs for now.
The way it is implemented in our code (middleware) makes it easy to change in the future if we are not happy with it.
Also, even though express-validator provides ready to use middleware functions, I decided to create a custom one because it is easier to control the error response when the validation fails. Otherwise we would have to create a new middleware function to catch the specific error thrown by the library.

Existing other options:

@craigzour craigzour force-pushed the feature/report-problem-with-submission branch 2 times, most recently from 1c3e6c5 to 1ac0e79 Compare August 30, 2024 13:49
email: contactEmail,
type: "Problem",
subject: "Problem with GC Forms / Problème avec Formulaires GC",
tags: [tagFromEnvironmentMode(), "Forms_API_Submission"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tags have been discussed with Jimmy from our support team.

@craigzour craigzour force-pushed the feature/report-problem-with-submission branch 2 times, most recently from 2e40c7c to 6e1ef1a Compare August 30, 2024 14:48
src/config.ts Outdated
// Internal function to load environment variables

function loadOptionalEnvVar(envVarName: string): string | undefined {
return process.env[envVarName];
}

function loadRequiredEnvVar(envVarName: string): string {
if (process.env.NODE_ENV === "test") {
return "TEST_IN_PROGRESS";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to re implement this condition as the way we mock the configuration variables during Vitest setup has been implemented in a way that will load the config file (importOriginal) as is before altering its content for testing purpose. Since the code in the config file will be executed it will try to load variables that don't exist in the Github Action environment.

vitest-setup.ts Outdated Show resolved Hide resolved
vitest-setup.ts Outdated Show resolved Hide resolved
@craigzour craigzour marked this pull request as ready for review September 3, 2024 17:59
@craigzour craigzour requested review from patheard, bryan-robitaille and wmoussa-gc and removed request for bryan-robitaille and wmoussa-gc September 3, 2024 17:59
@craigzour craigzour force-pushed the feature/report-problem-with-submission branch from 81e7f5d to d8c56e8 Compare September 4, 2024 20:23
Copy link
Contributor

@bryan-robitaille bryan-robitaille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. Since this project is still very young we'll continue to refactor and see what patterns work and what might need changing as we go along.

@craigzour craigzour merged commit 40eaf16 into main Sep 5, 2024
4 checks passed
@craigzour craigzour deleted the feature/report-problem-with-submission branch September 5, 2024 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants