- Introduced new `attendances` and `visits` tables to manage employee attendance and customer visits, including relevant fields for check-in and check-out details. - Updated `company_settings` to include a `check_in_radius_meters` column for attendance validation. - Implemented foreign key constraints to ensure data integrity between `attendances`, `visits`, `employees`, `branches`, and other related entities. - Created new services and controllers for handling attendance and visit operations, including check-in, check-out, and bulk actions. - Enhanced DTOs for attendance and visit data transfer, including validation for input data. - Added unit and integration tests to validate the new functionalities and ensure proper handling of attendance and visit records. - Created migration scripts to apply the necessary database schema changes for the new features.
63 lines
1.3 KiB
TypeScript
63 lines
1.3 KiB
TypeScript
import {
|
|
verifyBranchCheckIn,
|
|
verifyCustomerCheckIn,
|
|
} from './check-in-verification';
|
|
import { haversineDistanceMeters } from './geo-distance';
|
|
|
|
describe('geo-distance', () => {
|
|
it('returns zero for identical coordinates', () => {
|
|
expect(haversineDistanceMeters(-6.2, 106.8, -6.2, 106.8)).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('check-in-verification', () => {
|
|
const target = {
|
|
code: 'BR001',
|
|
nfcId: 'nfc-123',
|
|
latitude: -6.2,
|
|
longitude: 106.8,
|
|
};
|
|
|
|
it('accepts matching NFC tag', () => {
|
|
const result = verifyBranchCheckIn(
|
|
target,
|
|
{
|
|
method: 'nfc',
|
|
nfcId: 'nfc-123',
|
|
latitude: -6.2,
|
|
longitude: 106.8,
|
|
},
|
|
100,
|
|
);
|
|
expect(result.method).toBe('nfc');
|
|
});
|
|
|
|
it('accepts matching QR code', () => {
|
|
const result = verifyBranchCheckIn(
|
|
target,
|
|
{
|
|
method: 'qr',
|
|
qrCode: 'BR001',
|
|
latitude: -6.2,
|
|
longitude: 106.8,
|
|
},
|
|
100,
|
|
);
|
|
expect(result.method).toBe('qr');
|
|
});
|
|
|
|
it('rejects GPS when too far', () => {
|
|
expect(() =>
|
|
verifyCustomerCheckIn(
|
|
target,
|
|
{
|
|
method: 'gps',
|
|
latitude: -7,
|
|
longitude: 107.5,
|
|
},
|
|
100,
|
|
),
|
|
).toThrow('Too far from the customer location');
|
|
});
|
|
});
|