Skip to content

Commit

Permalink
fix: deprecate edit member (#362)
Browse files Browse the repository at this point in the history
* fix: udpate hook

* fix: mock server

* fix: merge changes

* fix: update deps

* fix: server mock function paths

* fix: use npm version of query-client
  • Loading branch information
spaenleh authored Oct 7, 2024
1 parent 8e85e76 commit 246e230
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 642 deletions.
4 changes: 2 additions & 2 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../fixtures/members';
import {
mockDeleteCurrentMember,
mockEditMember,
mockEditCurrentMember,
mockEditPublicProfile,
mockExportData,
mockGetCurrentMember,
Expand Down Expand Up @@ -77,7 +77,7 @@ Cypress.Commands.add(

mockSignOut();

mockEditMember(cachedCurrentMember, editMemberError);
mockEditCurrentMember(cachedCurrentMember, editMemberError);
mockEditPublicProfile(cachedCurrentProfile, editPublicProfileError);
mockGetCurrentMemberAvatar(currentMember, getAvatarUrlError);

Expand Down
45 changes: 9 additions & 36 deletions cypress/support/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { API_ROUTES } from '@graasp/query-client';
import {
CompleteMember,
HttpMethod,
Member,
PublicProfile,
buildSignInPath,
} from '@graasp/sdk';
Expand All @@ -17,10 +16,9 @@ import {
import { ID_FORMAT, MemberForTest } from './utils';

const {
buildGetMemberRoute,
buildGetCurrentMemberRoute,
SIGN_OUT_ROUTE,
buildPatchMemberRoute,
buildPatchCurrentMemberRoute,
buildUploadAvatarRoute,
buildPatchMemberPasswordRoute,
buildGetOwnPublicProfileRoute,
Expand Down Expand Up @@ -89,7 +87,7 @@ export const mockGetCurrentMember = (
cy.intercept(
{
method: HttpMethod.Get,
url: `${API_HOST}/${buildGetCurrentMemberRoute()}`,
pathname: `/${buildGetCurrentMemberRoute()}`,
},
({ reply }) => {
if (shouldThrowError) {
Expand All @@ -105,39 +103,14 @@ export const mockGetCurrentMember = (
).as('getCurrentMember');
};

export const mockGetMember = (members: Member[]): void => {
cy.intercept(
{
method: HttpMethod.Get,
url: new RegExp(`${API_HOST}/${buildGetMemberRoute(ID_FORMAT)}$`),
},
({ url, reply }) => {
const memberId = url.slice(API_HOST.length).split('/')[2];
const member = members.find((m) => m.id === memberId);

// member does not exist in db
if (!member) {
return reply({
statusCode: StatusCodes.NOT_FOUND,
});
}

return reply({
body: member,
statusCode: StatusCodes.OK,
});
},
).as('getMember');
};

export const mockEditMember = (
export const mockEditCurrentMember = (
currentMember: CompleteMember,
shouldThrowError: boolean,
): void => {
cy.intercept(
{
method: HttpMethod.Patch,
url: new RegExp(`${API_HOST}/${buildPatchMemberRoute(ID_FORMAT)}`),
pathname: `/${buildPatchCurrentMemberRoute()}`,
},
({ reply, body }) => {
if (shouldThrowError) {
Expand Down Expand Up @@ -252,7 +225,7 @@ export const mockPostAvatar = (shouldThrowError: boolean): void => {
cy.intercept(
{
method: HttpMethod.Post,
url: new RegExp(`${buildUploadAvatarRoute()}`),
pathname: `/${buildUploadAvatarRoute()}`,
},
({ reply }) => {
if (shouldThrowError) {
Expand All @@ -268,7 +241,7 @@ export const mockUpdatePassword = (shouldThrowError: boolean): void => {
cy.intercept(
{
method: HttpMethod.Patch,
url: new RegExp(`${API_HOST}/${buildPatchMemberPasswordRoute()}`),
pathname: `/${buildPatchMemberPasswordRoute()}`,
},
({ reply }) => {
if (shouldThrowError) {
Expand All @@ -284,7 +257,7 @@ export const mockUpdateEmail = (shouldThrowError: boolean): void => {
cy.intercept(
{
method: HttpMethod.Post,
url: new RegExp(`${API_HOST}/${buildPostMemberEmailUpdateRoute()}`),
pathname: `/${buildPostMemberEmailUpdateRoute()}`,
},
({ reply }) => {
if (shouldThrowError) {
Expand All @@ -300,7 +273,7 @@ export const mockExportData = (shouldThrowError: boolean): void => {
cy.intercept(
{
method: HttpMethod.Post,
url: new RegExp(`${API_HOST}/${buildExportMemberDataRoute()}`),
pathname: `/${buildExportMemberDataRoute()}`,
},
({ reply }) => {
if (shouldThrowError) {
Expand All @@ -316,7 +289,7 @@ export const mockDeleteCurrentMember = (): void => {
cy.intercept(
{
method: HttpMethod.Delete,
url: new RegExp(`${API_HOST}/${buildDeleteCurrentMemberRoute()}`),
pathname: `/${buildDeleteCurrentMemberRoute()}`,
},
({ reply }) => reply({ statusCode: StatusCodes.NO_CONTENT }),
).as('deleteCurrentMember');
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"@emotion/cache": "11.13.1",
"@emotion/react": "11.13.3",
"@emotion/styled": "11.13.0",
"@graasp/query-client": "3.26.0",
"@graasp/sdk": "4.31.0",
"@graasp/query-client": "4.0.1",
"@graasp/sdk": "4.32.0",
"@graasp/stylis-plugin-rtl": "2.2.0",
"@graasp/translations": "1.39.0",
"@graasp/ui": "5.2.1",
Expand All @@ -34,7 +34,7 @@
"axios": "1.7.7",
"date-fns": "4.1.0",
"http-status-codes": "2.3.0",
"i18next": "23.15.1",
"i18next": "23.15.2",
"lodash.truncate": "4.4.2",
"lucide-react": "^0.447.0",
"react": "18.3.1",
Expand Down
3 changes: 1 addition & 2 deletions src/components/main/EditMemberPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const EditMemberPreferences = ({
}: EditPreferencesProp): JSX.Element => {
const { t } = useAccountTranslation();
const { t: translateCommon } = useCommonTranslation();
const { mutate: editMember } = mutations.useEditMember();
const { mutate: editMember } = mutations.useEditCurrentMember();

const memberLang = member?.extra?.lang ?? DEFAULT_LANG;
const memberEmailFreq = member?.extra?.emailFreq ?? DEFAULT_EMAIL_FREQUENCY;
Expand All @@ -49,7 +49,6 @@ const EditMemberPreferences = ({
};
const saveSettings = () => {
editMember({
id: member.id,
extra: {
lang: selectedLang,
emailFreq: selectedEmailFreq,
Expand Down
3 changes: 1 addition & 2 deletions src/modules/profile/EditPersonalInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const EditPersonalInformation = ({
}: EditMemberPersonalInformationProp): JSX.Element => {
const { t } = useAccountTranslation();
const { t: translateCommon } = useCommonTranslation();
const { mutate: editMember } = mutations.useEditMember();
const { mutate: editMember } = mutations.useEditCurrentMember();
const { mutate: updateEmail } = mutations.useUpdateMemberEmail();
const [newUserName, setNewUserName] = useState('');
const [newEmail, setNewEmail] = useState('');
Expand Down Expand Up @@ -95,7 +95,6 @@ const EditPersonalInformation = ({
const name = newUserName.trim();
if (member && name !== member.name) {
editMember({
id: member.id,
name,
});
}
Expand Down
Loading

0 comments on commit 246e230

Please sign in to comment.