Skip to content

Commit

Permalink
test(unit): add basic test for rekor_api
Browse files Browse the repository at this point in the history
  • Loading branch information
kahboom committed Mar 25, 2024
1 parent cc6b6b1 commit c3a7ffa
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/modules/api/rekor_api.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { renderHook } from "@testing-library/react";
import { useRekorSearch } from "./rekor_api";
import { useRekorClient } from "./context";

jest.mock("./context", () => ({
useRekorClient: jest.fn(),
}));

Object.defineProperty(global.self, "crypto", {
value: {
subtle: {
digest: jest.fn().mockImplementation(async () => {
const hashBuffer = new ArrayBuffer(32);
const hashArray = new Uint8Array(hashBuffer);
hashArray.fill(0);
return hashBuffer;
}),
},
},
});

describe("useRekorSearch", () => {
it("searches by logIndex", async () => {
const mockGetLogEntryByIndex = jest.fn().mockResolvedValue(0);

(useRekorClient as jest.Mock).mockReturnValue({
entries: { getLogEntryByIndex: mockGetLogEntryByIndex },
});

const { result } = renderHook(() => useRekorSearch());

await result.current({ attribute: "logIndex", query: 123 });

expect(mockGetLogEntryByIndex).toHaveBeenCalledWith({ logIndex: 123 });
});
});

0 comments on commit c3a7ffa

Please sign in to comment.