Commit 810f696970c88c8b43ddb9e71b31baef21238191
1 parent
3a625ce9
test(usr): update stub regression to authenticated REQ-USR-004
Showing
2 changed files
with
29 additions
and
34 deletions
backend/src/test/java/com/xly/erp/module/mod/controller/ModuleControllerIT.java
| @@ -139,19 +139,17 @@ class ModuleControllerIT { | @@ -139,19 +139,17 @@ class ModuleControllerIT { | ||
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | @Test | 141 | @Test |
| 142 | - void postWithoutJwt_permitAllStub_returns200_andCreatedBySTUBADMIN() throws Exception { | 142 | + void postWithoutJwt_returns20001() throws Exception { |
| 143 | HttpHeaders headers = jsonHeaders(); | 143 | HttpHeaders headers = jsonHeaders(); |
| 144 | Map<String, Object> body = validBody("sp_test_nojwt", "无JWT"); | 144 | Map<String, Object> body = validBody("sp_test_nojwt", "无JWT"); |
| 145 | 145 | ||
| 146 | ResponseEntity<String> resp = rest.exchange( | 146 | ResponseEntity<String> resp = rest.exchange( |
| 147 | url(), HttpMethod.POST, new HttpEntity<>(body, headers), String.class); | 147 | url(), HttpMethod.POST, new HttpEntity<>(body, headers), String.class); |
| 148 | 148 | ||
| 149 | - JsonNode jb = objectMapper.readTree(resp.getBody()); | ||
| 150 | - assertThat(jb.get("code").asInt()).isZero(); | ||
| 151 | - int newId = jb.get("data").get("iIncrement").asInt(); | ||
| 152 | - String createdBy = jdbcTemplate.queryForObject( | ||
| 153 | - "SELECT sCreatedBy FROM tModule WHERE iIncrement = ?", String.class, newId); | ||
| 154 | - assertThat(createdBy).isEqualTo("STUB_ADMIN"); | 149 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); |
| 150 | + Integer count = jdbcTemplate.queryForObject( | ||
| 151 | + "SELECT COUNT(1) FROM tModule WHERE sProcedureName = 'sp_test_nojwt'", Integer.class); | ||
| 152 | + assertThat(count).isZero(); | ||
| 155 | } | 153 | } |
| 156 | 154 | ||
| 157 | @Test | 155 | @Test |
| @@ -260,7 +258,7 @@ class ModuleControllerIT { | @@ -260,7 +258,7 @@ class ModuleControllerIT { | ||
| 260 | } | 258 | } |
| 261 | 259 | ||
| 262 | @Test | 260 | @Test |
| 263 | - void putWithoutJwt_permitAllStub_returns200_andDoesNotChangeCreatedBy() throws Exception { | 261 | + void putWithoutJwt_returns20001() throws Exception { |
| 264 | Integer id = insertOriginal("sp_test_put_nojwt", "原", "ORIG_USER"); | 262 | Integer id = insertOriginal("sp_test_put_nojwt", "原", "ORIG_USER"); |
| 265 | HttpHeaders headers = jsonHeaders(); | 263 | HttpHeaders headers = jsonHeaders(); |
| 266 | Map<String, Object> body = updateBody(); | 264 | Map<String, Object> body = updateBody(); |
| @@ -269,10 +267,10 @@ class ModuleControllerIT { | @@ -269,10 +267,10 @@ class ModuleControllerIT { | ||
| 269 | ResponseEntity<String> resp = rest.exchange( | 267 | ResponseEntity<String> resp = rest.exchange( |
| 270 | idUrl(id), HttpMethod.PUT, new HttpEntity<>(body, headers), String.class); | 268 | idUrl(id), HttpMethod.PUT, new HttpEntity<>(body, headers), String.class); |
| 271 | 269 | ||
| 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"); | 270 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); |
| 271 | + String name = jdbcTemplate.queryForObject( | ||
| 272 | + "SELECT sModuleNameZh FROM tModule WHERE iIncrement = ?", String.class, id); | ||
| 273 | + assertThat(name).isEqualTo("原"); | ||
| 276 | } | 274 | } |
| 277 | 275 | ||
| 278 | @Test | 276 | @Test |
| @@ -359,18 +357,17 @@ class ModuleControllerIT { | @@ -359,18 +357,17 @@ class ModuleControllerIT { | ||
| 359 | } | 357 | } |
| 360 | 358 | ||
| 361 | @Test | 359 | @Test |
| 362 | - void deleteWithoutJwt_permitAllStub_returns200_andDeletedByIsSTUB() throws Exception { | 360 | + void deleteWithoutJwt_returns20001() throws Exception { |
| 363 | Integer id = insertOriginal("sp_test_del_nojwt", "原", "ORIG"); | 361 | Integer id = insertOriginal("sp_test_del_nojwt", "原", "ORIG"); |
| 364 | HttpHeaders headers = jsonHeaders(); | 362 | HttpHeaders headers = jsonHeaders(); |
| 365 | 363 | ||
| 366 | ResponseEntity<String> resp = rest.exchange( | 364 | ResponseEntity<String> resp = rest.exchange( |
| 367 | idUrl(id), HttpMethod.DELETE, new HttpEntity<>(headers), String.class); | 365 | idUrl(id), HttpMethod.DELETE, new HttpEntity<>(headers), String.class); |
| 368 | 366 | ||
| 369 | - assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isZero(); | ||
| 370 | - Map<String, Object> row = jdbcTemplate.queryForMap( | ||
| 371 | - "SELECT bDeleted, sDeletedBy FROM tModule WHERE iIncrement = ?", id); | ||
| 372 | - assertThat(row.get("bDeleted")).isEqualTo(true); | ||
| 373 | - assertThat(row.get("sDeletedBy")).isEqualTo("STUB_ADMIN"); | 367 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); |
| 368 | + Boolean stillAlive = jdbcTemplate.queryForObject( | ||
| 369 | + "SELECT bDeleted FROM tModule WHERE iIncrement = ?", Boolean.class, id); | ||
| 370 | + assertThat(stillAlive).isFalse(); | ||
| 374 | } | 371 | } |
| 375 | 372 | ||
| 376 | @Test | 373 | @Test |
| @@ -463,11 +460,11 @@ class ModuleControllerIT { | @@ -463,11 +460,11 @@ class ModuleControllerIT { | ||
| 463 | } | 460 | } |
| 464 | 461 | ||
| 465 | @Test | 462 | @Test |
| 466 | - void getWithoutJwt_permitAllStub_returns200() throws Exception { | 463 | + void getWithoutJwt_returns20001() throws Exception { |
| 467 | HttpHeaders headers = jsonHeaders(); | 464 | HttpHeaders headers = jsonHeaders(); |
| 468 | ResponseEntity<String> resp = rest.exchange( | 465 | ResponseEntity<String> resp = rest.exchange( |
| 469 | listUrl(null), HttpMethod.GET, new HttpEntity<>(headers), String.class); | 466 | listUrl(null), HttpMethod.GET, new HttpEntity<>(headers), String.class); |
| 470 | - assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isZero(); | 467 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); |
| 471 | } | 468 | } |
| 472 | 469 | ||
| 473 | @Test | 470 | @Test |
backend/src/test/java/com/xly/erp/module/usr/controller/UserControllerIT.java
| @@ -167,19 +167,17 @@ class UserControllerIT { | @@ -167,19 +167,17 @@ class UserControllerIT { | ||
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | @Test | 169 | @Test |
| 170 | - void postWithoutJwt_permitAllStub_returns200_andCreatedBySTUBADMIN() throws Exception { | 170 | + void postWithoutJwt_returns20001() throws Exception { |
| 171 | HttpHeaders headers = jsonHeaders(); | 171 | HttpHeaders headers = jsonHeaders(); |
| 172 | Map<String, Object> body = baseBody("sp_test_u_nojwt", "无JWT"); | 172 | Map<String, Object> body = baseBody("sp_test_u_nojwt", "无JWT"); |
| 173 | 173 | ||
| 174 | ResponseEntity<String> resp = rest.exchange( | 174 | ResponseEntity<String> resp = rest.exchange( |
| 175 | url(), HttpMethod.POST, new HttpEntity<>(body, headers), String.class); | 175 | url(), HttpMethod.POST, new HttpEntity<>(body, headers), String.class); |
| 176 | 176 | ||
| 177 | - JsonNode jb = objectMapper.readTree(resp.getBody()); | ||
| 178 | - assertThat(jb.get("code").asInt()).isZero(); | ||
| 179 | - int newId = jb.get("data").get("iIncrement").asInt(); | ||
| 180 | - String createdBy = jdbcTemplate.queryForObject( | ||
| 181 | - "SELECT sCreatedBy FROM tUser WHERE iIncrement = ?", String.class, newId); | ||
| 182 | - assertThat(createdBy).isEqualTo("STUB_ADMIN"); | 177 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); |
| 178 | + Integer count = jdbcTemplate.queryForObject( | ||
| 179 | + "SELECT COUNT(1) FROM tUser WHERE sUserNo = 'sp_test_u_nojwt'", Integer.class); | ||
| 180 | + assertThat(count).isZero(); | ||
| 183 | } | 181 | } |
| 184 | 182 | ||
| 185 | @Test | 183 | @Test |
| @@ -340,7 +338,7 @@ class UserControllerIT { | @@ -340,7 +338,7 @@ class UserControllerIT { | ||
| 340 | } | 338 | } |
| 341 | 339 | ||
| 342 | @Test | 340 | @Test |
| 343 | - void putWithoutJwt_permitAllStub_returns200_andDoesNotChangeCreatedBy() throws Exception { | 341 | + void putWithoutJwt_returns20001() throws Exception { |
| 344 | Integer userId = insertUserWithPerms("sp_test_u_pnojwt", "原", null, null); | 342 | Integer userId = insertUserWithPerms("sp_test_u_pnojwt", "原", null, null); |
| 345 | HttpHeaders headers = jsonHeaders(); | 343 | HttpHeaders headers = jsonHeaders(); |
| 346 | Map<String, Object> body = baseBody("sp_test_u_pnojwt", "改"); | 344 | Map<String, Object> body = baseBody("sp_test_u_pnojwt", "改"); |
| @@ -348,10 +346,10 @@ class UserControllerIT { | @@ -348,10 +346,10 @@ class UserControllerIT { | ||
| 348 | ResponseEntity<String> resp = rest.exchange( | 346 | ResponseEntity<String> resp = rest.exchange( |
| 349 | idUrl(userId), HttpMethod.PUT, new HttpEntity<>(body, headers), String.class); | 347 | idUrl(userId), HttpMethod.PUT, new HttpEntity<>(body, headers), String.class); |
| 350 | 348 | ||
| 351 | - assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isZero(); | ||
| 352 | - String createdBy = jdbcTemplate.queryForObject( | ||
| 353 | - "SELECT sCreatedBy FROM tUser WHERE iIncrement = ?", String.class, userId); | ||
| 354 | - assertThat(createdBy).isEqualTo("ORIG_CREATOR"); | 349 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); |
| 350 | + String name = jdbcTemplate.queryForObject( | ||
| 351 | + "SELECT sUserName FROM tUser WHERE iIncrement = ?", String.class, userId); | ||
| 352 | + assertThat(name).isEqualTo("原"); | ||
| 355 | } | 353 | } |
| 356 | 354 | ||
| 357 | @Test | 355 | @Test |
| @@ -459,11 +457,11 @@ class UserControllerIT { | @@ -459,11 +457,11 @@ class UserControllerIT { | ||
| 459 | } | 457 | } |
| 460 | 458 | ||
| 461 | @Test | 459 | @Test |
| 462 | - void getWithoutJwt_permitAllStub_returns200() throws Exception { | 460 | + void getWithoutJwt_returns20001() throws Exception { |
| 463 | HttpHeaders headers = jsonHeaders(); | 461 | HttpHeaders headers = jsonHeaders(); |
| 464 | ResponseEntity<String> resp = rest.exchange( | 462 | ResponseEntity<String> resp = rest.exchange( |
| 465 | listUrl(""), HttpMethod.GET, new HttpEntity<>(headers), String.class); | 463 | listUrl(""), HttpMethod.GET, new HttpEntity<>(headers), String.class); |
| 466 | - assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isZero(); | 464 | + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); |
| 467 | } | 465 | } |
| 468 | 466 | ||
| 469 | @Test | 467 | @Test |