-
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.
feat(chat): Implement user private and public chat
- a user should be able to read previous chats - a user should be able to post a public chat - users should be able to chat privately Delivers #187419133
- Loading branch information
Showing
27 changed files
with
1,502 additions
and
111 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { configureStore } from "@reduxjs/toolkit"; | ||
import MockAdapter from "axios-mock-adapter"; | ||
|
||
import api from "../redux/api/api"; | ||
import authSlice, { fetchUser, setUser } from "../redux/reducers/authSlice"; | ||
|
||
const mockApi = new MockAdapter(api); | ||
const mockStore = (initialState) => | ||
configureStore({ | ||
reducer: { | ||
// @ts-ignore | ||
auth: authSlice, | ||
}, | ||
preloadedState: initialState, | ||
}); | ||
|
||
describe("Auth Slice Thunks", () => { | ||
let store; | ||
|
||
beforeEach(() => { | ||
mockApi.reset(); | ||
store = mockStore({ | ||
auth: { | ||
loading: false, | ||
data: [], | ||
error: null, | ||
userInfo: JSON.parse(localStorage.getItem("userInfo") || "{}"), | ||
}, | ||
}); | ||
}); | ||
|
||
it("should handle fetchUser pending", async () => { | ||
mockApi.onGet("/users/me").reply(200, {}); | ||
|
||
store.dispatch(fetchUser()); | ||
expect(store.getState().auth.loading).toBe(true); | ||
}); | ||
|
||
it("should handle fetchUser fulfilled", async () => { | ||
const mockData = { id: "1", name: "John Doe" }; | ||
mockApi.onGet("/users/me").reply(200, mockData); | ||
|
||
await store.dispatch(fetchUser()); | ||
|
||
expect(store.getState().auth.loading).toBe(false); | ||
expect(store.getState().auth.data).toEqual(mockData); | ||
expect(localStorage.getItem("userInfo")).toEqual(JSON.stringify(mockData)); | ||
}); | ||
|
||
it("should handle fetchUser rejected", async () => { | ||
mockApi.onGet("/users/me").reply(500); | ||
|
||
await store.dispatch(fetchUser()); | ||
|
||
expect(store.getState().auth.loading).toBe(false); | ||
expect(store.getState().auth.error).toBe("Rejected"); | ||
}); | ||
|
||
it("should handle setUser", () => { | ||
const mockUser = { id: "2", name: "Jane Doe" }; | ||
store.dispatch(setUser(mockUser)); | ||
|
||
expect(store.getState().auth.userInfo).toEqual(mockUser); | ||
expect(localStorage.getItem("userInfo")).toEqual(JSON.stringify(mockUser)); | ||
}); | ||
|
||
it("should handle fetchUser axios error with specific message", async () => { | ||
mockApi.onGet("/users/me").reply(500, { message: "Server error" }); | ||
|
||
await store.dispatch(fetchUser()); | ||
|
||
expect(store.getState().auth.loading).toBe(false); | ||
expect(store.getState().auth.error.message).toBe("Server error"); | ||
}); | ||
|
||
it("should handle fetchUser axios network error", async () => { | ||
mockApi.onGet("/users/me").networkError(); | ||
|
||
await store.dispatch(fetchUser()); | ||
|
||
expect(store.getState().auth.loading).toBe(false); | ||
expect(store.getState().auth.error).toBe("Rejected"); | ||
}); | ||
}); |
Oops, something went wrong.