diff --git a/backend/src/modules/locations/driver-location.service.spec.ts b/backend/src/modules/locations/driver-location.service.spec.ts index a952fc1..72816d6 100644 --- a/backend/src/modules/locations/driver-location.service.spec.ts +++ b/backend/src/modules/locations/driver-location.service.spec.ts @@ -21,18 +21,27 @@ function fakeMatching() { } as any; } +/** الجيوفنس تعاونٌ جانبي لا يحجب النبضة — يكفي التأكّد أنه يُنادى. */ +function fakeGeofence() { + return { + processLocation: jest.fn().mockResolvedValue(undefined), + } as any; +} + describe('DriverLocationService', () => { let redis: any; let matching: ReturnType; let svc: DriverLocationService; let driversRepo: any; + let geofence: ReturnType; beforeEach(async () => { redis = new RedisMock({ keyPrefix: 'tripz:' }); await redis.flushall(); // المخزن مشترك بين نسخ ioredis-mock matching = fakeMatching(); + geofence = fakeGeofence(); driversRepo = { findOne: jest.fn().mockResolvedValue(null) }; - svc = new DriverLocationService(redis, driversRepo, matching); + svc = new DriverLocationService(redis, driversRepo, matching, geofence); }); it('أول نبضة ذات دلالة وتُخزَّن في Redis بلا قاعدة', async () => { @@ -59,6 +68,18 @@ describe('DriverLocationService', () => { expect(r.significant).toBe(false); expect(await redis.llen('loc:tracks')).toBe(tracksBefore); expect(matching.setPosition).not.toHaveBeenCalled(); + expect(geofence.processLocation).not.toHaveBeenCalled(); + }); + + it('نبضة ذات دلالة تُغذّي الجيوفنس ولا تُسقطها إن فشل', async () => { + geofence.processLocation.mockRejectedValue(new Error('geofence down')); + + const r = await svc.update(TENANT, DRIVER, CLASS, BASE); + + expect(r.significant).toBe(true); // الجيوفنس تعاون جانبي لا يُفشل النبضة + expect(geofence.processLocation).toHaveBeenCalledWith( + TENANT, DRIVER, 'driver', BASE.lat, BASE.lng, + ); }); it('تحرّك أكثر من 10م = دلالة + نقطة مسار + تحديث الفهرس', async () => {