Skip to content

Commit 82e266d

Browse files
committed
refactor: 💡 fix tests
1 parent fbaebb6 commit 82e266d

9 files changed

Lines changed: 23 additions & 18 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

backend/test/controllers/users-controller.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ describe("UsersController", () => {
9191
(user as any).id = 1;
9292
userService.mocks.findUserWithCredentials.mockResolvedValue(user);
9393

94+
userService.mocks.getUser.mockResolvedValue({
95+
firstName: "firstName",
96+
lastName: "lastName",
97+
});
98+
9499
const token = "token";
95100
userService.mocks.generateLoginToken.mockReturnValue(token);
96101
const response = await controller.login({
@@ -111,6 +116,10 @@ describe("UsersController", () => {
111116
user.role = UserRole.Moderator;
112117
userService.mocks.findUserWithCredentials.mockResolvedValue(user);
113118
userService.mocks.generateLoginToken.mockReturnValue("token");
119+
userService.mocks.getUser.mockResolvedValue({
120+
firstName: "firstName",
121+
lastName: "lastName",
122+
});
114123
const response = await controller.login({
115124
data: {
116125
email: "test@foo.bar",
@@ -143,6 +152,10 @@ describe("UsersController", () => {
143152
const user = new User();
144153
user.role = role;
145154
userService.mocks.generateLoginToken.mockReturnValue(token);
155+
userService.mocks.getUser.mockResolvedValue({
156+
firstName: "firstname",
157+
lastName: "lastName",
158+
});
146159
const response = await controller.refreshLoginToken(user);
147160
expect(response.token).toBe(token);
148161
expect(response.user.role).toBe(role);

backend/test/services/mock/mock-user-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ export const MockUserService = jest.fn(
2020
verifyUserByVerifyToken: jest.fn(),
2121
verifyUserResetPassword: jest.fn(),
2222
forgotPassword: jest.fn(),
23+
getUser: jest.fn(),
2324
}),
2425
);

frontend/src/components/base/text-input.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ const Area = styled.textarea`
1818
resize: vertical;
1919
`;
2020

21-
const Input = styled.input`
22-
${FieldStyle}
23-
`;
24-
2521
/**
2622
* The type of the text input.
2723
*/
@@ -63,13 +59,9 @@ export const TextInput = ({
6359
type = TextInputType.Text,
6460
autoFocus = false,
6561
mandatory,
66-
min,
67-
max,
6862
maxLength = 1024,
69-
allowDecimals,
7063
isDisabled = false,
7164
name,
72-
autoCompleteField,
7365
description,
7466
rows,
7567
}: ITextInputProps) => {
@@ -112,6 +104,7 @@ export const TextInput = ({
112104
variant="outlined"
113105
label={description}
114106
fullWidth
107+
focused={isFocused}
115108
{...fieldProps}
116109
/>
117110
</div>

frontend/src/components/forms/country-question.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export const countryNames = countries.map(({ country }) => country).sort();
1515

1616
interface ICountryQuestionProps {
1717
question: QuestionDTO<CountryQuestionConfigurationDTO>;
18-
value: string;
19-
onChange: (value: string) => any;
18+
valueInput: string;
19+
onChange: (event: React.SyntheticEvent, value: string) => any;
2020
isDisabled?: boolean;
2121
}
2222

@@ -25,13 +25,14 @@ interface ICountryQuestionProps {
2525
* Basically a choices question, but separating it allows better visualization.
2626
*/
2727
export const CountryQuestion = ({
28-
value,
28+
valueInput,
2929
onChange,
3030
question,
3131
isDisabled,
3232
}: ICountryQuestionProps) => {
3333
const handleChange = useCallback(
34-
(event: React.SyntheticEvent, value: string | null) => onChange(value!),
34+
(event: React.SyntheticEvent, value: string | null) =>
35+
onChange(event, value!),
3536
[onChange],
3637
);
3738

@@ -47,7 +48,7 @@ export const CountryQuestion = ({
4748
)}
4849
disabled={isDisabled}
4950
onChange={handleChange}
50-
value={value}
51+
value={valueInput}
5152
/>
5253
</FormField>
5354
</div>

frontend/src/components/forms/unified-question.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const Question = ({
6565
<CountryQuestion
6666
question={question as QuestionDTO<CountryQuestionConfigurationDTO>}
6767
onChange={onChange}
68-
value={value}
68+
valueInput={value}
6969
isDisabled={isDisabled}
7070
/>
7171
);

frontend/src/components/pages/statistics.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { InternalLink } from "../base/link";
2020
import { Text } from "../base/text";
2121
import { TimeChart } from "../base/time-chart";
2222
import { TitledNumber } from "../base/titled-number";
23-
import { WorldMap } from "../base/worldmap";
2423
import { Page } from "./page";
2524
import { SimpleCard } from "../base/simple-card";
2625
import { Grid } from "@mui/material";
@@ -212,7 +211,6 @@ export const Statistics = () => {
212211
}, [safeApplications]);
213212

214213
const statistics = allQuestions.map(({ id, configuration, title }) => {
215-
const key = `${title}-${id}`;
216214
const counts = answersByQuestionID[id!];
217215

218216
if (!counts) {

frontend/src/components/routers/sidebar/sidebar-menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const SidebarMenuItem = ({
6161
children,
6262
}: ISidebarMenuItemProps) => (
6363
<LI>
64-
<Link to={to} exact onClick={onClick}>
64+
<Link to={to!} exact onClick={onClick}>
6565
{children}
6666
</Link>
6767
</LI>

frontend/src/components/settings/form-editor.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { FormSettingsDTO, QuestionDTO } from "../../api/types/dto";
55
import { QuestionType } from "../../api/types/enums";
66
import { moveArrayItemDown, moveArrayItemUp } from "../../util";
77
import { Button } from "../base/button";
8-
import { Divider } from "../base/divider";
98
import { Elevated } from "../base/elevated";
109
import { FlexColumnContainer, Spacer } from "../base/flex";
1110
import { FormFieldButton } from "../base/form-field-button";

0 commit comments

Comments
 (0)