Skip to content

Commit 1856503

Browse files
fix: add missing prisma mocks (findFirst, update, findMany) to property-views spec
1 parent 5ff8610 commit 1856503

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

‎src/property-views/property-views.service.spec.ts‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,36 @@ import { PrismaService } from '../database/prisma.service';
66
describe('PropertyViewsService', () => {
77
let service: PropertyViewsService;
88
let prisma: {
9-
property: { findUnique: jest.Mock };
10-
propertyView: { create: jest.Mock; findMany: jest.Mock; count: jest.Mock; groupBy: jest.Mock };
9+
property: { findUnique: jest.Mock; update: jest.Mock; findMany: jest.Mock };
10+
propertyView: {
11+
create: jest.Mock;
12+
findMany: jest.Mock;
13+
count: jest.Mock;
14+
groupBy: jest.Mock;
15+
findFirst: jest.Mock;
16+
};
1117
$transaction: jest.Mock;
1218
};
1319

1420
beforeEach(async () => {
1521
prisma = {
1622
property: {
1723
findUnique: jest.fn(),
24+
update: jest.fn(),
25+
findMany: jest.fn().mockResolvedValue([]),
1826
},
1927
propertyView: {
2028
create: jest.fn(),
2129
findMany: jest.fn().mockResolvedValue([]),
2230
count: jest.fn().mockResolvedValue(0),
2331
groupBy: jest.fn().mockResolvedValue([]),
32+
findFirst: jest.fn().mockResolvedValue(null),
2433
},
2534
$transaction: jest.fn(),
2635
};
2736

2837
const module: TestingModule = await Test.createTestingModule({
29-
providers: [
30-
PropertyViewsService,
31-
{ provide: PrismaService, useValue: prisma },
32-
],
38+
providers: [PropertyViewsService, { provide: PrismaService, useValue: prisma }],
3339
}).compile();
3440

3541
service = module.get<PropertyViewsService>(PropertyViewsService);
@@ -43,9 +49,9 @@ describe('PropertyViewsService', () => {
4349
it('should throw NotFoundException for non-existent property', async () => {
4450
prisma.property.findUnique.mockResolvedValue(null);
4551

46-
await expect(
47-
service.recordView('non-existent', { ipAddress: '127.0.0.1' }),
48-
).rejects.toThrow(NotFoundException);
52+
await expect(service.recordView('non-existent', { ipAddress: '127.0.0.1' })).rejects.toThrow(
53+
NotFoundException,
54+
);
4955
});
5056

5157
it('should create a view and increment view count', async () => {
@@ -89,7 +95,11 @@ describe('PropertyViewsService', () => {
8995
it('should return unique visitor counts', async () => {
9096
prisma.propertyView.groupBy
9197
.mockResolvedValueOnce([{ userId: 'u1' }, { userId: 'u2' }])
92-
.mockResolvedValueOnce([{ ipAddress: '1.1.1.1' }, { ipAddress: '2.2.2.2' }, { ipAddress: '3.3.3.3' }]);
98+
.mockResolvedValueOnce([
99+
{ ipAddress: '1.1.1.1' },
100+
{ ipAddress: '2.2.2.2' },
101+
{ ipAddress: '3.3.3.3' },
102+
]);
93103

94104
const result = await service.getUniqueVisitorCount('prop-1');
95105

0 commit comments

Comments
 (0)