diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index 01cb054..f9d9db2 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -208,7 +208,7 @@ export const organizationSchema = z.object({ configId: z.string(), name: z.string(), avatarUrl: z.string(), - membershipRole: z.enum(["admin", "member", "owner"]).default("member"), + membershipRole: z.enum(["member", "admin", "owner", "billing_manager"]).default("member"), isIncluded: z.boolean().default(true), destinationOrg: z.string().optional().nullable(), status: z diff --git a/src/lib/gitea.test.ts b/src/lib/gitea.test.ts index 64236fb..7b5711d 100644 --- a/src/lib/gitea.test.ts +++ b/src/lib/gitea.test.ts @@ -8,10 +8,19 @@ import { createMockResponse, mockFetch } from "@/tests/mock-fetch"; // Mock the isRepoPresentInGitea function const mockIsRepoPresentInGitea = mock(() => Promise.resolve(false)); +let mockDbSelectResult: any[] = []; + // Mock the database module mock.module("@/lib/db", () => { return { db: { + select: () => ({ + from: () => ({ + where: () => ({ + limit: () => Promise.resolve(mockDbSelectResult) + }) + }) + }), update: () => ({ set: () => ({ where: () => Promise.resolve() @@ -63,6 +72,7 @@ describe("Gitea Repository Mirroring", () => { originalConsoleError = console.error; console.log = mock(() => {}); console.error = mock(() => {}); + mockDbSelectResult = []; }); afterEach(() => { @@ -449,4 +459,37 @@ describe("getGiteaRepoOwner - Organization Override Tests", () => { const result = getGiteaRepoOwner({ config: configWithFlatUser, repository: repo }); expect(result).toBe("giteauser"); }); + + test("getGiteaRepoOwnerAsync honors organization override for owner role", async () => { + mockDbSelectResult = [ + { + id: "org-id", + userId: "user-id", + configId: "config-id", + name: "myorg", + membershipRole: "owner", + status: "imported", + destinationOrg: "custom-org", + avatarUrl: "https://example.com/avatar.png", + isIncluded: true, + repositoryCount: 0, + createdAt: new Date(), + updatedAt: new Date() + } + ]; + + const configWithUser: Partial = { + ...baseConfig, + userId: "user-id" + }; + + const repo = { ...baseRepo, organization: "myorg" }; + + const result = await getGiteaRepoOwnerAsync({ + config: configWithUser, + repository: repo + }); + + expect(result).toBe("custom-org"); + }); }); diff --git a/src/types/organizations.ts b/src/types/organizations.ts index 4b0927e..f845d46 100644 --- a/src/types/organizations.ts +++ b/src/types/organizations.ts @@ -5,6 +5,7 @@ import type { RepoStatus } from "./Repository"; export const membershipRoleEnum = z.enum([ "member", "admin", + "owner", "billing_manager", ]);