Commit e1342b63a06d7387310b9d2347bdf112bdd7ced0
1 parent
bb041e74
test(mod): module update integration coverage REQ-MOD-002
Showing
1 changed file
with
94 additions
and
0 deletions
backend/src/test/java/com/xly/erp/module/mod/controller/ModuleControllerIT.java
| ... | ... | @@ -193,6 +193,100 @@ class ModuleControllerIT { |
| 193 | 193 | assertThat(row.get("sCreatedBy")).isEqualTo("ORIG_USER"); |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | + @Test | |
| 197 | + void putNonExistentId_returns40400() throws Exception { | |
| 198 | + String token = testJwtHelper.signFor("ADMIN001"); | |
| 199 | + HttpHeaders headers = jsonHeaders(); | |
| 200 | + headers.set("Authorization", "Bearer " + token); | |
| 201 | + | |
| 202 | + ResponseEntity<String> resp = rest.exchange( | |
| 203 | + idUrl(99999998), HttpMethod.PUT, new HttpEntity<>(updateBody(), headers), String.class); | |
| 204 | + | |
| 205 | + JsonNode jb = objectMapper.readTree(resp.getBody()); | |
| 206 | + assertThat(jb.get("code").asInt()).isEqualTo(40400); | |
| 207 | + } | |
| 208 | + | |
| 209 | + @Test | |
| 210 | + void putInvalidDisplayType_returns40010() throws Exception { | |
| 211 | + Integer id = insertOriginal("sp_test_put_invalidtype", "原", "ORIG"); | |
| 212 | + String token = testJwtHelper.signFor("ADMIN001"); | |
| 213 | + HttpHeaders headers = jsonHeaders(); | |
| 214 | + headers.set("Authorization", "Bearer " + token); | |
| 215 | + Map<String, Object> body = updateBody(); | |
| 216 | + body.put("sDisplayType", "火星"); | |
| 217 | + | |
| 218 | + ResponseEntity<String> resp = rest.exchange( | |
| 219 | + idUrl(id), HttpMethod.PUT, new HttpEntity<>(body, headers), String.class); | |
| 220 | + | |
| 221 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(40010); | |
| 222 | + } | |
| 223 | + | |
| 224 | + @Test | |
| 225 | + void putSelfParent_returns40021() throws Exception { | |
| 226 | + Integer id = insertOriginal("sp_test_put_self", "原", "ORIG"); | |
| 227 | + String token = testJwtHelper.signFor("ADMIN001"); | |
| 228 | + HttpHeaders headers = jsonHeaders(); | |
| 229 | + headers.set("Authorization", "Bearer " + token); | |
| 230 | + Map<String, Object> body = updateBody(); | |
| 231 | + body.put("iParentId", id); | |
| 232 | + | |
| 233 | + ResponseEntity<String> resp = rest.exchange( | |
| 234 | + idUrl(id), HttpMethod.PUT, new HttpEntity<>(body, headers), String.class); | |
| 235 | + | |
| 236 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(40021); | |
| 237 | + } | |
| 238 | + | |
| 239 | + @Test | |
| 240 | + void putCyclicParent_returns40021() throws Exception { | |
| 241 | + Integer rootId = insertOriginal("sp_test_put_root", "根", "ORIG"); | |
| 242 | + jdbcTemplate.update( | |
| 243 | + "INSERT INTO tModule (sBrandsId, sSubsidiaryId, tCreateDate, sDisplayType, sProcedureName, " | |
| 244 | + + "sModuleType, sManageDeptEn, bShowPermission, sModuleNameZh, iParentId, iSortOrder, sCreatedBy, bDeleted) " | |
| 245 | + + "VALUES ('XLY','XLY', NOW(), '手机端', 'sp_test_put_child', '业务模块', 'IT', 0, '子', ?, 0, 'ORIG', 0)", | |
| 246 | + rootId); | |
| 247 | + Integer childId = jdbcTemplate.queryForObject( | |
| 248 | + "SELECT iIncrement FROM tModule WHERE sProcedureName = 'sp_test_put_child'", Integer.class); | |
| 249 | + | |
| 250 | + String token = testJwtHelper.signFor("ADMIN001"); | |
| 251 | + HttpHeaders headers = jsonHeaders(); | |
| 252 | + headers.set("Authorization", "Bearer " + token); | |
| 253 | + Map<String, Object> body = updateBody(); | |
| 254 | + body.put("iParentId", childId); | |
| 255 | + | |
| 256 | + ResponseEntity<String> resp = rest.exchange( | |
| 257 | + idUrl(rootId), HttpMethod.PUT, new HttpEntity<>(body, headers), String.class); | |
| 258 | + | |
| 259 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(40021); | |
| 260 | + } | |
| 261 | + | |
| 262 | + @Test | |
| 263 | + void putWithoutJwt_permitAllStub_returns200_andDoesNotChangeCreatedBy() throws Exception { | |
| 264 | + Integer id = insertOriginal("sp_test_put_nojwt", "原", "ORIG_USER"); | |
| 265 | + HttpHeaders headers = jsonHeaders(); | |
| 266 | + Map<String, Object> body = updateBody(); | |
| 267 | + body.put("sModuleNameZh", "更新无jwt"); | |
| 268 | + | |
| 269 | + ResponseEntity<String> resp = rest.exchange( | |
| 270 | + idUrl(id), HttpMethod.PUT, new HttpEntity<>(body, headers), String.class); | |
| 271 | + | |
| 272 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isZero(); | |
| 273 | + String createdBy = jdbcTemplate.queryForObject( | |
| 274 | + "SELECT sCreatedBy FROM tModule WHERE iIncrement = ?", String.class, id); | |
| 275 | + assertThat(createdBy).isEqualTo("ORIG_USER"); | |
| 276 | + } | |
| 277 | + | |
| 278 | + @Test | |
| 279 | + void putTamperedJwt_returns20001() throws Exception { | |
| 280 | + Integer id = insertOriginal("sp_test_put_tamper", "原", "ORIG"); | |
| 281 | + HttpHeaders headers = jsonHeaders(); | |
| 282 | + headers.set("Authorization", "Bearer not.a.real.jwt"); | |
| 283 | + | |
| 284 | + ResponseEntity<String> resp = rest.exchange( | |
| 285 | + idUrl(id), HttpMethod.PUT, new HttpEntity<>(updateBody(), headers), String.class); | |
| 286 | + | |
| 287 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); | |
| 288 | + } | |
| 289 | + | |
| 196 | 290 | private Integer insertOriginal(String procedureName, String nameZh, String createdBy) { |
| 197 | 291 | jdbcTemplate.update( |
| 198 | 292 | "INSERT INTO tModule (sBrandsId, sSubsidiaryId, tCreateDate, sDisplayType, sProcedureName, " | ... | ... |