Skip to content

Commit

Permalink
[Bug] Position type only applies to indeterminate (#12501)
Browse files Browse the repository at this point in the history
* govPositionType only for indeterminate

* update validation

* fix test

* fix test

* handle invalid states in getArgs()

* lint
  • Loading branch information
vd1992 authored Jan 17, 2025
1 parent 7216aba commit 2ccf25e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Enums\EmploymentCategory;
use App\Enums\GovContractorType;
use App\Enums\GovPositionType;
use App\Enums\WorkExperienceGovEmployeeType;
use Illuminate\Validation\Rule;
use Nuwave\Lighthouse\Validation\Validator;
Expand Down Expand Up @@ -62,16 +61,19 @@ public function rules(): array
'workExperience.govPositionType' => [
Rule::requiredIf(
(
$this->arg('workExperience.govEmploymentType') === WorkExperienceGovEmployeeType::INDETERMINATE->name ||
$this->arg('workExperience.govEmploymentType') === WorkExperienceGovEmployeeType::TERM->name
$this->arg('workExperience.govEmploymentType') === WorkExperienceGovEmployeeType::INDETERMINATE->name
)
),
Rule::prohibitedIf(
(
$this->arg('workExperience.govEmploymentType') !== WorkExperienceGovEmployeeType::INDETERMINATE->name
)
),
Rule::prohibitedIf(
(
$this->arg('workExperience.employmentCategory') !== EmploymentCategory::GOVERNMENT_OF_CANADA->name
)
),
$this->arg('workExperience.govEmploymentType') === WorkExperienceGovEmployeeType::TERM->name ? Rule::notIn(GovPositionType::SUBSTANTIVE->name) : null,
],
'workExperience.govContractorRoleSeniority' => [
Rule::requiredIf(
Expand Down
6 changes: 3 additions & 3 deletions api/tests/Feature/WorkExperienceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function testCreatingExperienceFailsValidatingRequired(): void
)->assertGraphQLValidationError('workExperience.extRoleSeniority', 'The work experience.ext role seniority field is required.');
}

// test that validation rejects creating experiences with substantive position type when gov employee type is term
// test that validation rejects creating experiences with govPositionType when gov employee type is term
public function testCreatingExperienceFailsValidatingGovPositionType(): void
{
$this->actingAs($this->admin, 'api')->graphQL(
Expand All @@ -169,7 +169,7 @@ public function testCreatingExperienceFailsValidatingGovPositionType(): void
'govPositionType' => GovPositionType::SUBSTANTIVE->name,
],
]
)->assertGraphQLValidationError('workExperience.govPositionType', 'The selected work experience.gov position type is invalid.');
)->assertGraphQLValidationError('workExperience.govPositionType', 'The work experience.gov position type field is prohibited.');
}

// test that a created work experience of government type queries without issue
Expand All @@ -194,7 +194,7 @@ public function testQueryingCreatedExperienceGovernment(): void
'userId' => $this->admin->id,
'workExperience' => [
'employmentCategory' => EmploymentCategory::GOVERNMENT_OF_CANADA->name,
'govEmploymentType' => WorkExperienceGovEmployeeType::TERM->name,
'govEmploymentType' => WorkExperienceGovEmployeeType::INDETERMINATE->name,
'govPositionType' => GovPositionType::ACTING->name,
'classificationId' => $classification->id,
'departmentId' => $department->id,
Expand Down
12 changes: 2 additions & 10 deletions apps/playwright/fixtures/ExperiencePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,10 @@ class ExperiencePage extends AppPage {
})
.click();

// Ensure "Substantive" option is removed from position type group
// when employment type is "Term"
// Ensure position type group disappears when employment type is "Term"
await expect(
this.page.getByRole("group", { name: /position type/i }),
).not.toContainText("Substantive");

await this.page
.getByRole("group", { name: /position type/i })
.getByRole("radio", {
name: /acting/i,
})
.click();
).toBeHidden();

// Change the employment type to "Indeterminate"
await this.page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@ const GovFields = ({ labels }: SubExperienceFormProps) => {
name: "govContractorType",
});

// If the government employee type is "Term",
// then remove the "Substantive" option from the govPositionTypes
const allPositionTypes = localizedEnumToOptions(data?.govPositionTypes, intl);
const conditionalPositionTypes =
watchGovEmploymentType === WorkExperienceGovEmployeeType.Term
? allPositionTypes.filter(
(positionType) =>
positionType.value !== String(GovPositionType.Substantive),
)
: allPositionTypes;

const departmentOptions = unpackMaybes(data?.departments).map(
({ id, name }) => ({
value: id,
Expand Down Expand Up @@ -272,15 +261,14 @@ const GovFields = ({ labels }: SubExperienceFormProps) => {
rules={{ required: intl.formatMessage(errorMessages.required) }}
/>
</div>
{(watchGovEmploymentType ===
WorkExperienceGovEmployeeType.Indeterminate ||
watchGovEmploymentType === WorkExperienceGovEmployeeType.Term) && (
{watchGovEmploymentType ===
WorkExperienceGovEmployeeType.Indeterminate && (
<div data-h2-flex-item="base(1of1)">
<RadioGroup
idPrefix="govPositionType"
name="govPositionType"
legend={labels.positionType}
items={conditionalPositionTypes}
items={localizedEnumToOptions(data?.govPositionTypes, intl)}
rules={{ required: intl.formatMessage(errorMessages.required) }}
/>
</div>
Expand Down
13 changes: 12 additions & 1 deletion apps/web/src/hooks/useExperienceMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CreateEducationExperienceMutation,
CreatePersonalExperienceMutation,
CreateWorkExperienceMutation,
GovEmployeeType,
graphql,
} from "@gc-digital-talent/graphql";

Expand Down Expand Up @@ -158,10 +159,20 @@ export const useExperienceMutations = (
id: string,
values: ExperienceDetailsSubmissionData,
): ExperienceMutationArgs => {
// users may have invalid WorkExperience state with govEmploymentType TERM and non-null govPositionType
const massagedValues = values;
if (
experienceType === "work" &&
!!massagedValues.govEmploymentType &&
massagedValues.govEmploymentType !== GovEmployeeType.Indeterminate
) {
massagedValues.govPositionType = null;
}

return {
id,
...(!!experienceType && {
[args[experienceType]]: values,
[args[experienceType]]: massagedValues,
}),
} as ExperienceMutationArgs;
};
Expand Down

0 comments on commit 2ccf25e

Please sign in to comment.