-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
useractions.unit.test : profile update actions
- Loading branch information
1 parent
bddabad
commit 3bd5c66
Showing
1 changed file
with
30 additions
and
9 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 |
---|---|---|
|
@@ -32,6 +32,7 @@ import { | |
EmailAuthProvider, | ||
reauthenticateWithCredential, | ||
updatePassword, | ||
signOut, | ||
} from 'firebase/auth'; | ||
import { toastError } from "../src/actions/toastActions.js"; | ||
import { | ||
|
@@ -74,6 +75,7 @@ jest.mock('firebase/auth', () => ({ | |
reauthenticateWithCredential: jest.fn(), | ||
updatePassword: jest.fn(), | ||
storeUID: jest.fn(), | ||
signOut: jest.fn(), | ||
auth: { | ||
updateEmail: jest.fn(), | ||
}, | ||
|
@@ -205,6 +207,7 @@ describe('Async User Actions', () => { | |
it('should call storeUID with user UID on successful login', async () => { | ||
const user = { uid: 'testUID', email: '[email protected]', displayName: 'John Doe' }; | ||
const store = mockStore({}); | ||
|
||
signInWithEmailAndPassword.mockResolvedValue({ user }); | ||
|
||
await store.dispatch(startLoginWithEmail('[email protected]', 'password123')); | ||
|
@@ -219,8 +222,13 @@ describe('Async User Actions', () => { | |
|
||
await store.dispatch(startLoginWithEmail('[email protected]', 'password123')); | ||
|
||
await flushPromises(); | ||
|
||
const actions = store.getActions(); | ||
expect(actions[0]).toEqual(toastError('The password is invalid or the user does not have a password.')); | ||
|
||
const expectedErrorsMessage = firebaseErrorsMessages[error.code] || "Wrong password."; | ||
|
||
expect(actions[0]).toEqual(toastError(expectedErrorsMessage)); | ||
}); | ||
|
||
it('should dispatch LOGOUT and toastError on successful logout', async () => { | ||
|
@@ -236,25 +244,38 @@ describe('Async User Actions', () => { | |
|
||
}); | ||
|
||
|
||
|
||
|
||
// ### Profile Update Actions | ||
|
||
describe('Profile Update Actions', () => { | ||
it('should dispatch UPDATE_PROFILE on successful profile update', async () => { | ||
// const store = mockStore({}); | ||
const store = mockStore({}); | ||
|
||
// updateProfile.mockResolvedValue(); | ||
updateProfile.mockResolvedValue(); | ||
|
||
// await store.dispatch(startUpdateProfile('John', 'Doe')); | ||
await store.dispatch(startUpdateProfile('John', 'Doe')); | ||
|
||
// const action = store.getActions(); | ||
// expect(action[0]).toEqual({ | ||
// type: UPDATE_PROFILE, | ||
// payload: ['John', 'Doe'], | ||
// }); | ||
const action = store.getActions(); | ||
expect(action[0]).toEqual({ | ||
type: UPDATE_PROFILE, | ||
payload: ['John', 'Doe'], | ||
}); | ||
}); | ||
|
||
it('should dispatch toastError with appropriate message on profile update failure', async () => { | ||
const error = { code: '' }; | ||
const store = mockStore({}); | ||
|
||
updateProfile.mockRejectedValue(new Error('Error updating profile!')); | ||
|
||
await store.dispatch(startUpdateProfile('John', 'Doe')); | ||
|
||
await flushPromises(); | ||
|
||
const action = store.getActions(); | ||
expect(action[0]).toEqual(toastError('Error updating profile!')); | ||
}); | ||
}); | ||
|
||
|