forked from bepronetwork/web-network
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #427 from layerx-labs/dev
BEPRO 2.25
- Loading branch information
Showing
119 changed files
with
2,081 additions
and
1,120 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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
const mockAddSuccess = jest.fn(); | ||
const mockAddError = jest.fn(); | ||
const useToastStore = jest.fn(() => ({ | ||
addSuccess: mockAddSuccess | ||
addSuccess: mockAddSuccess, | ||
addError: mockAddError, | ||
})); | ||
|
||
export { | ||
useToastStore, | ||
mockAddSuccess | ||
mockAddSuccess, | ||
mockAddError, | ||
} |
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
65 changes: 65 additions & 0 deletions
65
__tests__/components/profile/avatar-form/avatar-form.controller.test.tsx
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,65 @@ | ||
import React from "react"; | ||
|
||
import { fireEvent, waitFor } from "@testing-library/dom"; | ||
import { useSession } from "next-auth/react"; | ||
|
||
import { AvatarForm } from "components/profile/avatar-form/avatar-form.controller"; | ||
|
||
import { useUpdateUserAvatar } from "x-hooks/api/user/use-update-user-avatar"; | ||
|
||
import { render } from "__tests__/utils/custom-render"; | ||
|
||
jest | ||
.mock("next-auth/react", () => ({ | ||
useSession: jest.fn().mockReturnValue({ | ||
update: jest.fn() | ||
}) | ||
})); | ||
|
||
jest | ||
.mock("x-hooks/stores/user/user.store", () => ({ | ||
useUserStore: jest.fn().mockReturnValue({ | ||
currentUser: { | ||
walletAddress: "0x000000000", | ||
}, | ||
}) | ||
})) | ||
|
||
jest | ||
.mock("x-hooks/api/user/use-update-user-avatar", () => ({ | ||
useUpdateUserAvatar: jest.fn(), | ||
})); | ||
|
||
describe("AvatarForm", () => { | ||
const avatarFile = new File(["avatar"], "avatar.png", { type: "image/png" }); | ||
window.URL.createObjectURL = jest.fn().mockReturnValue("url"); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("Should change user avatar", async () => { | ||
const result = render(<AvatarForm />); | ||
|
||
const editButton = result.getByTestId("user-edit-icon-btn"); | ||
await fireEvent.click(editButton); | ||
|
||
const avatarInput = result.getByTestId("Avatar"); | ||
|
||
await waitFor(() => { | ||
fireEvent.change(avatarInput, { | ||
target: { files: [avatarFile] }, | ||
}); | ||
}); | ||
|
||
const saveButton = result.getByTestId("update-avatar-button"); | ||
await fireEvent.click(saveButton); | ||
|
||
expect(useSession().update).toHaveBeenCalled(); | ||
expect(useUpdateUserAvatar) | ||
.toHaveBeenCalledWith({ | ||
address: "0x000000000", | ||
avatar: avatarFile | ||
}); | ||
}); | ||
}); |
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,78 @@ | ||
import { NextApiRequest } from "next"; | ||
|
||
import IpfsStorage from "services/ipfs-service"; | ||
|
||
import { updateUserAvatar } from "server/common/user/update-user-avatar"; | ||
import { HttpBadRequestError } from "server/errors/http-errors"; | ||
|
||
jest | ||
.mock("services/ipfs-service", () => ({ | ||
add: jest.fn().mockResolvedValue({ hash: "hash" }), | ||
})); | ||
|
||
jest | ||
.mock("services/logging", () => ({ | ||
Logger: { | ||
error: jest.fn() | ||
} | ||
})); | ||
|
||
jest | ||
.mock('server/utils/points-system/add-point-entry', () => ({ | ||
addPointEntry: jest.fn().mockResolvedValue("") | ||
})); | ||
|
||
describe("UpdateUserAvatar", () => { | ||
let mockRequest: NextApiRequest; | ||
|
||
beforeEach(() => { | ||
mockRequest = { | ||
body: { | ||
files: [ | ||
{ | ||
fileName: "avatar.png", | ||
fileData: "data:image/png,sadF#2fasdFQfqefasdf", | ||
} | ||
], | ||
context: { | ||
user: { | ||
avatar: null, | ||
save: jest.fn(), | ||
} | ||
} | ||
}, | ||
} as unknown as NextApiRequest; | ||
}); | ||
|
||
it("Should update user avatar successfully", async () => { | ||
await updateUserAvatar(mockRequest); | ||
|
||
expect(IpfsStorage.add).toHaveBeenCalled(); | ||
expect(mockRequest.body.context.user.avatar).toBe("hash"); | ||
expect(mockRequest.body.context.user.save).toHaveBeenCalled(); | ||
}); | ||
|
||
it("Should throw because no files were provided", async () => { | ||
mockRequest.body.files = null; | ||
await expect(() => updateUserAvatar(mockRequest)) | ||
.rejects | ||
.toBeInstanceOf(HttpBadRequestError); | ||
|
||
mockRequest.body.files = []; | ||
await expect(() => updateUserAvatar(mockRequest)) | ||
.rejects | ||
.toBeInstanceOf(HttpBadRequestError); | ||
}); | ||
|
||
it("Should throw because file type is invalid", async () => { | ||
mockRequest.body.files = [ | ||
{ | ||
fileName: "avatar.svg", | ||
fileData: "data:image/svg,sadF#2fasdFQfqefasdf", | ||
} | ||
]; | ||
await expect(() => updateUserAvatar(mockRequest)) | ||
.rejects | ||
.toBeInstanceOf(HttpBadRequestError); | ||
}); | ||
}); |
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,9 @@ | ||
import { SVGProps } from "react"; | ||
|
||
export default function LightningIcon(props: SVGProps<SVGSVGElement>) { | ||
return ( | ||
<svg width="18" height="24" viewBox="0 0 18 24" fill="none" xmlns="http://www.w3.org/2000/svg" {...props}> | ||
<path d="M17.2303 11.0785C17.2019 10.9583 17.1443 10.8469 17.0625 10.7544C16.9807 10.6618 16.8774 10.5908 16.7616 10.5478L11.3607 8.5219L12.735 1.64721C12.7662 1.48748 12.7445 1.32197 12.6733 1.17564C12.6021 1.0293 12.4852 0.910102 12.3403 0.836016C12.1954 0.76193 12.0304 0.73698 11.8701 0.764931C11.7097 0.792882 11.5629 0.872217 11.4516 0.990965L0.951594 12.241C0.866314 12.3308 0.804621 12.4404 0.772028 12.5599C0.739435 12.6795 0.736955 12.8052 0.764812 12.9259C0.792669 13.0466 0.849993 13.1585 0.931665 13.2517C1.01334 13.3448 1.11681 13.4163 1.23284 13.4597L6.63566 15.4857L5.26503 22.3528C5.23391 22.5126 5.25558 22.6781 5.32679 22.8244C5.39799 22.9708 5.51485 23.09 5.65974 23.164C5.80464 23.2381 5.96969 23.2631 6.13001 23.2351C6.29032 23.2072 6.4372 23.1278 6.54847 23.0091L17.0485 11.7591C17.1322 11.6692 17.1926 11.5601 17.2243 11.4415C17.256 11.3228 17.2581 11.1981 17.2303 11.0785ZM7.25347 20.0625L8.23503 15.1519C8.27016 14.9777 8.24232 14.7968 8.15648 14.6412C8.07063 14.4857 7.93236 14.3656 7.76628 14.3025L2.81253 12.4416L10.7457 3.94221L9.76503 8.85284C9.7299 9.027 9.75774 9.20797 9.84358 9.36352C9.92943 9.51907 10.0677 9.6391 10.2338 9.70222L15.1838 11.5585L7.25347 20.0625Z" fill="white" /> | ||
</svg> | ||
); | ||
} |
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
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
Oops, something went wrong.