-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Migrate updateProfile to ts (#3607)
- Loading branch information
1 parent
ecdafdb
commit 78d2b2a
Showing
5 changed files
with
162 additions
and
26 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 |
---|---|---|
|
@@ -33,6 +33,10 @@ beforeEach(() => { | |
server.resetHandlers() | ||
}) | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
afterAll(() => { | ||
server.close() | ||
}) | ||
|
@@ -43,7 +47,7 @@ describe('DetailsSection', () => { | |
const mutate = vi.fn() | ||
const addNotification = vi.fn() | ||
|
||
useAddNotification.mockReturnValue(addNotification) | ||
vi.mocked(useAddNotification).mockReturnValue(addNotification) | ||
server.use( | ||
graphql.mutation('UpdateProfile', (info) => { | ||
mutate(info.variables) | ||
|
@@ -52,15 +56,23 @@ describe('DetailsSection', () => { | |
data: { | ||
updateProfile: { | ||
me: { | ||
username: 'donald duck', | ||
email: info.variables.input.email | ||
? info.variables.input.email | ||
: '[email protected]', | ||
name: info.variables.input.name | ||
? info.variables.input.name | ||
: 'donald duck', | ||
avatarUrl: 'http://127.0.0.1/avatar-url', | ||
onboardingCompleted: false, | ||
onboardingCompleted: true, | ||
privateAccess: null, | ||
businessEmail: null, | ||
user: { | ||
name: info.variables.input.name | ||
? info.variables.input.name | ||
: 'donald duck', | ||
username: 'donald duck', | ||
avatarUrl: 'http://127.0.0.1/avatar-url', | ||
avatar: 'http://127.0.0.1/avatar-url', | ||
student: false, | ||
studentCreatedAt: null, | ||
studentUpdatedAt: null, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
@@ -218,10 +230,15 @@ describe('DetailsSection', () => { | |
) | ||
}) | ||
}) | ||
|
||
describe('when mutation is not successful', () => { | ||
it('adds an error notification', async () => { | ||
const { user, addNotification } = setup() | ||
server.use( | ||
graphql.mutation('UpdateProfile', () => { | ||
return HttpResponse.error() | ||
}) | ||
) | ||
|
||
render(<DetailsSection name="donald duck" email="[email protected]" />, { | ||
wrapper, | ||
}) | ||
|
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
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 |
---|---|---|
|
@@ -16,6 +16,11 @@ const user = { | |
name: 'terry', | ||
avatarUrl: 'http://127.0.0.1/avatar-url', | ||
onboardingCompleted: false, | ||
privateAccess: true, | ||
businessEmail: null, | ||
student: false, | ||
studentCreatedAt: null, | ||
studentUpdatedAt: null, | ||
} | ||
|
||
const queryClient = new QueryClient({ | ||
|
@@ -50,9 +55,19 @@ describe('useUpdateProfile', () => { | |
server.use( | ||
graphql.mutation('UpdateProfile', (info) => { | ||
const newUser = { | ||
...user, | ||
name: info.variables.input.name, | ||
email: info.variables.input.email, | ||
onboardingCompleted: user.onboardingCompleted, | ||
privateAccess: user.privateAccess, | ||
businessEmail: user.businessEmail, | ||
user: { | ||
name: info.variables.input.name, | ||
username: user.username, | ||
avatarUrl: user.avatarUrl, | ||
avatar: user.avatarUrl, | ||
student: user.student, | ||
studentCreatedAt: user.studentCreatedAt, | ||
studentUpdatedAt: user.studentUpdatedAt, | ||
}, | ||
} | ||
|
||
return HttpResponse.json({ | ||
|
@@ -88,11 +103,19 @@ describe('useUpdateProfile', () => { | |
|
||
await waitFor(() => | ||
expect(result.current.data).toStrictEqual({ | ||
avatarUrl: 'http://127.0.0.1/avatar-url', | ||
email: '[email protected]', | ||
name: 'new name', | ||
privateAccess: true, | ||
onboardingCompleted: false, | ||
username: 'TerrySmithDC', | ||
businessEmail: null, | ||
user: { | ||
name: 'new name', | ||
username: 'TerrySmithDC', | ||
avatarUrl: 'http://127.0.0.1/avatar-url', | ||
avatar: 'http://127.0.0.1/avatar-url', | ||
student: false, | ||
studentCreatedAt: null, | ||
studentUpdatedAt: null, | ||
}, | ||
}) | ||
) | ||
}) | ||
|
@@ -108,11 +131,19 @@ describe('useUpdateProfile', () => { | |
|
||
await waitFor(() => | ||
expect(result.current.data).toStrictEqual({ | ||
avatarUrl: 'http://127.0.0.1/avatar-url', | ||
email: '[email protected]', | ||
name: 'new name', | ||
privateAccess: true, | ||
onboardingCompleted: false, | ||
username: 'TerrySmithDC', | ||
businessEmail: null, | ||
user: { | ||
name: 'new name', | ||
username: 'TerrySmithDC', | ||
avatarUrl: 'http://127.0.0.1/avatar-url', | ||
avatar: 'http://127.0.0.1/avatar-url', | ||
student: false, | ||
studentCreatedAt: null, | ||
studentUpdatedAt: null, | ||
}, | ||
}) | ||
) | ||
}) | ||
|
@@ -153,11 +184,19 @@ describe('useUpdateProfile', () => { | |
|
||
await waitFor(() => | ||
expect(result.current.data).toStrictEqual({ | ||
avatarUrl: 'http://127.0.0.1/avatar-url', | ||
email: '[email protected]', | ||
name: 'new name', | ||
privateAccess: true, | ||
onboardingCompleted: false, | ||
username: 'TerrySmithDC', | ||
businessEmail: null, | ||
user: { | ||
name: 'new name', | ||
username: 'TerrySmithDC', | ||
avatarUrl: 'http://127.0.0.1/avatar-url', | ||
avatar: 'http://127.0.0.1/avatar-url', | ||
student: false, | ||
studentCreatedAt: null, | ||
studentUpdatedAt: null, | ||
}, | ||
}) | ||
) | ||
}) | ||
|
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
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