Add SKIP_GPS_VALIDATION feature for attendance and visit services
- Introduced SKIP_GPS_VALIDATION environment variable to control GPS validation during check-ins and check-outs. - Updated loadEnv function to parse SKIP_GPS_VALIDATION and enforce its rules based on NODE_ENV. - Enhanced attendance and visit services to utilize the new configuration, allowing GPS validation to be skipped in development environments. - Added unit tests to verify the behavior of SKIP_GPS_VALIDATION in various scenarios, ensuring proper handling in both production and development contexts. - Updated check-in verification logic to respect the SKIP_GPS_VALIDATION option, improving flexibility in location checks.
This commit is contained in:
@@ -17,6 +17,7 @@ describe('loadEnv', () => {
|
||||
expect(env.REFRESH_TOKEN_EXPIRES_IN_MS).toBe(7 * 24 * 60 * 60 * 1000);
|
||||
expect(env.BCRYPT_SALT_ROUNDS).toBe(10);
|
||||
expect(env.DEFAULT_TIMEZONE).toBe('GMT+7');
|
||||
expect(env.SKIP_GPS_VALIDATION).toBe(false);
|
||||
});
|
||||
|
||||
it('throws when DATABASE_URL is missing', () => {
|
||||
@@ -75,4 +76,33 @@ describe('loadEnv', () => {
|
||||
}),
|
||||
).toThrow('must match');
|
||||
});
|
||||
|
||||
it('enables SKIP_GPS_VALIDATION outside production', () => {
|
||||
const env = loadEnv({
|
||||
...valid,
|
||||
SKIP_GPS_VALIDATION: 'true',
|
||||
NODE_ENV: 'development',
|
||||
});
|
||||
|
||||
expect(env.SKIP_GPS_VALIDATION).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects SKIP_GPS_VALIDATION in production', () => {
|
||||
expect(() =>
|
||||
loadEnv({
|
||||
...valid,
|
||||
SKIP_GPS_VALIDATION: 'true',
|
||||
NODE_ENV: 'production',
|
||||
}),
|
||||
).toThrow('cannot be enabled in production');
|
||||
});
|
||||
|
||||
it('rejects invalid SKIP_GPS_VALIDATION values', () => {
|
||||
expect(() =>
|
||||
loadEnv({
|
||||
...valid,
|
||||
SKIP_GPS_VALIDATION: 'yes',
|
||||
}),
|
||||
).toThrow('must be true or false');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user