diff --git a/src/database/cleanup.service.spec.ts b/src/database/cleanup.service.spec.ts new file mode 100644 index 00000000..4f6e01ee --- /dev/null +++ b/src/database/cleanup.service.spec.ts @@ -0,0 +1,40 @@ +import { CleanupService } from './cleanup.service'; +import { PrismaService } from './prisma.service'; + +describe('CleanupService', () => { + let service: CleanupService; + let prisma: jest.Mocked>; + + beforeEach(() => { + prisma = { + blacklistedToken: { + findMany: jest.fn().mockResolvedValue([]), + deleteMany: jest.fn().mockResolvedValue({ count: 0 }), + } as any, + passwordResetToken: { + findMany: jest.fn().mockResolvedValue([]), + deleteMany: jest.fn().mockResolvedValue({ count: 0 }), + } as any, + session: { + findMany: jest.fn().mockResolvedValue([]), + deleteMany: jest.fn().mockResolvedValue({ count: 0 }), + } as any, + loginHistory: { + findMany: jest.fn().mockResolvedValue([]), + deleteMany: jest.fn().mockResolvedValue({ count: 0 }), + } as any, + }; + service = new CleanupService(prisma as unknown as PrismaService); + }); + + it('performCleanup returns summary with totalDeleted of 0 when no records exist', async () => { + const summary = await service.performCleanup(); + expect(summary.totalDeleted).toBe(0); + expect(summary.results).toHaveLength(4); + }); + + it('getLastSummary returns null before any cleanup run', () => { + const result = service.getLastSummary(); + expect(result).toBeNull(); + }); +}); \ No newline at end of file diff --git a/src/email/email-webhook.controller.ts b/src/email/email-webhook.controller.ts index 7900beae..ad056df3 100644 --- a/src/email/email-webhook.controller.ts +++ b/src/email/email-webhook.controller.ts @@ -1,4 +1,3 @@ -// @ts-nocheck import { Controller, Post, Body, Get, HttpCode, UseGuards } from '@nestjs/common'; import { EmailService } from './email.service'; diff --git a/src/email/email.module.ts b/src/email/email.module.ts index 0a1e459e..01f62482 100644 --- a/src/email/email.module.ts +++ b/src/email/email.module.ts @@ -1,4 +1,3 @@ -// @ts-nocheck import { Module } from '@nestjs/common'; import { EmailService } from './email.service'; diff --git a/src/email/email.processor.ts b/src/email/email.processor.ts index 487c5f6c..35cc327b 100644 --- a/src/email/email.processor.ts +++ b/src/email/email.processor.ts @@ -1,4 +1,3 @@ -// @ts-nocheck import { Processor, WorkerHost } from '@nestjs/bullmq'; import { Job } from 'bullmq'; @@ -33,7 +32,8 @@ export class EmailProcessor extends WorkerHost { context, }); this.logger.log(`Email sent successfully to ${to}`); - } catch (error) { + } catch (err: unknown) { + const error = err instanceof Error ? err : new Error(String(err)); this.logger.error(`Failed to send email to ${to}: ${error.message}`, error.stack); throw error; // BullMQ will handle retries if configured } diff --git a/src/email/email.service.ts b/src/email/email.service.ts index 70a4ef78..bdad9fe3 100644 --- a/src/email/email.service.ts +++ b/src/email/email.service.ts @@ -1,4 +1,3 @@ -// @ts-nocheck import { Injectable, Logger } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; @@ -264,7 +263,7 @@ export class EmailService { if (options.language && options.template) { const lang = options.language; const i18nKey = `email.${options.template}`; - const translated = this.i18nService.translate(i18nKey, lang, options.context); + const translated = this.i18nService.translate(i18nKey, { userPreference: lang }, options.context); if (translated !== i18nKey) { options.subject = options.subject || translated; } @@ -329,7 +328,8 @@ export class EmailService { ); this.logger.log(`📧 Email to ${options.to} queued for subject: ${options.subject}`); - } catch (error) { + } catch (err: unknown) { + const error = err instanceof Error ? err : new Error(String(err)); this.logger.error(`❌ Failed to queue email to ${options.to}: ${error.message}`); throw error; } @@ -347,7 +347,7 @@ export class EmailService { }); const language = user?.languagePreference || 'en'; - const translated = this.i18nService.translate(templateKey, language, params); + const translated = this.i18nService.translate(templateKey, { userPreference: language }, params); await this.sendEmail({ to, diff --git a/src/property-views/property-views.controller.ts b/src/property-views/property-views.controller.ts index 443f9c31..7ea66e15 100644 --- a/src/property-views/property-views.controller.ts +++ b/src/property-views/property-views.controller.ts @@ -1,4 +1,3 @@ -// @ts-nocheck import { BadRequestException, @@ -13,6 +12,10 @@ import { UseGuards, } from '@nestjs/common'; import { Request } from 'express'; + +interface RequestWithAuth extends Request { + authUser?: { sub: string }; +} import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { PropertyViewsService } from './property-views.service'; import { diff --git a/src/property-views/property-views.module.ts b/src/property-views/property-views.module.ts index 6f6af1da..fc09e461 100644 --- a/src/property-views/property-views.module.ts +++ b/src/property-views/property-views.module.ts @@ -1,4 +1,3 @@ -// @ts-nocheck import { Module } from '@nestjs/common'; import { PropertyViewsController } from './property-views.controller'; diff --git a/src/support-tickets/support-tickets.service.spec.ts b/src/support-tickets/support-tickets.service.spec.ts new file mode 100644 index 00000000..f6bdda15 --- /dev/null +++ b/src/support-tickets/support-tickets.service.spec.ts @@ -0,0 +1,34 @@ +import { SupportTicketsService } from './support-tickets.service'; +import { PrismaService } from '../database/prisma.service'; +import { NotificationsService } from '../notifications/notifications.service'; + +describe('SupportTicketsService', () => { + let service: SupportTicketsService; + let prisma: jest.Mocked>; + let notifications: jest.Mocked>; + + beforeEach(() => { + prisma = { + supportTicket: { + create: jest.fn().mockResolvedValue({ id: 'ticket-1', priority: 'HIGH', slaDeadline: new Date() }), + findUnique: jest.fn().mockResolvedValue(null), + findMany: jest.fn().mockResolvedValue([]), + update: jest.fn().mockResolvedValue({}), + } as any, + }; + notifications = { sendNotification: jest.fn().mockResolvedValue(undefined) }; + service = new SupportTicketsService( + prisma as unknown as PrismaService, + notifications as unknown as NotificationsService, + ); + }); + + it('creates a ticket with correct SLA deadline for HIGH priority', async () => { + const result = await service.createTicket('user-1', { + subject: 'Test', description: 'Desc', priority: 'HIGH', + } as any); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + expect(prisma.supportTicket!.create).toHaveBeenCalled(); + expect(result.id).toBe('ticket-1'); + }); +}); \ No newline at end of file