|
@@ -20,6 +20,7 @@ import java.util.Date;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.mock;
|
|
@@ -125,6 +126,28 @@ class TrainAttendCodeissueContractTest {
|
|
|
verify(codeMapper, never()).insert(any(TrainAttendanceCode.class));
|
|
verify(codeMapper, never()).insert(any(TrainAttendanceCode.class));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 过期 active 码不得被幂等复用:必须轮换旧码并签发一枚全新的 active 码。
|
|
|
|
|
+ * 对应 SRS §5.5「签到码含批次+场次+时效,过期/作废后失效,可轮换」中「过期后失效、可轮换」边界,
|
|
|
|
|
+ * 现有契约单测仅覆盖「未过期码 replay 复用」,未覆盖过期码必须重新签发。
|
|
|
|
|
+ */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void expiredActiveCodeIsNotReusedAndNewCodeIsIssued() {
|
|
|
|
|
+ stubCohortExists();
|
|
|
|
|
+ TrainAttendanceCode expired = activeCode(480, "theory");
|
|
|
|
|
+ expired.setValidTo(new Date(System.currentTimeMillis() - 60_000L)); // 已过期
|
|
|
|
|
+ when(codeMapper.selectOne(any())).thenReturn(expired);
|
|
|
|
|
+ when(codeMapper.selectList(any())).thenReturn(Collections.singletonList(expired));
|
|
|
|
|
+
|
|
|
|
|
+ Result<Map<String, Object>> r = service.issueCode(true, ADMIN_ID, SESSION_ID, 480, "theory", "expired");
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(CODE_OK, r.getCode());
|
|
|
|
|
+ assertNotNull(r.getData(), "过期码必须重新签发,返回新码");
|
|
|
|
|
+ assertNotEquals(OLD_CODE, r.getData().get("code"), "过期 active 码不得被幂等复用,必须签发新码");
|
|
|
|
|
+ verify(codeMapper).insert(any(TrainAttendanceCode.class));
|
|
|
|
|
+ verify(codeMapper).updateById(any(TrainAttendanceCode.class)); // 旧码轮换为 rotated
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ==================== 边界 1:同键异载荷 C4092 ====================
|
|
// ==================== 边界 1:同键异载荷 C4092 ====================
|
|
|
|
|
|
|
|
/**
|
|
/**
|