Skip to content

Commit 85f4875

Browse files
Jonath-zserapieTuyishime
authored andcommitted
chore: resolve conflicts
1 parent cbbdc7a commit 85f4875

File tree

8 files changed

+357
-104
lines changed

8 files changed

+357
-104
lines changed

__mocks__/provider/ReduxProvider.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

__mocks__/provider/handlers.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { http, HttpResponse, delay } from "msw";
2+
3+
export const handlers = [
4+
http.get("/api/communities", async () => {
5+
await delay(150);
6+
console.log("Called called called");
7+
return HttpResponse.json({ community: {} });
8+
}),
9+
];

__mocks__/renderWithRedux.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
import { RenderOptions, render } from "@testing-library/react";
2-
import { ReactElement } from "react";
3-
import ReduxProvider from "./provider/ReduxProvider";
1+
import { IRootState, middlewares, reducers } from "@/store";
2+
import { configureStore } from "@reduxjs/toolkit";
3+
import { ReactElement, ReactNode } from "react";
4+
import { Provider } from "react-redux";
5+
import { render } from "@testing-library/react";
46

5-
const customRender = (element: ReactElement, options?: Omit<RenderOptions, "wrapper">) => {
6-
return render(element, { wrapper: ReduxProvider, ...options })
7-
}
7+
const mockStore = (state: Partial<IRootState>) => {
8+
return configureStore({
9+
reducer: reducers,
10+
middleware: (getDefaultMiddleware) => {
11+
return getDefaultMiddleware().concat(...middlewares);
12+
},
13+
preloadedState: state,
14+
});
15+
};
816

