test: isolate module mocking and add sequential test script
This commit is contained in:
+2
-1
@@ -6,7 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun --hot index.js",
|
"dev": "bun --hot index.js",
|
||||||
"start": "NODE_ENV=production bun index.js",
|
"start": "NODE_ENV=production bun index.js",
|
||||||
"db:migrate": "psql $DATABASE_URL -f schema.sql"
|
"db:migrate": "psql $DATABASE_URL -f schema.sql",
|
||||||
|
"test": "bun test test/rateLimit.test.js && bun test test/file.test.js && bun test test/telegram.test.js && bun test test/upload.test.js && bun test test/files.test.js && bun test test/health.test.js && bun test test/bot.test.js && bun test test/bootstrap.test.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/engines": "^7.8.0",
|
"@prisma/engines": "^7.8.0",
|
||||||
|
|||||||
+5
-1
@@ -1,4 +1,4 @@
|
|||||||
import { describe, it, expect, mock, spyOn, beforeEach } from "bun:test";
|
import { describe, it, expect, mock, spyOn, beforeEach, afterAll } from "bun:test";
|
||||||
import logger from "../src/utils/logger.js";
|
import logger from "../src/utils/logger.js";
|
||||||
|
|
||||||
// Mock environment
|
// Mock environment
|
||||||
@@ -145,4 +145,8 @@ describe("Telegram Bot Handler", () => {
|
|||||||
expect(mockForwardToStorage).not.toHaveBeenCalled();
|
expect(mockForwardToStorage).not.toHaveBeenCalled();
|
||||||
expect(replyMock).toHaveBeenCalledWith(expect.stringContaining("exceeds"));
|
expect(replyMock).toHaveBeenCalledWith(expect.stringContaining("exceeds"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
mock.restore();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+5
-2
@@ -1,5 +1,4 @@
|
|||||||
import { describe, it, expect, mock, spyOn, beforeEach } from "bun:test";
|
import { describe, it, expect, mock, beforeEach, afterAll } from "bun:test";
|
||||||
import logger from "../src/utils/logger.js";
|
|
||||||
|
|
||||||
// Mock database layer
|
// Mock database layer
|
||||||
const mockSelect = mock(() => ({
|
const mockSelect = mock(() => ({
|
||||||
@@ -176,4 +175,8 @@ describe("File Route Handlers", () => {
|
|||||||
expect(body.error).toBe("Server error");
|
expect(body.error).toBe("Server error");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
mock.restore();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+5
-2
@@ -1,5 +1,4 @@
|
|||||||
import { describe, it, expect, mock, spyOn, beforeEach, afterEach } from "bun:test";
|
import { describe, it, expect, mock, beforeEach, afterAll } from "bun:test";
|
||||||
import logger from "../src/utils/logger.js";
|
|
||||||
|
|
||||||
// Mock db
|
// Mock db
|
||||||
const mockInsert = mock(() => ({
|
const mockInsert = mock(() => ({
|
||||||
@@ -116,4 +115,8 @@ describe("Upload Route Handler", () => {
|
|||||||
expect(body.public_id).toBe("mocked-nanoid-id");
|
expect(body.public_id).toBe("mocked-nanoid-id");
|
||||||
expect(body.file_name).toBe("test_multi.txt");
|
expect(body.file_name).toBe("test_multi.txt");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
mock.restore();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user