Skip to content

Commit

Permalink
update user mutations with new required ID field
Browse files Browse the repository at this point in the history
  • Loading branch information
esizer committed Sep 28, 2022
1 parent e4e11de commit 6144912
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 15 deletions.
2 changes: 2 additions & 0 deletions frontend/admin/src/js/api/userOperations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ mutation CreateUser($user: CreateUserInput!) {

mutation UpdateUserAsUser($id: ID!, $user: UpdateUserAsUserInput!) {
updateUserAsUser(id: $id, user: $user) {
id
sub
firstName
lastName
Expand Down Expand Up @@ -167,6 +168,7 @@ mutation UpdateUserAsUser($id: ID!, $user: UpdateUserAsUserInput!) {

mutation UpdateUserAsAdmin($id: ID!, $user: UpdateUserAsAdminInput!) {
updateUserAsAdmin(id: $id, user: $user) {
id
sub
roles

Expand Down
23 changes: 13 additions & 10 deletions frontend/admin/src/js/components/user/UpdateUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const UpdateUserForm: React.FunctionComponent<UpdateUserFormProps> = ({
values: FormValues,
): UpdateUserAsAdminInput => ({
...values,
id: initialUser.id,
// empty string isn't valid according to API validation regex pattern, but null is valid.
telephone: emptyToNull(values.telephone),
// empty string will violate uniqueness constraints
Expand Down Expand Up @@ -240,15 +241,18 @@ const UpdateUser: React.FunctionComponent<{ userId: string }> = ({
graphql operation to fail. */
executeMutation({
id,
user: pick(data, [
"email",
"firstName",
"lastName",
"telephone",
"preferredLang",
"sub",
"roles",
]),
user: {
id,
...pick(data, [
"email",
"firstName",
"lastName",
"telephone",
"preferredLang",
"sub",
"roles",
]),
},
}).then((result) => {
if (result.data?.updateUserAsAdmin) {
return result.data.updateUserAsAdmin;
Expand All @@ -258,7 +262,6 @@ const UpdateUser: React.FunctionComponent<{ userId: string }> = ({

return (
<Pending fetching={fetching} error={error}>
{" "}
<DashboardContentContainer>
{userData?.user ? (
<UpdateUserForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ query getGovInfoFormLookupData {

mutation UpdateGovAsUser($id: ID!, $user: UpdateUserAsUserInput!) {
updateUserAsUser(id: $id, user: $user) {
id
isGovEmployee
govEmployeeType
hasPriorityEntitlement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export const AboutMeForm: React.FunctionComponent<AboutMeFormProps> = ({
});

const formValuesToSubmitData = (data: FormValues): UpdateUserAsUserInput => {
return data;
return {
...data,
id: initialUser.id,
};
};

const handleSubmit: SubmitHandler<FormValues> = async (formValues) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ query getAboutMe {

mutation UpdateUserAsUser($id: ID!, $user: UpdateUserAsUserInput!) {
updateUserAsUser(id: $id, user: $user) {
id
preferredLang
currentProvince
currentCity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ const CreateAccount: React.FunctionComponent = () => {
const handleCreateAccount = (id: string, data: UpdateUserAsUserInput) =>
executeMutation({
id,
user: data,
user: {
...data,
id,
},
}).then((result) => {
if (result.data?.updateUserAsUser) {
return result.data.updateUserAsUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ query getCreateAccountFormData {

mutation CreateAccount($id: ID!, $user: UpdateUserAsUserInput!) {
updateUserAsUser(id: $id, user: $user) {
id
email
firstName
lastName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ describe("DiversityEquityInclusionForm", () => {
});

it("should update on save", async () => {
const mockSave = jest.fn(() => Promise.resolve({ data: {} }));
const mockSave = jest.fn(() =>
Promise.resolve({ id: "", data: { id: "" } }),
);
renderDiversityEquityInclusionForm({
user: {
...mockUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ query getMyDiversityInfo {

mutation updateMyDiversityInfo($id: ID!, $user: UpdateUserAsUserInput!) {
updateUserAsUser(id: $id, user: $user) {
id
isWoman
isIndigenous
isVisibleMinority
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { action } from "@storybook/addon-actions";
import { Meta, Story } from "@storybook/react";
import { fakeUsers } from "@common/fakeData";
import { pick } from "lodash";
import { UpdateUserAsUserInput } from "@common/api/generated";
import { LanguageInformationForm } from "./LanguageInformationForm";

export default {
Expand All @@ -19,9 +20,9 @@ const TemplateLangInfoForm: Story = (args) => {
return (
<LanguageInformationForm
initialData={initialData}
submitHandler={async (id, data) => {
submitHandler={async (id: string, data: UpdateUserAsUserInput) => {
action("Update Language Information")(id, data);
return Promise.resolve(data);
return Promise.resolve(null);
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ query GetLanguageInformation {

mutation UpdateLanguageInformation($id: ID!, $user: UpdateUserAsUserInput!) {
updateUserAsUser(id: $id, user: $user) {
id
lookingForEnglish
lookingForFrench
lookingForBilingual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ query getMyStatus {

mutation UpdateMyStatus($id: ID!, $user: UpdateUserAsUserInput!) {
updateUserAsUser(id: $id, user: $user) {
id
jobLookingStatus
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ query getRoleSalaryInfo {

mutation UpdateRoleSalary($id: ID!, $user: UpdateUserAsUserInput!) {
updateUserAsUser(id: $id, user: $user) {
id
expectedGenericJobTitles {
id
key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query WorkLocationPreference {

mutation createWorkLocationPreference($id: ID!, $user: UpdateUserAsUserInput!) {
updateUserAsUser(id: $id, user: $user) {
id
locationPreferences
locationExemptions
isProfileComplete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query getWorkPreferences {

mutation UpdateWorkPreferences($id: ID!, $user: UpdateUserAsUserInput!) {
updateUserAsUser(id: $id, user: $user) {
id
wouldAcceptTemporary
acceptedOperationalRequirements
isProfileComplete
Expand Down

0 comments on commit 6144912

Please sign in to comment.