-
Notifications
You must be signed in to change notification settings - Fork 71
feature/test-nft #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feature/test-nft #194
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,101 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import NFTRepository from "../../../repositories/nft.repository"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // filepath: src/modules/nft/_tests_/application/repository/repository.test.ts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Note: We recommend installing an extension to run jest tests. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe("NFTRepository - reference-related operations", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let repository: any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mockModel: any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mockPrisma: any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| beforeEach(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repository = new NFTRepository(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockModel = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| findUnique: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| findMany: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| delete: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add missing Prisma count mock.
mockModel = {
create: jest.fn(),
findUnique: jest.fn(),
findMany: jest.fn(),
delete: jest.fn(),
+ count: jest.fn(),
};π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Some codebases use nft while others nFT for the Prisma model accessor. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Provide both to make tests resilient to either shape. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockPrisma = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nft: mockModel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nFT: mockModel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Inject the mocked prisma into the repository instance regardless of how it's referenced inside. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (repository as any).prisma = mockPrisma; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("should expose CRUD methods", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(typeof repository.createNFT).toBe("function"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(typeof repository.getNFTById).toBe("function"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(typeof repository.getNFTByUserId).toBe("function"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(typeof repository.deleteNFT).toBe("function"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+32
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method names donβt exist on NFTRepository. The repository exposes - expect(typeof repository.createNFT).toBe("function");
- expect(typeof repository.getNFTById).toBe("function");
- expect(typeof repository.getNFTByUserId).toBe("function");
- expect(typeof repository.deleteNFT).toBe("function");
+ expect(typeof repository.create).toBe("function");
+ expect(typeof repository.findById).toBe("function");
+ expect(typeof repository.findByUserId).toBe("function");
+ expect(typeof repository.delete).toBe("function");π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("createNFT() - creates an NFT and returns its reference", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const payload = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| userId: "user-1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| organizationId: "org-1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: "An NFT for testing", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isMinted: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const created = { id: "nft-1", ...payload }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockModel.create.mockResolvedValue(created); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await repository.createNFT(payload); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockModel.create).toHaveBeenCalled(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Common Prisma pattern: create({ data: payload }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockModel.create.mock.calls[0][0]).toEqual(expect.objectContaining({ data: payload })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(result).toEqual(created); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+39
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align create test with repository contract and domain mapping.
- it("createNFT() - creates an NFT and returns its reference", async () => {
+ it("create() - creates an NFT and returns mapped domain entity", async () => {
const payload = {
userId: "user-1",
organizationId: "org-1",
description: "An NFT for testing",
- isMinted: false,
};
- const created = { id: "nft-1", ...payload };
+ const created = { id: "nft-1", ...payload };
mockModel.create.mockResolvedValue(created);
- const result = await repository.createNFT(payload);
+ const result = await repository.create(payload);
- expect(mockModel.create).toHaveBeenCalled();
- // Common Prisma pattern: create({ data: payload })
- expect(mockModel.create.mock.calls[0][0]).toEqual(expect.objectContaining({ data: payload }));
- expect(result).toEqual(created);
+ expect(mockModel.create).toHaveBeenCalledWith(expect.objectContaining({ data: payload }));
+ expect(result).toMatchObject({
+ id: created.id,
+ userId: payload.userId,
+ organizationId: payload.organizationId,
+ description: payload.description,
+ });
});π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("getNFTById() - retrieves an NFT using its ID", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const nft = { id: "nft-2", userId: "user-2", description: "by id" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockModel.findUnique.mockResolvedValue(nft); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await repository.getNFTById("nft-2"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockModel.findUnique).toHaveBeenCalled(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Common Prisma pattern: findUnique({ where: { id } }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockModel.findUnique.mock.calls[0][0]).toEqual(expect.objectContaining({ where: { id: "nft-2" } })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(result).toEqual(nft); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the correct read method and assert on mapped entity. Method is - it("getNFTById() - retrieves an NFT using its ID", async () => {
+ it("findById() - retrieves an NFT using its ID", async () => {
const nft = { id: "nft-2", userId: "user-2", description: "by id" };
mockModel.findUnique.mockResolvedValue(nft);
- const result = await repository.getNFTById("nft-2");
+ const result = await repository.findById("nft-2");
expect(mockModel.findUnique).toHaveBeenCalled();
// Common Prisma pattern: findUnique({ where: { id } })
expect(mockModel.findUnique.mock.calls[0][0]).toEqual(expect.objectContaining({ where: { id: "nft-2" } }));
- expect(result).toEqual(nft);
+ expect(result).toMatchObject(nft);
});π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("getNFTByUserId() - retrieves NFTs owned by a specific user", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const nfts = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { id: "nft-a", userId: "owner-1", description: "A" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { id: "nft-b", userId: "owner-1", description: "B" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockModel.findMany.mockResolvedValue(nfts); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await repository.getNFTByUserId("owner-1"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockModel.findMany).toHaveBeenCalled(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Common Prisma pattern: findMany({ where: { userId } }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockModel.findMany.mock.calls[0][0]).toEqual(expect.objectContaining({ where: { userId: "owner-1" } })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(result).toEqual(nfts); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+70
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Account for pagination and total count in
- it("getNFTByUserId() - retrieves NFTs owned by a specific user", async () => {
+ it("findByUserId() - retrieves NFTs owned by a specific user with pagination", async () => {
const nfts = [
{ id: "nft-a", userId: "owner-1", description: "A" },
{ id: "nft-b", userId: "owner-1", description: "B" },
];
mockModel.findMany.mockResolvedValue(nfts);
+ mockModel.count.mockResolvedValue(nfts.length);
- const result = await repository.getNFTByUserId("owner-1");
+ const result = await repository.findByUserId("owner-1", 1, 2);
expect(mockModel.findMany).toHaveBeenCalled();
- // Common Prisma pattern: findMany({ where: { userId } })
- expect(mockModel.findMany.mock.calls[0][0]).toEqual(expect.objectContaining({ where: { userId: "owner-1" } }));
- expect(result).toEqual(nfts);
+ expect(mockModel.findMany.mock.calls[0][0]).toEqual(
+ expect.objectContaining({
+ where: { userId: "owner-1" },
+ skip: 0,
+ take: 2,
+ orderBy: { createdAt: "desc" },
+ })
+ );
+ expect(mockModel.count).toHaveBeenCalledWith({ where: { userId: "owner-1" } });
+ expect(result.total).toBe(nfts.length);
+ expect(result.nfts).toHaveLength(nfts.length);
+ expect(result.nfts[0]).toMatchObject(nfts[0]);
});π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("deleteNFT() - removes an NFT and ensures it is no longer retrievable", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const deleted = { id: "nft-del", userId: "owner-del", description: "to be deleted" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockModel.delete.mockResolvedValue(deleted); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await repository.deleteNFT("nft-del"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockModel.delete).toHaveBeenCalled(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Common Prisma pattern: delete({ where: { id } }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockModel.delete.mock.calls[0][0]).toEqual(expect.objectContaining({ where: { id: "nft-del" } })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(result).toEqual(deleted); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Simulate subsequent retrieval returns null (not found) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockModel.findUnique.mockResolvedValueOnce(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const afterDelete = await repository.getNFTById("nft-del"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(afterDelete).toBeNull(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+85
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Method is - it("deleteNFT() - removes an NFT and ensures it is no longer retrievable", async () => {
+ it("delete() - removes an NFT and ensures it is no longer retrievable", async () => {
const deleted = { id: "nft-del", userId: "owner-del", description: "to be deleted" };
mockModel.delete.mockResolvedValue(deleted);
- const result = await repository.deleteNFT("nft-del");
+ await repository.delete("nft-del");
expect(mockModel.delete).toHaveBeenCalled();
// Common Prisma pattern: delete({ where: { id } })
- expect(mockModel.delete.mock.calls[0][0]).toEqual(expect.objectContaining({ where: { id: "nft-del" } }));
- expect(result).toEqual(deleted);
+ expect(mockModel.delete.mock.calls[0][0]).toEqual(expect.objectContaining({ where: { id: "nft-del" } }));
// Simulate subsequent retrieval returns null (not found)
mockModel.findUnique.mockResolvedValueOnce(null);
- const afterDelete = await repository.getNFTById("nft-del");
+ const afterDelete = await repository.findById("nft-del");
expect(afterDelete).toBeNull();
});π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π‘ Verification agent
π§© Analysis chain
Fix import: repository exports are named, not default.
nft.repository.tsexposesexport class NFTRepository, not a default export. Use a named import.Apply:
Verify with:
π Script executed:
Length of output: 749
Fix import to use named export for NFTRepository
src/modules/nft/__tests__/application/repository/repository.test.tscurrently importsNFTRepositoryas a default export, butsrc/modules/nft/repositories/nft.repository.tsexports it by name. Update as follows:π Committable suggestion
π€ Prompt for AI Agents