This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
gitgram-ai/gitgram/backend/tests/services.test.ts
caelum0x 14b1fe6b2c feat: build out + functionally verify all 7 subprojects to working state
Autonomous multi-agent build/verify drive across gitgram + aitimemachine.
All 7 subprojects now build and run; agents fixed real defects throughout.

Backend (gitgram/backend):
- Migrate to Express 5 typing (ambient .d.ts shims for express-rate-limit,
  @apollo/server, @trpc/server that resolve Express 5 types under workspace
  hoisting); fix 2 real GraphQL typing defects; scope typeRoots to local types
- Fix startup crash (missing `buffer` pkg required by nsfwjs)
- Install ioredis + web-push; build clean, boots (HTTP 200), 1241/1266 tests

Web (gitgram/web): next build green (fix route-slug conflict, remove dead
lib/trpc.ts); document monorepo dual-React vitest harness limitation (71/86)

Mobile (gitgram/mobile): port proximity-unique features (org, starred,
reading-list, languages, snippets) onto modern expo-router + axios stack;
exclude standalone proximity/ from tsconfig + jest; typecheck clean, 8/8 tests

AITM core: fix CLI crash from duplicate command registrations (vendored merge);
secure 2 unauthenticated API routes; 520/520 tests
AITM api-server: fix ioredis construct + a2a SDK decls + test mocks; 715/715
AITM mcp: fix TS5076 syntax + slow gitnexus import; 63/63
AITM website: next build green (88 routes)

Root deps: fix broken @types/uuid stub (real v9), relax override to $@types/uuid

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 04:10:22 +03:00

87 lines
2.6 KiB
TypeScript

import { sendEmail } from '../src/services/emailService';
import { geocodingService } from '../src/services/geocodingService';
import { generateSecret, verifyTOTP } from '../src/services/twoFactorService';
import speakeasy from 'speakeasy';
describe('Service Layer Tests', () => {
describe('Email Service', () => {
it('should handle missing API key gracefully', async () => {
const originalKey = process.env.RESEND_API_KEY;
delete process.env.RESEND_API_KEY;
await expect(
sendEmail({
to: 'test@example.com',
subject: 'Test',
html: '<p>Test</p>',
})
).resolves.not.toThrow();
if (originalKey) {
process.env.RESEND_API_KEY = originalKey;
}
});
it('should format email correctly', async () => {
const options = {
to: 'test@example.com',
subject: 'Test Subject',
html: '<p>Test HTML</p>',
};
// Should not throw when API key is missing (development mode)
await expect(sendEmail(options)).resolves.not.toThrow();
});
});
describe('Geocoding Service', () => {
it('should handle missing API key gracefully', async () => {
const originalKey = process.env.GOOGLE_MAPS_API_KEY;
delete process.env.GOOGLE_MAPS_API_KEY;
const result = await geocodingService.geocodeAddress('123 Main St');
expect(result).toBeNull();
if (originalKey) {
process.env.GOOGLE_MAPS_API_KEY = originalKey;
}
});
it('should reverse geocode coordinates', async () => {
const originalKey = process.env.GOOGLE_MAPS_API_KEY;
delete process.env.GOOGLE_MAPS_API_KEY;
const result = await geocodingService.reverseGeocode(37.7749, -122.4194);
expect(result).toBeNull();
if (originalKey) {
process.env.GOOGLE_MAPS_API_KEY = originalKey;
}
});
});
describe('2FA Service', () => {
it('should generate secret', () => {
const secret = generateSecret('test@example.com');
expect(secret).toHaveProperty('secret');
expect(secret).toHaveProperty('otpauthUrl');
expect(secret.secret).toBeTruthy();
});
it('should verify token', () => {
const secret = generateSecret('test@example.com');
const token = speakeasy.totp({ secret: secret.secret, encoding: 'base32' });
const isValid = verifyTOTP(secret.secret, token);
expect(isValid).toBe(true);
});
it('should reject invalid token', () => {
const secret = generateSecret('test@example.com');
const isValid = verifyTOTP(secret.secret, '000000');
expect(isValid).toBe(false);
});
});
});