From 810f696970c88c8b43ddb9e71b31baef21238191 Mon Sep 17 00:00:00 2001 From: zichun Date: Thu, 30 Apr 2026 14:58:38 +0800 Subject: [PATCH] test(usr): update stub regression to authenticated REQ-USR-004 --- backend/src/test/java/com/xly/erp/module/mod/controller/ModuleControllerIT.java | 37 +++++++++++++++++-------------------- backend/src/test/java/com/xly/erp/module/usr/controller/UserControllerIT.java | 26 ++++++++++++-------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/backend/src/test/java/com/xly/erp/module/mod/controller/ModuleControllerIT.java b/backend/src/test/java/com/xly/erp/module/mod/controller/ModuleControllerIT.java index 8998e35..5c48214 100644 --- a/backend/src/test/java/com/xly/erp/module/mod/controller/ModuleControllerIT.java +++ b/backend/src/test/java/com/xly/erp/module/mod/controller/ModuleControllerIT.java @@ -139,19 +139,17 @@ class ModuleControllerIT { } @Test - void postWithoutJwt_permitAllStub_returns200_andCreatedBySTUBADMIN() throws Exception { + void postWithoutJwt_returns20001() throws Exception { HttpHeaders headers = jsonHeaders(); Map body = validBody("sp_test_nojwt", "无JWT"); ResponseEntity resp = rest.exchange( url(), HttpMethod.POST, new HttpEntity<>(body, headers), String.class); - JsonNode jb = objectMapper.readTree(resp.getBody()); - assertThat(jb.get("code").asInt()).isZero(); - int newId = jb.get("data").get("iIncrement").asInt(); - String createdBy = jdbcTemplate.queryForObject( - "SELECT sCreatedBy FROM tModule WHERE iIncrement = ?", String.class, newId); - assertThat(createdBy).isEqualTo("STUB_ADMIN"); + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); + Integer count = jdbcTemplate.queryForObject( + "SELECT COUNT(1) FROM tModule WHERE sProcedureName = 'sp_test_nojwt'", Integer.class); + assertThat(count).isZero(); } @Test @@ -260,7 +258,7 @@ class ModuleControllerIT { } @Test - void putWithoutJwt_permitAllStub_returns200_andDoesNotChangeCreatedBy() throws Exception { + void putWithoutJwt_returns20001() throws Exception { Integer id = insertOriginal("sp_test_put_nojwt", "原", "ORIG_USER"); HttpHeaders headers = jsonHeaders(); Map body = updateBody(); @@ -269,10 +267,10 @@ class ModuleControllerIT { ResponseEntity resp = rest.exchange( idUrl(id), HttpMethod.PUT, new HttpEntity<>(body, headers), String.class); - assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isZero(); - String createdBy = jdbcTemplate.queryForObject( - "SELECT sCreatedBy FROM tModule WHERE iIncrement = ?", String.class, id); - assertThat(createdBy).isEqualTo("ORIG_USER"); + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); + String name = jdbcTemplate.queryForObject( + "SELECT sModuleNameZh FROM tModule WHERE iIncrement = ?", String.class, id); + assertThat(name).isEqualTo("原"); } @Test @@ -359,18 +357,17 @@ class ModuleControllerIT { } @Test - void deleteWithoutJwt_permitAllStub_returns200_andDeletedByIsSTUB() throws Exception { + void deleteWithoutJwt_returns20001() throws Exception { Integer id = insertOriginal("sp_test_del_nojwt", "原", "ORIG"); HttpHeaders headers = jsonHeaders(); ResponseEntity resp = rest.exchange( idUrl(id), HttpMethod.DELETE, new HttpEntity<>(headers), String.class); - assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isZero(); - Map row = jdbcTemplate.queryForMap( - "SELECT bDeleted, sDeletedBy FROM tModule WHERE iIncrement = ?", id); - assertThat(row.get("bDeleted")).isEqualTo(true); - assertThat(row.get("sDeletedBy")).isEqualTo("STUB_ADMIN"); + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); + Boolean stillAlive = jdbcTemplate.queryForObject( + "SELECT bDeleted FROM tModule WHERE iIncrement = ?", Boolean.class, id); + assertThat(stillAlive).isFalse(); } @Test @@ -463,11 +460,11 @@ class ModuleControllerIT { } @Test - void getWithoutJwt_permitAllStub_returns200() throws Exception { + void getWithoutJwt_returns20001() throws Exception { HttpHeaders headers = jsonHeaders(); ResponseEntity resp = rest.exchange( listUrl(null), HttpMethod.GET, new HttpEntity<>(headers), String.class); - assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isZero(); + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); } @Test diff --git a/backend/src/test/java/com/xly/erp/module/usr/controller/UserControllerIT.java b/backend/src/test/java/com/xly/erp/module/usr/controller/UserControllerIT.java index 5ba255c..0efb929 100644 --- a/backend/src/test/java/com/xly/erp/module/usr/controller/UserControllerIT.java +++ b/backend/src/test/java/com/xly/erp/module/usr/controller/UserControllerIT.java @@ -167,19 +167,17 @@ class UserControllerIT { } @Test - void postWithoutJwt_permitAllStub_returns200_andCreatedBySTUBADMIN() throws Exception { + void postWithoutJwt_returns20001() throws Exception { HttpHeaders headers = jsonHeaders(); Map body = baseBody("sp_test_u_nojwt", "无JWT"); ResponseEntity resp = rest.exchange( url(), HttpMethod.POST, new HttpEntity<>(body, headers), String.class); - JsonNode jb = objectMapper.readTree(resp.getBody()); - assertThat(jb.get("code").asInt()).isZero(); - int newId = jb.get("data").get("iIncrement").asInt(); - String createdBy = jdbcTemplate.queryForObject( - "SELECT sCreatedBy FROM tUser WHERE iIncrement = ?", String.class, newId); - assertThat(createdBy).isEqualTo("STUB_ADMIN"); + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); + Integer count = jdbcTemplate.queryForObject( + "SELECT COUNT(1) FROM tUser WHERE sUserNo = 'sp_test_u_nojwt'", Integer.class); + assertThat(count).isZero(); } @Test @@ -340,7 +338,7 @@ class UserControllerIT { } @Test - void putWithoutJwt_permitAllStub_returns200_andDoesNotChangeCreatedBy() throws Exception { + void putWithoutJwt_returns20001() throws Exception { Integer userId = insertUserWithPerms("sp_test_u_pnojwt", "原", null, null); HttpHeaders headers = jsonHeaders(); Map body = baseBody("sp_test_u_pnojwt", "改"); @@ -348,10 +346,10 @@ class UserControllerIT { ResponseEntity resp = rest.exchange( idUrl(userId), HttpMethod.PUT, new HttpEntity<>(body, headers), String.class); - assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isZero(); - String createdBy = jdbcTemplate.queryForObject( - "SELECT sCreatedBy FROM tUser WHERE iIncrement = ?", String.class, userId); - assertThat(createdBy).isEqualTo("ORIG_CREATOR"); + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); + String name = jdbcTemplate.queryForObject( + "SELECT sUserName FROM tUser WHERE iIncrement = ?", String.class, userId); + assertThat(name).isEqualTo("原"); } @Test @@ -459,11 +457,11 @@ class UserControllerIT { } @Test - void getWithoutJwt_permitAllStub_returns200() throws Exception { + void getWithoutJwt_returns20001() throws Exception { HttpHeaders headers = jsonHeaders(); ResponseEntity resp = rest.exchange( listUrl(""), HttpMethod.GET, new HttpEntity<>(headers), String.class); - assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isZero(); + assertThat(objectMapper.readTree(resp.getBody()).get("code").asInt()).isEqualTo(20001); } @Test -- libgit2 0.22.2