Skip to content

Conversation

@Samumeee
Copy link

@Samumeee Samumeee commented Sep 1, 2025

🚀 Volunchain Pull Request

Mark with an x all the checkboxes that apply (like [x])

  • Closes #
  • Added tests (if necessary)
  • Run tests
  • [] Run formatting
  • [] Evidence attached
  • Commented the code

📌 Type of Change

  • Documentation (updates to README, docs, or comments)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

📝 Changes description

Add test about repositorys

⏰ Time spent breakdown

40 minutes

Summary by CodeRabbit

  • Tests
    • Added a comprehensive unit test suite for the NFT repository, covering create, retrieval by ID, retrieval by user, and delete operations.
    • Verifies correct query payloads and post-deletion behavior to ensure data consistency.
    • Increases coverage across common and edge scenarios, improving reliability and reducing regression risk.
    • Enhances resilience by validating behavior against variations in underlying data access patterns.

@coderabbitai
Copy link

coderabbitai bot commented Sep 1, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
Tests: NFTRepository CRUD
src/modules/nft/__tests__/application/repository/repository.test.ts
Introduces unit tests for NFTRepository covering create, read (by id, by user id), and delete operations with mocked Prisma (nft/nFT). Verifies method calls, payloads, where clauses, and post-delete null retrieval.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

In a burrow of mocks and jest, I hop,
CRUD carrots lined up—plop, plop, plop.
Create, fetch, delete—now it’s gone,
nFT or nft, I nibble on.
Tests pass green beneath moonlight’s glow—
Thump-thump, to the repo I go! 🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 both nft and nFT is fine, but unnecessary if the generator is consistent.


11-30: Consider DI for Prisma to avoid private-field mutation in tests.

Inject PrismaClient via 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 23a1f32 and f93eb4e.

📒 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";
Copy link

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.ts

Length 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.

Suggested change
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.

Comment on lines +14 to +19
mockModel = {
create: jest.fn(),
findUnique: jest.fn(),
findMany: jest.fn(),
delete: jest.fn(),
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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.

Comment on lines +32 to +37
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");
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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").

Comment on lines +39 to +56
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);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Align create test with repository contract and domain mapping.

  • Method is create, not createNFT.
  • Payload fields should match what create actually writes (userId, organizationId, description).
  • The repository returns a domain NFT instance, 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.

Suggested change
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.

Comment on lines +58 to +68
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);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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.

Comment on lines +70 to +83
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);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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 }).

Comment on lines +85 to +100
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();
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants