Update planner, check-in records, location service and tests
AI Code Review / review (pull_request) Successful in 6m54s

This commit is contained in:
周瑞哲
2026-07-31 15:12:21 +08:00
parent 73664ca974
commit c0ed0048aa
11 changed files with 174 additions and 53 deletions
+17 -1
View File
@@ -1,5 +1,9 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { getCurrentGcj02Location, isLocationPermissionDenied } from '../src/services/location'
import {
getCurrentGcj02Location,
isLocationPermissionDenied,
isLocationSnapshotFresh,
} from '../src/services/location'
describe('current location adapter', () => {
beforeEach(() => {
@@ -73,4 +77,16 @@ describe('current location adapter', () => {
expect(isLocationPermissionDenied({ errMsg: 'getLocation:fail privacy permission is not authorized' })).toBe(false)
expect(isLocationPermissionDenied({ errMsg: 'getLocation:fail system error' })).toBe(false)
})
it('evaluates location freshness at exact boundaries and rejects invalid clocks', () => {
const capturedAt = '2026-07-31T02:00:00.000Z'
const capturedTimestamp = Date.parse(capturedAt)
const maxAgeMs = 5 * 60 * 1000
expect(isLocationSnapshotFresh(capturedAt, capturedTimestamp, maxAgeMs)).toBe(true)
expect(isLocationSnapshotFresh(capturedAt, capturedTimestamp + maxAgeMs, maxAgeMs)).toBe(true)
expect(isLocationSnapshotFresh(capturedAt, capturedTimestamp + maxAgeMs + 1, maxAgeMs)).toBe(false)
expect(isLocationSnapshotFresh(capturedAt, capturedTimestamp - 1, maxAgeMs)).toBe(false)
expect(isLocationSnapshotFresh('invalid', capturedTimestamp, maxAgeMs)).toBe(false)
})
})