Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { fireEvent } from "@testing-library/dom";
import { cleanup } from "@testing-library/react";

import { PointsSystemAdministration }
from "components/administration/points-system-administration/points-system-administration.controller";

import { useBulkUpdatePointsBase } from "x-hooks/api/points";

import { render } from "__tests__/utils/custom-render";

jest.mock("x-hooks/api/points", () => ({
useBulkUpdatePointsBase: jest.fn(),
useGetPointsBase: jest.fn().mockReturnValue([
{ id: 1, actionName: "action1", scalingFactor: 1, pointsPerAction: 1, counter: "1" },
{ id: 2, actionName: "action2", scalingFactor: 1, pointsPerAction: 1, counter: "1" },
])
}))

describe("PointsSystemAdministration", () => {
beforeEach(() => {
cleanup();
jest.clearAllMocks();
});

it("Should bulk update scalingFactor successfully", async () => {
const result = render(<PointsSystemAdministration />);

const scalingFactorInput = result.getByTestId("scaling-factor-input");
fireEvent.change(scalingFactorInput, { target: { value: "2" } });

const updateAllButton = result.getByTestId("update-all-button");
fireEvent.click(updateAllButton);

expect(useBulkUpdatePointsBase).toHaveBeenCalledWith({
rows: [
{ id: 1, actionName: "action1", scalingFactor: "2" },
{ id: 2, actionName: "action2", scalingFactor: "2" },
]
});
});

it("Should update changed rows successfully", async () => {
const result = render(<PointsSystemAdministration />);

const scalingFactorRow1 = result.getByTestId("table-row-0-scalingFactor-input");
fireEvent.change(scalingFactorRow1, { target: { value: "3" } });

const counterRow2 = result.getByTestId("table-row-1-counter-input");
fireEvent.change(counterRow2, { target: { value: "3" } });

const saveChangesButton = result.getByTestId("save-changes-button");
fireEvent.click(saveChangesButton);

expect(useBulkUpdatePointsBase).toHaveBeenCalledWith({
rows: [
{ id: 1, actionName: "action1", scalingFactor: "3", pointsPerAction: 1, counter: "1" },
{ id: 2, actionName: "action2", scalingFactor: 1, pointsPerAction: 1, counter: "3" },
]
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import models from "db/models";

import { bulkUpdatePointsBase } from "server/common/points-base/bulk-update/bulk-update-points-base";
import { HttpBadRequestError } from "server/errors/http-errors";

jest.mock("db/models", () => ({
pointsBase: {
update: jest.fn()
}
}));

describe("BulkUpdatePointsBase", () => {
let request = null;

beforeEach(() => {
jest.clearAllMocks();
request = {
body: {
rows: [
{
id: 1,
actionName: "action1",
scalingFactor: 1,
pointsPerAction: 1,
counter: "1"
}
]
}
}
});

it("Should update sucessfully", async () => {
await bulkUpdatePointsBase(request);
expect(models.pointsBase.update)
.toHaveBeenCalledWith({
scalingFactor: 1,
pointsPerAction: 1,
counter: "1"
}, {
where: {
id: 1
}
});
});

it("Should throws because no rows was sent", async () => {
request.body = {};
await expect(() =>
bulkUpdatePointsBase(request)).rejects.toThrow(new HttpBadRequestError("Missing rows to update"));
});

it("Should throws because id was not provided", async () => {
request.body = {
rows: [
{
actionName: "action1",
scalingFactor: 1,
pointsPerAction: 1,
counter: "1"
}
]
};
await expect(() =>
bulkUpdatePointsBase(request)).rejects.toThrow(new HttpBadRequestError("Missing paramaters for action1"));
});

it("Should throws because no changed column was provided", async () => {
request.body = {
rows: [
{
id: 1,
actionName: "action1"
}
]
};
await expect(() =>
bulkUpdatePointsBase(request)).rejects.toThrow(new HttpBadRequestError("Missing paramaters for action1"));
});

it("Should throws because scalingFactor is invalid", async () => {
request.body = {
rows: [
{
id: 1,
actionName: "action1",
scalingFactor: 0,
}
]
};
await expect(() =>
bulkUpdatePointsBase(request)).rejects.toThrow(new HttpBadRequestError("Invalid paramaters for action1"));
});

it("Should throws because pointsPerAction is invalid", async () => {
request.body = {
rows: [
{
id: 1,
actionName: "action1",
pointsPerAction: 0,
}
]
};
await expect(() =>
bulkUpdatePointsBase(request)).rejects.toThrow(new HttpBadRequestError("Invalid paramaters for action1"));
});

it("Should throws because counter is invalid", async () => {
request.body = {
rows: [
{
id: 1,
actionName: "action1",
counter: "B",
}
]
};
await expect(() =>
bulkUpdatePointsBase(request)).rejects.toThrow(new HttpBadRequestError("Invalid paramaters for action1"));
});
});
63 changes: 63 additions & 0 deletions __tests__/server/common/user/update-user-about.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {NextApiRequest} from "next";

import {updateUserAbout} from "server/common/user/update-user-about";
import {HttpBadRequestError} from "server/errors/http-errors";

jest.mock('server/utils/jwt', () => ({
UserRoleUtils: {
hasAdminRole: jest.fn(),
},
}));

jest.mock('db/models', () => ({
pointsEvents: {
findOne: jest.fn(),
},
}));

jest.mock('server/common/user/get-user-by-address', () => ({getUserByAddress: jest.fn()}));
jest.mock('services/logging', () => ({Logger: jest.fn()}));
jest.mock('server/utils/points-system/add-point-entry', () => ({addPointEntry: jest.fn().mockResolvedValue("")}));
jest.mock('server/utils/points-system/remove-point-entry', () => ({removePointEntry: jest.fn().mockResolvedValue("")}));

describe('updateUserAbout', () => {
let mockRequest: NextApiRequest;

beforeEach(() => {
mockRequest = {
query: {address: "0x0"},
body: {
context: {
user: {
update: jest.fn(),
save: jest.fn(),
}
}
},
} as unknown as NextApiRequest;
})

it("Fails because no `about` on body", async () => {
await expect(updateUserAbout(mockRequest)).rejects.toThrow(HttpBadRequestError);
});

it("Fails because no `body.about` > 512 throws", async () => {
mockRequest.body.about = Array(514).join("a");
await expect(updateUserAbout(mockRequest)).rejects.toThrow(HttpBadRequestError);
});

it("Succeeds with `body.about` empty string", async () => {
mockRequest.body.about = "";
await updateUserAbout(mockRequest);
expect(mockRequest.body.context.user.update).toHaveBeenCalled();
expect(mockRequest.body.context.user.save).toHaveBeenCalled();
});

it("Succeeds with `body.about` string", async () => {
mockRequest.body.about = "My about";
await updateUserAbout(mockRequest);
expect(mockRequest.body.context.user.update).toHaveBeenCalled();
expect(mockRequest.body.context.user.save).toHaveBeenCalled();
});

})
8 changes: 7 additions & 1 deletion __tests__/server/common/user/update-user-socials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ jest.mock('server/utils/jwt', () => ({
},
}));

jest.mock('server/utils/add-point-entry', () => ({addPointEntry: jest.fn().mockResolvedValue("")}));
jest.mock('db/models', () => ({
pointsEvents: {
findOne: jest.fn(),
},
}));

jest.mock('server/utils/points-system/add-point-entry', () => ({addPointEntry: jest.fn().mockResolvedValue("")}));
jest.mock('server/utils/points-system/remove-point-entry', () => ({addPointEntry: jest.fn().mockResolvedValue("")}));

describe('updateUserSocials', () => {
let mockRequest: NextApiRequest;
Expand Down
21 changes: 21 additions & 0 deletions assets/github-mark.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { SVGProps } from "react";

export default function GithubMark(props: SVGProps<SVGSVGElement>) {
return (
<svg
width="46"
height="44"
viewBox="0 0 46 44"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M22.5611 0C10.0854 0 0 10.0833 0 22.5578C0 32.5293 6.46207 40.97 15.4267 43.9574C16.5475 44.182 16.958 43.472 16.958 42.8748C16.958 42.3518 16.9211 40.5593 16.9211 38.6916C10.6451 40.0363 9.33821 36.0025 9.33821 36.0025C8.32962 33.3882 6.83521 32.7163 6.83521 32.7163C4.78109 31.3344 6.98484 31.3344 6.98484 31.3344C9.2634 31.4838 10.459 33.6499 10.459 33.6499C12.4757 37.0856 15.7255 36.1148 17.0328 35.5172C17.2194 34.0606 17.8175 33.0522 18.4524 32.4922C13.4469 31.9692 8.18046 30.0273 8.18046 21.3625C8.18046 18.8975 9.07637 16.8809 10.496 15.3125C10.272 14.7524 9.48737 12.4364 10.7204 9.33671C10.7204 9.33671 12.6254 8.73904 16.9206 11.6522C18.7596 11.1584 20.6561 10.9072 22.5611 10.9051C24.4661 10.9051 26.408 11.1668 28.2012 11.6522C32.4969 8.73904 34.4019 9.33671 34.4019 9.33671C35.6349 12.4364 34.8498 14.7524 34.6259 15.3125C36.0829 16.8809 36.9418 18.8975 36.9418 21.3625C36.9418 30.0273 31.6754 31.9316 26.6324 32.4922C27.4545 33.2017 28.1638 34.546 28.1638 36.6749C28.1638 39.6999 28.1269 42.1277 28.1269 42.8743C28.1269 43.472 28.5379 44.182 29.6582 43.9578C38.6228 40.9695 45.0849 32.5293 45.0849 22.5578C45.1218 10.0833 34.9995 0 22.5611 0Z"
fill="white"
/>
</svg>
);
}
20 changes: 5 additions & 15 deletions assets/icons/check-circle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,16 @@ import { SVGProps } from "react";
export default function CheckCircle(props: SVGProps<SVGSVGElement>) {
return (
<svg
width="108"
height="108"
viewBox="0 0 108 108"
width="30"
height="30"
viewBox="0 0 30 30"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
d="M72.5625 43.875L47.7984 67.5L35.4375 55.6875"
stroke="#4250E4"
strokeWidth="3"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M54 94.5C76.3675 94.5 94.5 76.3675 94.5 54C94.5 31.6325 76.3675 13.5 54 13.5C31.6325 13.5 13.5 31.6325 13.5 54C13.5 76.3675 31.6325 94.5 54 94.5Z"
stroke="#4250E4"
strokeWidth="3"
strokeLinecap="round"
strokeLinejoin="round"
d="M20.3508 11.5242C20.438 11.6113 20.5071 11.7147 20.5543 11.8285C20.6015 11.9423 20.6257 12.0643 20.6257 12.1875C20.6257 12.3107 20.6015 12.4327 20.5543 12.5465C20.5071 12.6603 20.438 12.7637 20.3508 12.8508L13.7883 19.4133C13.7012 19.5004 13.5978 19.5696 13.484 19.6168C13.3702 19.664 13.2482 19.6882 13.125 19.6882C13.0018 19.6882 12.8798 19.664 12.766 19.6168C12.6522 19.5696 12.5488 19.5004 12.4617 19.4133L9.64922 16.6008C9.47331 16.4249 9.37448 16.1863 9.37448 15.9375C9.37448 15.6887 9.47331 15.4501 9.64922 15.2742C9.82514 15.0983 10.0637 14.9995 10.3125 14.9995C10.5613 14.9995 10.7999 15.0983 10.9758 15.2742L13.125 17.4246L19.0242 11.5242C19.1113 11.4371 19.2147 11.3679 19.3285 11.3207C19.4423 11.2735 19.5643 11.2493 19.6875 11.2493C19.8107 11.2493 19.9327 11.2735 20.0465 11.3207C20.1603 11.3679 20.2637 11.4371 20.3508 11.5242ZM27.1875 15C27.1875 17.4105 26.4727 19.7668 25.1335 21.771C23.7944 23.7752 21.8909 25.3373 19.664 26.2598C17.437 27.1822 14.9865 27.4236 12.6223 26.9533C10.2582 26.4831 8.08659 25.3223 6.38214 23.6179C4.67769 21.9134 3.51694 19.7418 3.04668 17.3777C2.57643 15.0135 2.81778 12.563 3.74022 10.336C4.66267 8.10907 6.22477 6.20564 8.22899 4.86646C10.2332 3.52728 12.5895 2.8125 15 2.8125C18.2313 2.81591 21.3292 4.10104 23.6141 6.3859C25.899 8.67076 27.1841 11.7687 27.1875 15ZM25.3125 15C25.3125 12.9604 24.7077 10.9666 23.5745 9.27068C22.4414 7.5748 20.8308 6.25302 18.9464 5.47249C17.0621 4.69196 14.9886 4.48774 12.9881 4.88565C10.9877 5.28356 9.1502 6.26573 7.70797 7.70796C6.26574 9.15019 5.28357 10.9877 4.88566 12.9881C4.48775 14.9886 4.69197 17.0621 5.4725 18.9464C6.25303 20.8308 7.57481 22.4414 9.27069 23.5745C10.9666 24.7077 12.9604 25.3125 15 25.3125C17.7341 25.3094 20.3553 24.2219 22.2886 22.2886C24.2219 20.3553 25.3094 17.7341 25.3125 15Z"
fill="#2AB38A"
/>
</svg>
);
Expand Down
15 changes: 15 additions & 0 deletions assets/icons/github.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function Github() {
return <svg width="20" height="20" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg"
fill="none" stroke="#000000">
<g id="SVGRepo_iconCarrier">
<g id="Page-1" stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
<g id="Dribbble-Light-Preview" transform="translate(-140.000000, -7559.000000)" fill="#c4c7d3">
<g id="icons" transform="translate(56.000000, 160.000000)">
<path
d="M94,7399 C99.523,7399 104,7403.59 104,7409.253 C104,7413.782 101.138,7417.624 97.167,7418.981 C96.66,7419.082 96.48,7418.762 96.48,7418.489 C96.48,7418.151 96.492,7417.047 96.492,7415.675 C96.492,7414.719 96.172,7414.095 95.813,7413.777 C98.04,7413.523 100.38,7412.656 100.38,7408.718 C100.38,7407.598 99.992,7406.684 99.35,7405.966 C99.454,7405.707 99.797,7404.664 99.252,7403.252 C99.252,7403.252 98.414,7402.977 96.505,7404.303 C95.706,7404.076 94.85,7403.962 94,7403.958 C93.15,7403.962 92.295,7404.076 91.497,7404.303 C89.586,7402.977 88.746,7403.252 88.746,7403.252 C88.203,7404.664 88.546,7405.707 88.649,7405.966 C88.01,7406.684 87.619,7407.598 87.619,7408.718 C87.619,7412.646 89.954,7413.526 92.175,7413.785 C91.889,7414.041 91.63,7414.493 91.54,7415.156 C90.97,7415.418 89.522,7415.871 88.63,7414.304 C88.63,7414.304 88.101,7413.319 87.097,7413.247 C87.097,7413.247 86.122,7413.234 87.029,7413.87 C87.029,7413.87 87.684,7414.185 88.139,7415.37 C88.139,7415.37 88.726,7417.2 91.508,7416.58 C91.513,7417.437 91.522,7418.245 91.522,7418.489 C91.522,7418.76 91.338,7419.077 90.839,7418.982 C86.865,7417.627 84,7413.783 84,7409.253 C84,7403.59 88.478,7399 94,7399"></path>
</g>
</g>
</g>
</g>
</svg>
}
11 changes: 11 additions & 0 deletions assets/icons/linkedin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function Linkedin() {
return <svg fill="#c4c7d3" height="20" width="20" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg"
viewBox="-143 145 512 512">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
<g id="SVGRepo_iconCarrier">
<path
d="M113,145c-141.4,0-256,114.6-256,256s114.6,256,256,256s256-114.6,256-256S254.4,145,113,145z M41.4,508.1H-8.5V348.4h49.9 V508.1z M15.1,328.4h-0.4c-18.1,0-29.8-12.2-29.8-27.7c0-15.8,12.1-27.7,30.5-27.7c18.4,0,29.7,11.9,30.1,27.7 C45.6,316.1,33.9,328.4,15.1,328.4z M241,508.1h-56.6v-82.6c0-21.6-8.8-36.4-28.3-36.4c-14.9,0-23.2,10-27,19.6 c-1.4,3.4-1.2,8.2-1.2,13.1v86.3H71.8c0,0,0.7-146.4,0-159.7h56.1v25.1c3.3-11,21.2-26.6,49.8-26.6c35.5,0,63.3,23,63.3,72.4V508.1z "></path>
</g>
</svg>
}
19 changes: 19 additions & 0 deletions assets/icons/star-filled-icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { SVGProps } from "react";

export default function StarFilledIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
width="13"
height="13"
viewBox="0 0 13 13"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
d="M11.2494 5.86159L9.13536 7.70659L9.76864 10.4535C9.80216 10.5971 9.79259 10.7474 9.74115 10.8855C9.68971 11.0237 9.59868 11.1437 9.47943 11.2304C9.36018 11.3172 9.21801 11.3668 9.07069 11.3732C8.92337 11.3796 8.77744 11.3424 8.65114 11.2663L6.25536 9.81315L3.86474 11.2663C3.73844 11.3424 3.59251 11.3796 3.44519 11.3732C3.29787 11.3668 3.1557 11.3172 3.03645 11.2304C2.9172 11.1437 2.82617 11.0237 2.77473 10.8855C2.72329 10.7474 2.71373 10.5971 2.74724 10.4535L3.37958 7.7094L1.26505 5.86159C1.15321 5.76513 1.07234 5.6378 1.03258 5.49557C0.992813 5.35333 0.995931 5.20252 1.04154 5.06205C1.08714 4.92158 1.17321 4.7977 1.28894 4.70594C1.40467 4.61419 1.54491 4.55865 1.69208 4.54628L4.47927 4.30487L5.56724 1.70987C5.62405 1.57371 5.71989 1.4574 5.84267 1.37559C5.96545 1.29378 6.1097 1.25012 6.25724 1.25012C6.40478 1.25012 6.54902 1.29378 6.67181 1.37559C6.79459 1.4574 6.89042 1.57371 6.94724 1.70987L8.03849 4.30487L10.8247 4.54628C10.9719 4.55865 11.1122 4.61419 11.2279 4.70594C11.3436 4.7977 11.4297 4.92158 11.4753 5.06205C11.5209 5.20252 11.524 5.35333 11.4842 5.49557C11.4445 5.6378 11.3636 5.76513 11.2518 5.86159H11.2494Z"
fill="#FFDE6B"
/>
</svg>
);
}
19 changes: 19 additions & 0 deletions assets/icons/star-icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { SVGProps } from "react";

export default function StarIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
width="12"
height="13"
viewBox="0 0 12 13"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
d="M11.2129 5.0605C11.1675 4.92052 11.0819 4.797 10.9668 4.70531C10.8517 4.61363 10.7121 4.55783 10.5656 4.54487L7.78165 4.30487L6.6904 1.70987C6.63359 1.57371 6.53775 1.4574 6.41497 1.37559C6.29219 1.29378 6.14794 1.25012 6.0004 1.25012C5.85286 1.25012 5.70862 1.29378 5.58583 1.37559C5.46305 1.4574 5.36722 1.57371 5.3104 1.70987L4.22243 4.30487L1.43524 4.54628C1.28807 4.55865 1.14783 4.61419 1.0321 4.70594C0.91637 4.7977 0.830306 4.92158 0.7847 5.06205C0.739095 5.20252 0.735977 5.35333 0.77574 5.49557C0.815502 5.6378 0.896374 5.76513 1.00821 5.86159L3.12275 7.7094L2.48899 10.4535C2.45548 10.5971 2.46505 10.7474 2.51649 10.8855C2.56793 11.0237 2.65896 11.1437 2.77821 11.2304C2.89746 11.3172 3.03963 11.3668 3.18695 11.3732C3.33427 11.3796 3.4802 11.3424 3.60649 11.2663L5.99712 9.81315L8.3929 11.2663C8.5192 11.3424 8.66513 11.3796 8.81244 11.3732C8.95976 11.3668 9.10194 11.3172 9.22118 11.2304C9.34043 11.1437 9.43147 11.0237 9.48291 10.8855C9.53435 10.7474 9.54391 10.5971 9.5104 10.4535L8.87712 7.70659L10.9912 5.86159C11.103 5.7648 11.1837 5.63711 11.2232 5.49457C11.2626 5.35203 11.259 5.20101 11.2129 5.0605ZM10.4995 5.29487L8.3854 7.13987C8.28251 7.22937 8.20597 7.34523 8.16401 7.47499C8.12205 7.60474 8.11627 7.74348 8.14728 7.87628L8.78243 10.625L6.38853 9.1719C6.27173 9.10078 6.13762 9.06315 6.00087 9.06315C5.86412 9.06315 5.73001 9.10078 5.61321 9.1719L3.22259 10.625L3.85353 7.87815C3.88453 7.74536 3.87875 7.60662 3.83679 7.47686C3.79483 7.34711 3.71829 7.23125 3.6154 7.14175L1.5004 5.29768C1.50023 5.29628 1.50023 5.29487 1.5004 5.29347L4.28665 5.05253C4.42268 5.04054 4.55286 4.99163 4.66314 4.91109C4.77342 4.83055 4.85962 4.72143 4.91243 4.5955L6.0004 2.00378L7.0879 4.5955C7.14072 4.72143 7.22691 4.83055 7.33719 4.91109C7.44747 4.99163 7.57765 5.04054 7.71368 5.05253L10.5004 5.29347C10.5004 5.29347 10.5004 5.29628 10.5004 5.29675L10.4995 5.29487Z"
fill="currentColor"
/>
</svg>
);
}
Loading