-
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
Conversation
WalkthroughAdds a new Jest test suite validating NFTRepository CRUD methods (createNFT, getNFTById, getNFTByUserId, deleteNFT) using a mocked Prisma client supporting both nft and nFT accessors. Tests assert correct Prisma method invocations and simulate post-deletion retrieval returning null. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 7
🧹 Nitpick comments (4)
src/modules/nft/__tests__/application/repository/repository.test.ts (4)
3-4: Correct the file path comment.Minor mismatch may confuse editors and runners.
-// filepath: src/modules/nft/_tests_/application/repository/repository.test.ts +// filepath: src/modules/nft/__tests__/application/repository/repository.test.ts
7-9: Prefer typed repository for IDE help; keep any-cast only for prisma injection.- let repository: any; + let repository: NFTRepository; let mockModel: any; let mockPrisma: any;
21-30: Optional: keep only the accessor your schema actually generates.The implementation uses
nFT; keeping bothnftandnFTis fine, but unnecessary if the generator is consistent.
11-30: Consider DI for Prisma to avoid private-field mutation in tests.Inject
PrismaClientvia constructor (e.g.,constructor(private prisma = new PrismaClient()) {}) to remove(repository as any).prisma = ...and enable cleaner mocking.Happy to provide a small refactor PR for constructor-based DI plus updated tests.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/modules/nft/__tests__/application/repository/repository.test.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/modules/nft/__tests__/application/repository/repository.test.ts (1)
src/modules/nft/repositories/nft.repository.ts (1)
NFTRepository(15-101)
| @@ -0,0 +1,101 @@ | |||
| import NFTRepository from "../../../repositories/nft.repository"; | |||
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.ts exposes export class NFTRepository, not a default export. Use a named import.
Apply:
-import NFTRepository from "../../../repositories/nft.repository";
+import { NFTRepository } from "../../../repositories/nft.repository";Verify with:
🏁 Script executed:
#!/bin/bash
rg -nP 'export\s+default\s+NFTRepository\b|export\s+default\s+\w*NFTRepository' src/modules/nft/repositories/nft.repository.ts || true
echo "Legacy method names present?"
rg -nP 'async\s+(createNFT|getNFTById|getNFTByUserId|deleteNFT)\s*\(' src/modules/nft/repositories/nft.repository.ts || echo "None"
echo "Current methods present:"
rg -nP 'async\s+(create|findById|findByUserId|update|delete)\s*\(' src/modules/nft/repositories/nft.repository.tsLength of output: 749
Fix import to use named export for NFTRepository
src/modules/nft/__tests__/application/repository/repository.test.ts currently imports NFTRepository as a default export, but src/modules/nft/repositories/nft.repository.ts exports it by name. Update as follows:
-import NFTRepository from "../../../repositories/nft.repository";
+import { NFTRepository } from "../../../repositories/nft.repository";📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import NFTRepository from "../../../repositories/nft.repository"; | |
| import { NFTRepository } from "../../../repositories/nft.repository"; |
🤖 Prompt for AI Agents
In src/modules/nft/__tests__/application/repository/repository.test.ts around
line 1, the test imports NFTRepository as a default export but the
implementation file exports it as a named export; update the import statement to
use a named import (e.g., import { NFTRepository } from
"../../../repositories/nft.repository";) so the test imports match the
repository's named export.
| mockModel = { | ||
| create: jest.fn(), | ||
| findUnique: jest.fn(), | ||
| findMany: jest.fn(), | ||
| delete: jest.fn(), | ||
| }; |
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.
Add missing Prisma count mock.
findByUserId calls nFT.count. Without this, tests for pagination will break.
mockModel = {
create: jest.fn(),
findUnique: jest.fn(),
findMany: jest.fn(),
delete: jest.fn(),
+ count: jest.fn(),
};📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| mockModel = { | |
| create: jest.fn(), | |
| findUnique: jest.fn(), | |
| findMany: jest.fn(), | |
| delete: jest.fn(), | |
| }; | |
| mockModel = { | |
| create: jest.fn(), | |
| findUnique: jest.fn(), | |
| findMany: jest.fn(), | |
| delete: jest.fn(), | |
| count: jest.fn(), | |
| }; |
🤖 Prompt for AI Agents
In src/modules/nft/__tests__/application/repository/repository.test.ts around
lines 14 to 19, the test's mockModel is missing a Prisma-style count method that
repository.findByUserId invokes for pagination; add a count mock (e.g., count:
jest.fn()) to mockModel and ensure tests that assert pagination stub the count
mock's return value appropriately so pagination paths exercise expected
behavior.
| 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"); | ||
| }); |
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.
Method names don’t exist on NFTRepository.
The repository exposes create, findById, findByUserId, and delete. Update assertions.
- 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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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"); | |
| }); | |
| it("should expose CRUD methods", () => { | |
| expect(typeof repository.create).toBe("function"); | |
| expect(typeof repository.findById).toBe("function"); | |
| expect(typeof repository.findByUserId).toBe("function"); | |
| expect(typeof repository.delete).toBe("function"); | |
| }); |
🤖 Prompt for AI Agents
In src/modules/nft/__tests__/application/repository/repository.test.ts around
lines 32 to 37, the test asserts non-existent method names (createNFT,
getNFTById, getNFTByUserId, deleteNFT); update the assertions to check the
actual NFTRepository method names: expect(typeof
repository.create).toBe("function"); expect(typeof
repository.findById).toBe("function"); expect(typeof
repository.findByUserId).toBe("function"); and expect(typeof
repository.delete).toBe("function").
| 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); | ||
| }); |
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.
Align create test with repository contract and domain mapping.
- Method is
create, notcreateNFT. - Payload fields should match what
createactually writes (userId,organizationId,description). - The repository returns a domain
NFTinstance, not the raw Prisma object.
- 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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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); | |
| }); | |
| it("create() - creates an NFT and returns mapped domain entity", async () => { | |
| const payload = { | |
| userId: "user-1", | |
| organizationId: "org-1", | |
| description: "An NFT for testing", | |
| }; | |
| const created = { id: "nft-1", ...payload }; | |
| mockModel.create.mockResolvedValue(created); | |
| const result = await repository.create(payload); | |
| expect(mockModel.create).toHaveBeenCalledWith(expect.objectContaining({ data: payload })); | |
| expect(result).toMatchObject({ | |
| id: created.id, | |
| userId: payload.userId, | |
| organizationId: payload.organizationId, | |
| description: payload.description, | |
| }); | |
| }); |
🤖 Prompt for AI Agents
In src/modules/nft/__tests__/application/repository/repository.test.ts around
lines 39 to 56, the test incorrectly references createNFT, uses an extra
isMinted field, and expects the raw Prisma object back; update the test to call
repository.create, build the payload only with fields the repo writes (userId,
organizationId, description), mock model.create to resolve the raw DB object,
and assert mockModel.create was called with an objectContaining({ data: payload
}); finally, change the expected result to the repository's domain NFT instance
(apply the same mapping the repository uses or instantiate the NFT domain
object) and assert the returned value equals that domain instance.
| 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); | ||
| }); |
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.
Use the correct read method and assert on mapped entity.
Method is findById, which maps to domain NFT.
- 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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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); | |
| }); | |
| 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.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).toMatchObject(nft); | |
| }); |
🤖 Prompt for AI Agents
In src/modules/nft/__tests__/application/repository/repository.test.ts around
lines 58 to 68, the test uses the wrong model method and asserts the raw DB
object; change the mock and expectations to use the repository's read method
findById (mockModel.findById) and have the mock return the DB row, then assert
the repository returns the mapped domain NFT (e.g., an instance or object
matching the NFT shape) — update mockModel.findUnique.mockResolvedValue to
mockModel.findById.mockResolvedValue, replace calls/expectations checking
findUnique and its call args with findById and its expected argument (id or { id
}), and change the final expect to compare result to the mapped NFT domain
object rather than the raw DB row.
| 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); | ||
| }); |
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.
Account for pagination and total count in findByUserId.
findByUserId(userId, page, pageSize) returns { nfts, total } and calls both findMany and count.
- 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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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); | |
| }); | |
| 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.findByUserId("owner-1", 1, 2); | |
| expect(mockModel.findMany).toHaveBeenCalled(); | |
| 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]); | |
| }); |
🤖 Prompt for AI Agents
In src/modules/nft/__tests__/application/repository/repository.test.ts around
lines 70 to 83, the test assumes repository.getNFTByUserId returns only an array
but the real implementation returns an object { nfts, total } and calls both
findMany and count; update the test to
mockModel.count.mockResolvedValue(totalNumber), adjust mockModel.findMany to
resolve the nfts, call repository.getNFTByUserId with page and pageSize args,
assert mockModel.findMany was called with pagination args (skip and take derived
from page/pageSize) and mockModel.count was called with the userId filter, and
finally expect the result toEqual({ nfts, total: totalNumber }).
| 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(); | ||
| }); |
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.
delete returns void; use findById to verify post-delete.
Method is delete(id: string): Promise<void>. Adjust expectations.
- 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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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(); | |
| }); | |
| 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); | |
| // Since delete() returns void, just await it | |
| 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" } })); | |
| // Simulate subsequent retrieval returns null (not found) | |
| mockModel.findUnique.mockResolvedValueOnce(null); | |
| const afterDelete = await repository.findById("nft-del"); | |
| expect(afterDelete).toBeNull(); | |
| }); |
🤖 Prompt for AI Agents
src/modules/nft/__tests__/application/repository/repository.test.ts around lines
85-100: The test assumes delete returns the deleted record but the
repository.delete method signature is Promise<void>; change the mock and
assertions so mockModel.delete.mockResolvedValueOnce(undefined) (or no value),
keep verifying it was called with the Prisma-style argument
(expect(mockModel.delete.mock.calls[0][0]).toEqual(expect.objectContaining({
where: { id: "nft-del" } }))), assert the returned result is undefined (or
removed) instead of the deleted object, then simulate retrieval by setting
mockModel.findUnique.mockResolvedValueOnce(null) and asserting
repository.getNFTById("nft-del") returns null to verify post-delete behavior.
🚀 Volunchain Pull Request
Mark with an
xall the checkboxes that apply (like[x])📌 Type of Change
📝 Changes description
Add test about repositorys
⏰ Time spent breakdown
40 minutes
Summary by CodeRabbit