mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-09 21:16:48 +03:00
refactor: update test files to use bun:test and remove vitest configuration
This commit is contained in:
@@ -127,7 +127,9 @@ describe("GitHub Test Connection API", () => {
|
|||||||
expect(response.status).toBe(500);
|
expect(response.status).toBe(500);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
expect(data.success).toBe(false);
|
// The createSecureErrorResponse function returns an error field, not success
|
||||||
expect(data.message).toContain("Bad credentials");
|
// It sanitizes error messages for security, so we expect the generic message
|
||||||
|
expect(data.error).toBeDefined();
|
||||||
|
expect(data.error).toBe("An internal server error occurred");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import { describe, test, expect, mock, beforeEach, afterEach } from "bun:test";
|
import { describe, test, expect, mock, beforeEach, afterEach } from "bun:test";
|
||||||
import type { MirrorRepoRequest } from "@/types/mirror";
|
import type { MirrorRepoRequest } from "@/types/mirror";
|
||||||
|
import { POST } from "./mirror-repo";
|
||||||
|
|
||||||
// Mock the database module
|
// Mock the database module
|
||||||
const mockDb = {
|
const mockDb = {
|
||||||
select: mock(() => ({
|
select: mock(() => ({
|
||||||
from: mock(() => ({
|
from: mock((table: any) => ({
|
||||||
where: mock(() => ({
|
where: mock(() => {
|
||||||
|
// Return config for configs table
|
||||||
|
if (table === mockConfigs) {
|
||||||
|
return {
|
||||||
limit: mock(() => Promise.resolve([{
|
limit: mock(() => Promise.resolve([{
|
||||||
id: "config-id",
|
id: "config-id",
|
||||||
userId: "user-id",
|
userId: "user-id",
|
||||||
@@ -20,15 +24,45 @@ const mockDb = {
|
|||||||
username: "giteauser"
|
username: "giteauser"
|
||||||
}
|
}
|
||||||
}]))
|
}]))
|
||||||
}))
|
};
|
||||||
|
}
|
||||||
|
// Return repositories for repositories table
|
||||||
|
return Promise.resolve([
|
||||||
|
{
|
||||||
|
id: "repo-id-1",
|
||||||
|
name: "test-repo-1",
|
||||||
|
visibility: "public",
|
||||||
|
status: "pending",
|
||||||
|
organization: null,
|
||||||
|
lastMirrored: null,
|
||||||
|
errorMessage: null,
|
||||||
|
forkedFrom: null,
|
||||||
|
mirroredLocation: ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "repo-id-2",
|
||||||
|
name: "test-repo-2",
|
||||||
|
visibility: "public",
|
||||||
|
status: "pending",
|
||||||
|
organization: null,
|
||||||
|
lastMirrored: null,
|
||||||
|
errorMessage: null,
|
||||||
|
forkedFrom: null,
|
||||||
|
mirroredLocation: ""
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
})
|
||||||
}))
|
}))
|
||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mockConfigs = {};
|
||||||
|
const mockRepositories = {};
|
||||||
|
|
||||||
mock.module("@/lib/db", () => ({
|
mock.module("@/lib/db", () => ({
|
||||||
db: mockDb,
|
db: mockDb,
|
||||||
configs: {},
|
configs: mockConfigs,
|
||||||
repositories: {}
|
repositories: mockRepositories
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock the gitea module
|
// Mock the gitea module
|
||||||
@@ -98,12 +132,13 @@ describe("Repository Mirroring API", () => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await mockModule.POST({ request } as any);
|
const response = await POST({ request } as any);
|
||||||
|
|
||||||
expect(response.status).toBe(400);
|
expect(response.status).toBe(400);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
expect(data.error).toBe("Missing userId or repositoryIds.");
|
expect(data.success).toBe(false);
|
||||||
|
expect(data.message).toBe("userId and repositoryIds are required.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("returns 400 if repositoryIds is missing", async () => {
|
test("returns 400 if repositoryIds is missing", async () => {
|
||||||
@@ -117,12 +152,13 @@ describe("Repository Mirroring API", () => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await mockModule.POST({ request } as any);
|
const response = await POST({ request } as any);
|
||||||
|
|
||||||
expect(response.status).toBe(400);
|
expect(response.status).toBe(400);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
expect(data.error).toBe("Missing userId or repositoryIds.");
|
expect(data.success).toBe(false);
|
||||||
|
expect(data.message).toBe("userId and repositoryIds are required.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("returns 200 and starts mirroring repositories", async () => {
|
test("returns 200 and starts mirroring repositories", async () => {
|
||||||
@@ -137,13 +173,13 @@ describe("Repository Mirroring API", () => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await mockModule.POST({ request } as any);
|
const response = await POST({ request } as any);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
expect(data.success).toBe(true);
|
expect(data.success).toBe(true);
|
||||||
expect(data.message).toBe("Repository mirroring started");
|
expect(data.message).toBe("Mirror job started.");
|
||||||
expect(data.batchId).toBe("test-batch-id");
|
expect(data.repositories).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// example.test.ts
|
// example.test.ts
|
||||||
import { describe, it, expect } from "vitest";
|
import { describe, test, expect } from "bun:test";
|
||||||
|
|
||||||
describe("Example Test", () => {
|
describe("Example Test", () => {
|
||||||
it("should pass", () => {
|
test("should pass", () => {
|
||||||
expect(true).toBe(true);
|
expect(true).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
import "@testing-library/jest-dom";
|
|
||||||
import { expect, afterEach } from "vitest";
|
|
||||||
import { cleanup } from "@testing-library/react";
|
|
||||||
|
|
||||||
// Run cleanup after each test case (e.g. clearing jsdom)
|
|
||||||
afterEach(() => {
|
|
||||||
cleanup();
|
|
||||||
});
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import { defineConfig } from 'vitest/config';
|
|
||||||
import react from '@vitejs/plugin-react';
|
|
||||||
import { fileURLToPath } from 'url';
|
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [react()],
|
|
||||||
test: {
|
|
||||||
environment: 'jsdom',
|
|
||||||
globals: true,
|
|
||||||
setupFiles: ['./src/tests/setup.ts'],
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
alias: {
|
|
||||||
'@': path.resolve(__dirname, './src'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user