From 4db7af9301f9dc1624798724bc1a291107672fff Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sat, 18 Jul 2026 19:25:57 +0300 Subject: [PATCH] fix(tests): inject GeofenceService into DriverLocationService spec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit الاختبار بقي على constructor بثلاثة وسائط بعد إضافة الجيوفنس، فأسقط `npm test` وأوقف بناء الصورة — فلم يقلع الـAPI أصلاً على 4010. يضيف أيضاً تغطية للتعاون الجديد: الجيوفنس لا يُنادى على نبضة بلا دلالة، ولا يُفشل النبضة إذا سقط هو. Co-Authored-By: Claude Opus 4.8 --- .../locations/driver-location.service.spec.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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 () => {