mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-06 11:36:44 +03:00
fixed tests
This commit is contained in:
110
src/lib/gitea-lfs.test.ts
Normal file
110
src/lib/gitea-lfs.test.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import { describe, test, expect, mock } from "bun:test";
|
||||
import type { Config } from "./db/schema";
|
||||
|
||||
describe("Git LFS Support", () => {
|
||||
test("should include LFS flag when configured", () => {
|
||||
const config: Partial<Config> = {
|
||||
giteaConfig: {
|
||||
url: "https://gitea.example.com",
|
||||
token: "test-token",
|
||||
defaultOwner: "testuser",
|
||||
lfs: true, // LFS enabled
|
||||
},
|
||||
mirrorOptions: {
|
||||
mirrorLFS: true, // UI option enabled
|
||||
},
|
||||
};
|
||||
|
||||
// Mock the payload that would be sent to Gitea API
|
||||
const createMirrorPayload = (config: Partial<Config>, repoUrl: string) => {
|
||||
const payload: any = {
|
||||
clone_addr: repoUrl,
|
||||
mirror: true,
|
||||
private: false,
|
||||
};
|
||||
|
||||
// Add LFS flag if configured
|
||||
if (config.giteaConfig?.lfs || config.mirrorOptions?.mirrorLFS) {
|
||||
payload.lfs = true;
|
||||
}
|
||||
|
||||
return payload;
|
||||
};
|
||||
|
||||
const payload = createMirrorPayload(config, "https://github.com/user/repo.git");
|
||||
|
||||
expect(payload).toHaveProperty("lfs");
|
||||
expect(payload.lfs).toBe(true);
|
||||
});
|
||||
|
||||
test("should not include LFS flag when not configured", () => {
|
||||
const config: Partial<Config> = {
|
||||
giteaConfig: {
|
||||
url: "https://gitea.example.com",
|
||||
token: "test-token",
|
||||
defaultOwner: "testuser",
|
||||
lfs: false, // LFS disabled
|
||||
},
|
||||
mirrorOptions: {
|
||||
mirrorLFS: false, // UI option disabled
|
||||
},
|
||||
};
|
||||
|
||||
const createMirrorPayload = (config: Partial<Config>, repoUrl: string) => {
|
||||
const payload: any = {
|
||||
clone_addr: repoUrl,
|
||||
mirror: true,
|
||||
private: false,
|
||||
};
|
||||
|
||||
if (config.giteaConfig?.lfs || config.mirrorOptions?.mirrorLFS) {
|
||||
payload.lfs = true;
|
||||
}
|
||||
|
||||
return payload;
|
||||
};
|
||||
|
||||
const payload = createMirrorPayload(config, "https://github.com/user/repo.git");
|
||||
|
||||
expect(payload).not.toHaveProperty("lfs");
|
||||
});
|
||||
|
||||
test("should handle LFS with either giteaConfig or mirrorOptions", () => {
|
||||
// Test with only giteaConfig.lfs
|
||||
const config1: Partial<Config> = {
|
||||
giteaConfig: {
|
||||
url: "https://gitea.example.com",
|
||||
token: "test-token",
|
||||
defaultOwner: "testuser",
|
||||
lfs: true,
|
||||
},
|
||||
};
|
||||
|
||||
// Test with only mirrorOptions.mirrorLFS
|
||||
const config2: Partial<Config> = {
|
||||
mirrorOptions: {
|
||||
mirrorLFS: true,
|
||||
},
|
||||
};
|
||||
|
||||
const createMirrorPayload = (config: Partial<Config>, repoUrl: string) => {
|
||||
const payload: any = {
|
||||
clone_addr: repoUrl,
|
||||
mirror: true,
|
||||
private: false,
|
||||
};
|
||||
|
||||
if (config.giteaConfig?.lfs || config.mirrorOptions?.mirrorLFS) {
|
||||
payload.lfs = true;
|
||||
}
|
||||
|
||||
return payload;
|
||||
};
|
||||
|
||||
const payload1 = createMirrorPayload(config1, "https://github.com/user/repo.git");
|
||||
const payload2 = createMirrorPayload(config2, "https://github.com/user/repo.git");
|
||||
|
||||
expect(payload1.lfs).toBe(true);
|
||||
expect(payload2.lfs).toBe(true);
|
||||
});
|
||||
});
|
||||
82
src/lib/scheduler-service.test.ts
Normal file
82
src/lib/scheduler-service.test.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { describe, test, expect, mock } from "bun:test";
|
||||
import { repoStatusEnum } from "@/types/Repository";
|
||||
import type { Repository } from "./db/schema";
|
||||
|
||||
describe("Scheduler Service - Ignored Repository Handling", () => {
|
||||
test("should skip repositories with 'ignored' status", async () => {
|
||||
// Create a repository with ignored status
|
||||
const ignoredRepo: Partial<Repository> = {
|
||||
id: "ignored-repo-id",
|
||||
name: "ignored-repo",
|
||||
fullName: "user/ignored-repo",
|
||||
status: repoStatusEnum.parse("ignored"),
|
||||
userId: "user-id",
|
||||
};
|
||||
|
||||
// Mock the scheduler logic that checks repository status
|
||||
const shouldMirrorRepository = (repo: Partial<Repository>): boolean => {
|
||||
// Skip ignored repositories
|
||||
if (repo.status === "ignored") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip recently mirrored repositories
|
||||
if (repo.status === "synced" || repo.status === "mirrored") {
|
||||
const lastUpdated = repo.updatedAt;
|
||||
if (lastUpdated && Date.now() - lastUpdated.getTime() < 3600000) {
|
||||
return false; // Skip if mirrored within last hour
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// Test that ignored repository is skipped
|
||||
expect(shouldMirrorRepository(ignoredRepo)).toBe(false);
|
||||
|
||||
// Test that non-ignored repository is not skipped
|
||||
const activeRepo: Partial<Repository> = {
|
||||
...ignoredRepo,
|
||||
status: repoStatusEnum.parse("imported"),
|
||||
};
|
||||
expect(shouldMirrorRepository(activeRepo)).toBe(true);
|
||||
|
||||
// Test that recently synced repository is skipped
|
||||
const recentlySyncedRepo: Partial<Repository> = {
|
||||
...ignoredRepo,
|
||||
status: repoStatusEnum.parse("synced"),
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
expect(shouldMirrorRepository(recentlySyncedRepo)).toBe(false);
|
||||
|
||||
// Test that old synced repository is not skipped
|
||||
const oldSyncedRepo: Partial<Repository> = {
|
||||
...ignoredRepo,
|
||||
status: repoStatusEnum.parse("synced"),
|
||||
updatedAt: new Date(Date.now() - 7200000), // 2 hours ago
|
||||
};
|
||||
expect(shouldMirrorRepository(oldSyncedRepo)).toBe(true);
|
||||
});
|
||||
|
||||
test("should validate all repository status enum values", () => {
|
||||
const validStatuses = [
|
||||
"imported",
|
||||
"mirroring",
|
||||
"mirrored",
|
||||
"syncing",
|
||||
"synced",
|
||||
"failed",
|
||||
"skipped",
|
||||
"ignored",
|
||||
"deleting",
|
||||
"deleted"
|
||||
];
|
||||
|
||||
validStatuses.forEach(status => {
|
||||
expect(() => repoStatusEnum.parse(status)).not.toThrow();
|
||||
});
|
||||
|
||||
// Test invalid status
|
||||
expect(() => repoStatusEnum.parse("invalid-status")).toThrow();
|
||||
});
|
||||
});
|
||||
@@ -1,8 +0,0 @@
|
||||
// example.test.ts
|
||||
import { describe, test, expect } from "bun:test";
|
||||
|
||||
describe("Example Test", () => {
|
||||
test("should pass", () => {
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user