fix(tests): inject GeofenceService into DriverLocationService spec
الاختبار بقي على constructor بثلاثة وسائط بعد إضافة الجيوفنس، فأسقط `npm test` وأوقف بناء الصورة — فلم يقلع الـAPI أصلاً على 4010. يضيف أيضاً تغطية للتعاون الجديد: الجيوفنس لا يُنادى على نبضة بلا دلالة، ولا يُفشل النبضة إذا سقط هو. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ab5f2938d5
commit
4db7af9301
@@ -21,18 +21,27 @@ function fakeMatching() {
|
|||||||
} as any;
|
} as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** الجيوفنس تعاونٌ جانبي لا يحجب النبضة — يكفي التأكّد أنه يُنادى. */
|
||||||
|
function fakeGeofence() {
|
||||||
|
return {
|
||||||
|
processLocation: jest.fn().mockResolvedValue(undefined),
|
||||||
|
} as any;
|
||||||
|
}
|
||||||
|
|
||||||
describe('DriverLocationService', () => {
|
describe('DriverLocationService', () => {
|
||||||
let redis: any;
|
let redis: any;
|
||||||
let matching: ReturnType<typeof fakeMatching>;
|
let matching: ReturnType<typeof fakeMatching>;
|
||||||
let svc: DriverLocationService;
|
let svc: DriverLocationService;
|
||||||
let driversRepo: any;
|
let driversRepo: any;
|
||||||
|
let geofence: ReturnType<typeof fakeGeofence>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
redis = new RedisMock({ keyPrefix: 'tripz:' });
|
redis = new RedisMock({ keyPrefix: 'tripz:' });
|
||||||
await redis.flushall(); // المخزن مشترك بين نسخ ioredis-mock
|
await redis.flushall(); // المخزن مشترك بين نسخ ioredis-mock
|
||||||
matching = fakeMatching();
|
matching = fakeMatching();
|
||||||
|
geofence = fakeGeofence();
|
||||||
driversRepo = { findOne: jest.fn().mockResolvedValue(null) };
|
driversRepo = { findOne: jest.fn().mockResolvedValue(null) };
|
||||||
svc = new DriverLocationService(redis, driversRepo, matching);
|
svc = new DriverLocationService(redis, driversRepo, matching, geofence);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('أول نبضة ذات دلالة وتُخزَّن في Redis بلا قاعدة', async () => {
|
it('أول نبضة ذات دلالة وتُخزَّن في Redis بلا قاعدة', async () => {
|
||||||
@@ -59,6 +68,18 @@ describe('DriverLocationService', () => {
|
|||||||
expect(r.significant).toBe(false);
|
expect(r.significant).toBe(false);
|
||||||
expect(await redis.llen('loc:tracks')).toBe(tracksBefore);
|
expect(await redis.llen('loc:tracks')).toBe(tracksBefore);
|
||||||
expect(matching.setPosition).not.toHaveBeenCalled();
|
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 () => {
|
it('تحرّك أكثر من 10م = دلالة + نقطة مسار + تحديث الفهرس', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user