mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-12 22:46:46 +03:00
fix: Custom organization mirror destination issue
This commit is contained in:
@@ -208,7 +208,7 @@ export const organizationSchema = z.object({
|
|||||||
configId: z.string(),
|
configId: z.string(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
avatarUrl: 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),
|
isIncluded: z.boolean().default(true),
|
||||||
destinationOrg: z.string().optional().nullable(),
|
destinationOrg: z.string().optional().nullable(),
|
||||||
status: z
|
status: z
|
||||||
|
|||||||
@@ -8,10 +8,19 @@ import { createMockResponse, mockFetch } from "@/tests/mock-fetch";
|
|||||||
// Mock the isRepoPresentInGitea function
|
// Mock the isRepoPresentInGitea function
|
||||||
const mockIsRepoPresentInGitea = mock(() => Promise.resolve(false));
|
const mockIsRepoPresentInGitea = mock(() => Promise.resolve(false));
|
||||||
|
|
||||||
|
let mockDbSelectResult: any[] = [];
|
||||||
|
|
||||||
// Mock the database module
|
// Mock the database module
|
||||||
mock.module("@/lib/db", () => {
|
mock.module("@/lib/db", () => {
|
||||||
return {
|
return {
|
||||||
db: {
|
db: {
|
||||||
|
select: () => ({
|
||||||
|
from: () => ({
|
||||||
|
where: () => ({
|
||||||
|
limit: () => Promise.resolve(mockDbSelectResult)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}),
|
||||||
update: () => ({
|
update: () => ({
|
||||||
set: () => ({
|
set: () => ({
|
||||||
where: () => Promise.resolve()
|
where: () => Promise.resolve()
|
||||||
@@ -63,6 +72,7 @@ describe("Gitea Repository Mirroring", () => {
|
|||||||
originalConsoleError = console.error;
|
originalConsoleError = console.error;
|
||||||
console.log = mock(() => {});
|
console.log = mock(() => {});
|
||||||
console.error = mock(() => {});
|
console.error = mock(() => {});
|
||||||
|
mockDbSelectResult = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -449,4 +459,37 @@ describe("getGiteaRepoOwner - Organization Override Tests", () => {
|
|||||||
const result = getGiteaRepoOwner({ config: configWithFlatUser, repository: repo });
|
const result = getGiteaRepoOwner({ config: configWithFlatUser, repository: repo });
|
||||||
expect(result).toBe("giteauser");
|
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<Config> = {
|
||||||
|
...baseConfig,
|
||||||
|
userId: "user-id"
|
||||||
|
};
|
||||||
|
|
||||||
|
const repo = { ...baseRepo, organization: "myorg" };
|
||||||
|
|
||||||
|
const result = await getGiteaRepoOwnerAsync({
|
||||||
|
config: configWithUser,
|
||||||
|
repository: repo
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toBe("custom-org");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import type { RepoStatus } from "./Repository";
|
|||||||
export const membershipRoleEnum = z.enum([
|
export const membershipRoleEnum = z.enum([
|
||||||
"member",
|
"member",
|
||||||
"admin",
|
"admin",
|
||||||
|
"owner",
|
||||||
"billing_manager",
|
"billing_manager",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user