9-
export * from "@testing-library/react"
10-
export { customRender as renderWithRedux }
17+
export const renderWithRedux = (component: ReactElement, state: Partial<IRootState> = {}) => {
18+
const Wrapper = ({ children }: { children: ReactNode }) => {
19+
return <Provider store={mockStore(state)}>{children}</Provider>;
20+
};
21+
22+
return render(component, { wrapper: Wrapper });
23+
};

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ const createJestConfig = nextJest({
1717
const config = {
1818
coverageProvider: "v8",
1919
testEnvironment: "jsdom",
20+
setupFiles: ["./jest.polyfills.js"],
2021
// Add more setup options before each test is run
2122
// setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
23+
testEnvironmentOptions: {
24+
customExportConditions: [""],
25+
},
2226
moduleNameMapper: {
2327
[`^(${esModules})-.*`]: "<rootDir>/__mocks__/plugin.ts",
2428
unified: "<rootDir>/__mocks__/unified.ts",

jest.polyfills.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
/**
3+
* @note The block below contains polyfills for Node.js globals
4+
* required for Jest to function when running JSDOM tests.
5+
* These HAVE to be require's and HAVE to be in this exact
6+
* order, since "undici" depends on the "TextEncoder" global API.
7+
*
8+
* Consider migrating to a more modern test runner if
9+
* you don't want to deal with this.
10+
*/
11+
12+
const { TextDecoder, TextEncoder, ReadableStream } = require("node:util");
13+
14+
Object.defineProperties(globalThis, {
15+
TextDecoder: { value: TextDecoder },
16+
TextEncoder: { value: TextEncoder },
17+
ReadableStream: { value: ReadableStream },
18+
});
19+
20+
const { Blob, File } = require("node:buffer");
21+
const { fetch, Headers, FormData, Request, Response } = require("undici");
22+
23+
Object.defineProperties(globalThis, {
24+
fetch: { value: fetch, writable: true },
25+
Blob: { value: Blob },
26+
File: { value: File },
27+
Headers: { value: Headers },
28+
FormData: { value: FormData },
29+
Request: { value: Request },
30+
Response: { value: Response },
31+
});

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"prettier-format": "prettier --config .prettierrc 'src/**/*.{ts,tsx,js,jsx}' --write",
1111
"check-branch-name": "./check_branch_name.sh",
1212
"prepare": "npx husky install && chmod +x .husky/* && chmod +x ./check_branch_name.sh",
13-
"test": "jest --silent"
13+
"test": "jest --silent --transformIgnorePatterns"
1414
},
1515
"dependencies": {
1616
"@coingecko/cryptoformat": "^0.5.4",
@@ -50,6 +50,7 @@
5050
"lodash.debounce": "^4.0.8",
5151
"lodash.uniqby": "^4.7.0",
5252
"lowlight": "^1.2.0",
53+
"msw": "^2.3.0",
5354
"next": "13.2.4",
5455
"next-i18next": "^13.2.2",
5556
"next-mdx-remote": "^4.4.1",
@@ -80,6 +81,7 @@
8081
"remark-unwrap-all-images": "^1.0.1",
8182
"sass": "^1.62.0",
8283
"typescript": "5.0.2",
84+
"undici": "^6.16.0",
8385
"unified": "^10.1.2",
8486
"unist-util-visit": "^2.0.0",
8587
"use-onclickoutside": "^0.4.1",

src/store/index.ts

Lines changed: 87 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,7 @@ export interface IRootState {
6262
web3Wallet: ReturnType<typeof web3WalletSlice.reducer>;
6363
store: ReturnType<typeof indexSlice.reducer>;
6464
auth: ReturnType<typeof authSlice.reducer>;
65-
coursesService: ReturnType<typeof coursesService.reducer>;
66-
communityService: ReturnType<typeof communityService.reducer>;
67-
walletService: ReturnType<typeof walletsService.reducer>;
68-
userService: ReturnType<typeof userSlice.reducer>;
6965
userReputations: ReturnType<typeof userReputationSlice.reducer>;
70-
userReputationService: ReturnType<typeof userReputationService.reducer>;
71-
userProfileService: ReturnType<typeof userProfileService.reducer>;
72-
notificationService: ReturnType<typeof notificationsService.reducer>;
73-
certificateService: ReturnType<typeof certificateService.reducer>;
74-
reputationProfileService: ReturnType<typeof reputationProfileService.reducer>;
75-
profileCommunitiesService: ReturnType<typeof profileCommunitiesService.reducer>;
76-
challengeService: ReturnType<typeof challengeService.reducer>;
77-
scoreboardService: ReturnType<typeof scoreboardService.reducer>;
78-
authService: ReturnType<typeof authService.reducer>;
79-
bountiesService: ReturnType<typeof bountiesService.reducer>;
8066
scoreboard: ReturnType<typeof scoreboardSlice.reducer>;
8167
bounties: ReturnType<typeof bountiesSlice.reducer>;
8268
submissions: ReturnType<typeof submissionsSlice.reducer>;
@@ -94,82 +80,103 @@ export interface IRootState {
9480
sumsubVerification: ReturnType<typeof sumsubVerificationSlice.reducer>;
9581
payouts: ReturnType<typeof payoutsSlice.reducer>;
9682
teams: ReturnType<typeof teamsSlice.reducer>;
97-
teamsService: ReturnType<typeof teamsService.reducer>;
9883
invites: ReturnType<typeof invitesSlice.reducer>;
9984
learningModuleService: ReturnType<typeof learningModulesService.reducer>;
10085
}
10186

87+
export type IRootService = {
88+
coursesService: ReturnType<typeof coursesService.reducer>;
89+
communityService: ReturnType<typeof communityService.reducer>;
90+
walletService: ReturnType<typeof walletsService.reducer>;
91+
userService: ReturnType<typeof userSlice.reducer>;
92+
userReputationService: ReturnType<typeof userReputationService.reducer>;
93+
userProfileService: ReturnType<typeof userProfileService.reducer>;
94+
notificationService: ReturnType<typeof notificationsService.reducer>;
95+
certificateService: ReturnType<typeof certificateService.reducer>;
96+
reputationProfileService: ReturnType<typeof reputationProfileService.reducer>;
97+
profileCommunitiesService: ReturnType<typeof profileCommunitiesService.reducer>;
98+
challengeService: ReturnType<typeof challengeService.reducer>;
99+
scoreboardService: ReturnType<typeof scoreboardService.reducer>;
100+
authService: ReturnType<typeof authService.reducer>;
101+
bountiesService: ReturnType<typeof bountiesService.reducer>;
102+
teamsService: ReturnType<typeof teamsService.reducer>;
103+
};
104+
105+
export const reducers = {
106+
[ui.name]: ui.reducer,
107+
[referralSlice.name]: referralSlice.reducer,
108+
[userSlice.name]: userSlice.reducer,
109+
[notificationsSlice.name]: notificationsSlice.reducer,
110+
[bannerSlice.name]: bannerSlice.reducer,
111+
[walletsSlice.name]: walletsSlice.reducer,
112+
[indexSlice.name]: indexSlice.reducer,
113+
[authSlice.name]: authSlice.reducer,
114+
[authService.reducerPath]: authService.reducer,
115+
[courseSlice.name]: courseSlice.reducer,
116+
[navigationSlice.name]: navigationSlice.reducer,
117+
[submissionsSlice.name]: submissionsSlice.reducer,
118+
[eventsSlice.name]: eventsSlice.reducer,
119+
[bountiesSlice.name]: bountiesSlice.reducer,
120+
[communitySlice.name]: communitySlice.reducer,
121+
[learningModulesSlice.name]: learningModulesSlice.reducer,
122+
[userProfileSlice.name]: userProfileSlice.reducer,
123+
[userReputationSlice.name]: userReputationSlice.reducer,
124+
[feedbackSlice.name]: feedbackSlice.reducer,
125+
[challengeSlice.name]: challengeSlice.reducer,
126+
[web3WalletSlice.name]: web3WalletSlice.reducer,
127+
[communityService.reducerPath]: communityService.reducer,
128+
[bountiesService.reducerPath]: bountiesService.reducer,
129+
[coursesService.reducerPath]: coursesService.reducer,
130+
[certificateService.reducerPath]: certificateService.reducer,
131+
[walletsService.reducerPath]: walletsService.reducer,
132+
[reputationProfileService.reducerPath]: reputationProfileService.reducer,
133+
[profileCommunitiesService.reducerPath]: profileCommunitiesService.reducer,
134+
[userService.reducerPath]: userService.reducer,
135+
[userProfileService.reducerPath]: userProfileService.reducer,
136+
[userReputationService.reducerPath]: userReputationService.reducer,
137+
[referralsService.reducerPath]: referralsService.reducer,
138+
[notificationsService.reducerPath]: notificationsService.reducer,
139+
[scoreboardSlice.name]: scoreboardSlice.reducer,
140+
[certificateSlice.name]: certificateSlice.reducer,
141+
[userReferralsSlice.name]: userReferralsSlice.reducer,
142+
[sumsubVerificationSlice.name]: sumsubVerificationSlice.reducer,
143+
[payoutsSlice.name]: payoutsSlice.reducer,
144+
[teamsSlice.name]: teamsSlice.reducer,
145+
[teamsService.reducerPath]: teamsService.reducer,
146+
[challengeService.reducerPath]: challengeService.reducer,
147+
[scoreboardService.reducerPath]: scoreboardService.reducer,
148+
[invitesSlice.name]: invitesSlice.reducer,
149+
[communitiesProfile.name]: communitiesProfile.reducer,
150+
[reputationSlice.name]: reputationSlice.reducer,
151+
};
152+
153+
export const middlewares = [
154+
coursesService.middleware,
155+
communityService.middleware,
156+
walletsService.middleware,
157+
userService.middleware,
158+
referralsService.middleware,
159+
notificationsService.middleware,
160+
userProfileService.middleware,
161+
bountiesService.middleware,
162+
certificateService.middleware,
163+
reputationProfileService.middleware,
164+
profileCommunitiesService.middleware,
165+
userReputationService.middleware,
166+
authService.middleware,
167+
teamsService.middleware,
168+
challengeService.middleware,
169+
scoreboardService.middleware,
170+
];
171+
102172
export const makeStore = () =>
103173
configureStore({
104174
reducer: {
105-
[ui.name]: ui.reducer,
106-
[referralSlice.name]: referralSlice.reducer,
107-
[userSlice.name]: userSlice.reducer,
108-
[notificationsSlice.name]: notificationsSlice.reducer,
109-
[bannerSlice.name]: bannerSlice.reducer,
110-
[walletsSlice.name]: walletsSlice.reducer,
111-
[indexSlice.name]: indexSlice.reducer,
112-
[authSlice.name]: authSlice.reducer,
113-
[authService.reducerPath]: authService.reducer,
114-
[courseSlice.name]: courseSlice.reducer,
115-
[navigationSlice.name]: navigationSlice.reducer,
116-
[submissionsSlice.name]: submissionsSlice.reducer,
117-
[eventsSlice.name]: eventsSlice.reducer,
118-
[bountiesSlice.name]: bountiesSlice.reducer,
119-
[communitySlice.name]: communitySlice.reducer,
120-
[learningModulesSlice.name]: learningModulesSlice.reducer,
121-
[userProfileSlice.name]: userProfileSlice.reducer,
122-
[userReputationSlice.name]: userReputationSlice.reducer,
123-
[feedbackSlice.name]: feedbackSlice.reducer,
124-
[challengeSlice.name]: challengeSlice.reducer,
125-
[web3WalletSlice.name]: web3WalletSlice.reducer,
126-
[communityService.reducerPath]: communityService.reducer,
127-
[bountiesService.reducerPath]: bountiesService.reducer,
128-
[coursesService.reducerPath]: coursesService.reducer,
129-
[certificateService.reducerPath]: certificateService.reducer,
130-
[walletsService.reducerPath]: walletsService.reducer,
131-
[reputationProfileService.reducerPath]: reputationProfileService.reducer,
132-
[profileCommunitiesService.reducerPath]: profileCommunitiesService.reducer,
133-
[userService.reducerPath]: userService.reducer,
134-
[userProfileService.reducerPath]: userProfileService.reducer,
135-
[userReputationService.reducerPath]: userReputationService.reducer,
136-
[referralsService.reducerPath]: referralsService.reducer,
137-
[notificationsService.reducerPath]: notificationsService.reducer,
138-
[scoreboardSlice.name]: scoreboardSlice.reducer,
139-
[certificateSlice.name]: certificateSlice.reducer,
140-
[userReferralsSlice.name]: userReferralsSlice.reducer,
141-
[sumsubVerificationSlice.name]: sumsubVerificationSlice.reducer,
142-
[payoutsSlice.name]: payoutsSlice.reducer,
143-
[teamsSlice.name]: teamsSlice.reducer,
144-
[teamsService.reducerPath]: teamsService.reducer,
145-
[challengeService.reducerPath]: challengeService.reducer,
146-
[scoreboardService.reducerPath]: scoreboardService.reducer,
147-
[invitesSlice.name]: invitesSlice.reducer,
148-
[communitiesProfile.name]: communitiesProfile.reducer,
149-
[reputationSlice.name]: reputationSlice.reducer,
150-
[learningModulesService.reducerPath]: learningModulesService.reducer,
175+
...reducers,
151176
},
152177

153178
middleware: (getDefaultMiddleware) => {
154-
return getDefaultMiddleware().concat(
155-
coursesService.middleware,
156-
communityService.middleware,
157-
walletsService.middleware,
158-
userService.middleware,
159-
referralsService.middleware,
160-
notificationsService.middleware,
161-
userProfileService.middleware,
162-
bountiesService.middleware,
163-
certificateService.middleware,
164-
reputationProfileService.middleware,
165-
profileCommunitiesService.middleware,
166-
userReputationService.middleware,
167-
authService.middleware,
168-
teamsService.middleware,
169-
challengeService.middleware,
170-
scoreboardService.middleware,
171-
learningModulesService.middleware
172-
);
179+
return getDefaultMiddleware().concat(...middlewares);
173180
},
174181
});
175182

0 commit comments

Comments
 (0)