Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamics committed Dec 17, 2024
1 parent 976e377 commit b2c25fd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/server/api/__tests__/network/getUserNetworks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { appRouter } from "../../root";
import { type Session } from "next-auth";
import { PrismaClient } from "@prisma/client";
import { type PartialDeep } from "type-fest";
import { MemberCounts } from "~/types/local/member";

const mockSession: PartialDeep<Session> = {
expires: new Date().toISOString(),
Expand All @@ -14,6 +15,19 @@ const mockSession: PartialDeep<Session> = {
},
};

// Mock the ZeroTier controller
jest.mock("~/utils/ztApi", () => ({
member_details: jest.fn().mockImplementation((_ctx, nwid, memberId) => {
// Mock both members as authorized for this test
return Promise.resolve({
authorized: true,
// Add other required properties that your implementation might need
id: memberId,
nwid: nwid,
});
}),
}));

test("getUserNetworks", async () => {
const prismaMock = new PrismaClient();

Expand All @@ -22,6 +36,7 @@ test("getUserNetworks", async () => {
name: string;
authorId: number;
networkMembers: NetworkMember[];
memberCounts: MemberCounts;
}

interface NetworkMember {
Expand All @@ -33,6 +48,11 @@ test("getUserNetworks", async () => {
nwid: "1",
name: "test",
authorId: 10,
memberCounts: {
display: "2 (2)",
authorized: 2,
total: 2,
},
networkMembers: [
{
id: "4ef7287f63",
Expand Down

0 comments on commit b2c25fd

Please sign in to comment.