Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions services/driver-service/src/services/admin-drivers.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ describe('AdminDriversService (#214)', () => {
expect(result.items[0]).not.toHaveProperty('nationalIdHash');
});

it('passes the status and verificationStatus filters straight through to the repository', async () => {
const { service, drivers, lookups } = setup();
drivers.findForAdmin.mockResolvedValue([[], 0]);
lookups.names.mockResolvedValue(new Map());

await service.list(listQuery({ status: 'OFFLINE' as never, verificationStatus: 'PENDING' as never }));

expect(drivers.findForAdmin).toHaveBeenCalledWith(expect.objectContaining({ status: 'OFFLINE', verificationStatus: 'PENDING' }), 1, 20);
});

it('never exposes secret fields: the staff driver row has a fixed shape', async () => {
const { service, drivers, lookups } = setup();
drivers.findForAdmin.mockResolvedValue([[driver('d1', 'u1')], 1]);
lookups.names.mockResolvedValue(new Map());

const row = (await service.list(listQuery())).items[0];

expect(Object.keys(row).sort()).toEqual(
['createdAt', 'drivingLicenceExpiresOn', 'fullName', 'id', 'licensePlate', 'status', 'submittedAt', 'userId', 'vehicleLicenceExpiresOn', 'vehicleType', 'verificationStatus', 'verifiedAt'].sort(),
);
expect(row).not.toHaveProperty('nationalIdHash');
expect(JSON.stringify(row)).not.toContain('secret-hash');
});

it('shows names as null, never made up, when user-service does not answer', async () => {
const { service, drivers, lookups } = setup();
drivers.findForAdmin.mockResolvedValue([[driver('d1', 'u1')], 1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ describe('AdminRestaurantsService (#214)', () => {
expect(result.items[0]).not.toHaveProperty('taxCardNumber');
});

it('passes the approvalStatus and status filters straight through, and no area when it is partial', async () => {
const { service, restaurants, lookups } = setup();
restaurants.findForAdmin.mockResolvedValue([[], 0]);
lookups.names.mockResolvedValue(new Map());

await service.list(Object.assign(new AdminListRestaurantsQueryDto(), { approvalStatus: 'SUBMITTED' as never, status: 'OPEN' as never, nearLat: 30 }));

expect(restaurants.findForAdmin).toHaveBeenCalledWith(
expect.objectContaining({ approvalStatus: 'SUBMITTED', status: 'OPEN', near: undefined }),
1,
20,
);
});

it('never exposes secret fields: the staff restaurant row has a fixed shape', async () => {
const { service, restaurants, lookups } = setup();
restaurants.findForAdmin.mockResolvedValue([[restaurant('r1', 'o1')], 1]);
lookups.names.mockResolvedValue(new Map());

const row = (await service.list(Object.assign(new AdminListRestaurantsQueryDto()))).items[0];

expect(Object.keys(row).sort()).toEqual(
['address', 'approvalStatus', 'approvedAt', 'contactPhone', 'createdAt', 'deliveryRadiusKm', 'id', 'latitude', 'longitude', 'name', 'ownerId', 'ownerName', 'status', 'submittedAt'].sort(),
);
expect(row).not.toHaveProperty('taxCardNumber');
expect(row).not.toHaveProperty('commercialRegistrationNumber');
expect(JSON.stringify(row)).not.toContain('123');
});

it('searches by the exact phone', async () => {
const { service, restaurants, lookups } = setup();
restaurants.findByContactPhone.mockResolvedValue([restaurant('r1', 'o1')]);
Expand Down
Loading