test(auth): add unit tests for various guards and services with mocked dependencies
This commit is contained in:
@@ -96,4 +96,37 @@ describe("MediaService", () => {
|
||||
expect(result.buffer).toEqual(Buffer.from("processed-video"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("scanFile", () => {
|
||||
it("should return false if clamav not initialized", async () => {
|
||||
const result = await service.scanFile(Buffer.from(""), "test.txt");
|
||||
expect(result.isInfected).toBe(false);
|
||||
});
|
||||
|
||||
it("should handle virus detection", async () => {
|
||||
// Mock private property to simulate initialized clamscan
|
||||
(service as any).isClamAvInitialized = true;
|
||||
(service as any).clamscan = {
|
||||
scanStream: jest.fn().mockResolvedValue({
|
||||
isInfected: true,
|
||||
viruses: ["Eicar-Test-Signature"],
|
||||
}),
|
||||
};
|
||||
|
||||
const result = await service.scanFile(Buffer.from(""), "test.txt");
|
||||
expect(result.isInfected).toBe(true);
|
||||
expect(result.virusName).toBe("Eicar-Test-Signature");
|
||||
});
|
||||
|
||||
it("should handle scan error", async () => {
|
||||
(service as any).isClamAvInitialized = true;
|
||||
(service as any).clamscan = {
|
||||
scanStream: jest.fn().mockRejectedValue(new Error("Scan failed")),
|
||||
};
|
||||
|
||||
await expect(
|
||||
service.scanFile(Buffer.from(""), "test.txt"),
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user