You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
2.4 KiB
48 lines
2.4 KiB
package com.mydreamjob.talentinvitation;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
|
|
import java.util.List;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
/** 只读验证 V42/V40 迁移在 H2 MODE=MySQL 中执行,且邀约历史不携带候选人敏感字段。 */
|
|
@SpringBootTest
|
|
@ActiveProfiles("integration-test")
|
|
class TalentInvitationPersistenceIntegrationTest {
|
|
@Autowired JdbcTemplate jdbcTemplate;
|
|
@MockBean RedisTemplate<String, Object> redisTemplate;
|
|
|
|
@Test
|
|
void v40Migration_createsInvitationTablesAndConstraints() {
|
|
assertThat(tableCount("TALENT_INVITATIONS")).isEqualTo(1);
|
|
assertThat(tableCount("TALENT_INVITATION_HISTORY")).isEqualTo(1);
|
|
String statusDefault = jdbcTemplate.queryForObject(
|
|
"SELECT COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='TALENT_INVITATIONS' AND COLUMN_NAME='STATUS'",
|
|
String.class);
|
|
assertThat(statusDefault).isIn("PENDING", "'PENDING'");
|
|
Integer idempotencyUnique = jdbcTemplate.queryForObject(
|
|
"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME='TALENT_INVITATIONS' "
|
|
+ "AND CONSTRAINT_NAME='UK_TALENT_INVITATIONS_IDEMPOTENCY' AND CONSTRAINT_TYPE='UNIQUE'", Integer.class);
|
|
assertThat(idempotencyUnique).isGreaterThanOrEqualTo(1);
|
|
}
|
|
|
|
@Test
|
|
void invitationHistory_containsNoStudentOrMessageColumns() {
|
|
List<String> columns = jdbcTemplate.queryForList(
|
|
"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='TALENT_INVITATION_HISTORY'",
|
|
String.class);
|
|
assertThat(columns).doesNotContain("STUDENT_USER_ID", "MESSAGE", "CANDIDATE_KEY", "PHONE", "EMAIL", "IP_ADDRESS", "USER_AGENT", "TOKEN", "PASSWORD");
|
|
assertThat(columns).contains("INVITATION_ID", "ACTION", "ACTOR_USER_ID", "CREATED_AT");
|
|
}
|
|
|
|
private int tableCount(String table) {
|
|
return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=?", Integer.class, table);
|
|
}
|
|
}
|
|
|