Skip to content

Commit a1f9c9f

Browse files
committed
chore(tests): update version management tests and exclude macOS resource fork files
1 parent cd5a643 commit a1f9c9f

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ services/backend/persistent_data/*
6161
services/backend/tests/e2e/test-data/*.db
6262

6363
._*.ts
64+
._*.sh
6465
._*.vue
6566
._*.md
6667
._*.js

services/backend/tests/unit/routes/index.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { describe, it, expect, vi, beforeEach, type MockedFunction } from 'vitest';
22
import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
33
import { registerRoutes } from '../../../src/routes/index';
4+
import { getVersionString } from '../../../src/config/version';
5+
6+
// Get version dynamically from version config
7+
const CURRENT_VERSION = getVersionString();
48

59
// Mock the route modules
610
vi.mock('../../../src/routes/db/status');
@@ -90,6 +94,14 @@ describe('Main Routes Registration', () => {
9094
mockHealthRoute.mockResolvedValue(undefined);
9195
});
9296

97+
describe('Version Management', () => {
98+
it('should read version from version config', () => {
99+
expect(CURRENT_VERSION).toBeDefined();
100+
expect(typeof CURRENT_VERSION).toBe('string');
101+
expect(CURRENT_VERSION).toMatch(/^\d+\.\d+\.\d+/);
102+
});
103+
});
104+
93105
describe('Route Registration', () => {
94106
it('should register all route modules', async () => {
95107
await registerRoutes(mockFastify as FastifyInstance);
@@ -167,7 +179,7 @@ describe('Main Routes Registration', () => {
167179
message: 'DeployStack Backend is running.',
168180
status: 'Database Not Configured/Connected - Use /api/db/status and /api/db/setup',
169181
timestamp: expect.any(String),
170-
version: '0.20.9'
182+
version: CURRENT_VERSION
171183
});
172184

173185
// Verify timestamp is a valid ISO string
@@ -187,7 +199,7 @@ describe('Main Routes Registration', () => {
187199
message: 'DeployStack Backend is running.',
188200
status: 'Database Connected',
189201
timestamp: expect.any(String),
190-
version: '0.20.9'
202+
version: CURRENT_VERSION
191203
});
192204

193205
// Verify timestamp is a valid ISO string
@@ -211,7 +223,7 @@ describe('Main Routes Registration', () => {
211223
const handler = routeHandlers['GET /'];
212224
const result = await handler(mockRequest, mockReply);
213225

214-
expect(result.version).toBe('0.20.9');
226+
expect(result.version).toBe(CURRENT_VERSION);
215227
expect(GlobalSettings.getBoolean).toHaveBeenCalledWith('global.show_version', true);
216228
});
217229

services/backend/tests/unit/utils/banner.test.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22
import { displayStartupBanner } from '../../../src/utils/banner';
33
import type { FastifyBaseLogger } from 'fastify';
4+
import { getVersionString } from '../../../src/config/version';
5+
6+
// Get version dynamically from version config
7+
const CURRENT_VERSION = getVersionString();
48

59
// Helper function to strip ANSI color codes from strings
610
const stripAnsiCodes = (str: string): string => {
@@ -11,6 +15,14 @@ describe('banner.ts', () => {
1115
let mockLogger: FastifyBaseLogger;
1216
let originalEnv: NodeJS.ProcessEnv;
1317

18+
describe('Version Management', () => {
19+
it('should read version from version config', () => {
20+
expect(CURRENT_VERSION).toBeDefined();
21+
expect(typeof CURRENT_VERSION).toBe('string');
22+
expect(CURRENT_VERSION).toMatch(/^\d+\.\d+\.\d+/);
23+
});
24+
});
25+
1426
beforeEach(() => {
1527
// Create mock logger
1628
mockLogger = {
@@ -44,7 +56,7 @@ describe('banner.ts', () => {
4456
const logCall = (mockLogger.info as any).mock.calls[0];
4557
expect(logCall[0]).toEqual({
4658
port: testPort,
47-
version: '0.20.9',
59+
version: CURRENT_VERSION,
4860
environment: 'test',
4961
operation: 'startup_banner'
5062
});
@@ -98,8 +110,8 @@ describe('banner.ts', () => {
98110
const logCall = (mockLogger.info as any).mock.calls[0];
99111
const bannerOutput = logCall[1] as string;
100112
// Should use the version from version.ts (which reads from package.json in development)
101-
expect(bannerOutput).toContain('v0.20.9');
102-
expect(logCall[0].version).toBe('0.20.9');
113+
expect(bannerOutput).toContain(`v${CURRENT_VERSION}`);
114+
expect(logCall[0].version).toBe(CURRENT_VERSION);
103115
});
104116

105117
it('should display current NODE_ENV', () => {
@@ -231,9 +243,9 @@ describe('banner.ts', () => {
231243
const logCall = (mockLogger.info as any).mock.calls[0];
232244
const bannerOutput = logCall[1] as string;
233245
const cleanOutput = stripAnsiCodes(bannerOutput);
234-
expect(cleanOutput).toContain('v0.20.9'); // Should use version.ts data
246+
expect(cleanOutput).toContain(`v${CURRENT_VERSION}`); // Should use version.ts data
235247
expect(cleanOutput).toContain('Environment: development'); // Should fallback to default
236-
expect(logCall[0].version).toBe('0.20.9');
248+
expect(logCall[0].version).toBe(CURRENT_VERSION);
237249
expect(logCall[0].environment).toBe('development');
238250

239251
// Restore original environment variables

services/backend/vitest.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ export default defineConfig({
44
test: {
55
environment: 'node',
66
include: ['tests/unit/**/*.test.ts'],
7-
exclude: ['tests/e2e/**/*'],
7+
exclude: [
8+
'tests/e2e/**/*',
9+
'tests/unit/**/._*.test.ts', // Exclude macOS resource fork files
10+
'**/._*' // Exclude all macOS resource fork files
11+
],
812
watch: false, // Disable watch mode by default
913
testTimeout: 10000, // 10 seconds timeout for unit tests
1014
typecheck: {

0 commit comments

Comments
 (0)