diff --git a/modules/backend-persistence/src/test/java/com/idea2strategy/backend/persistence/delegation/DelegationDisclosurePolicyMigrationIntegrationTest.java b/modules/backend-persistence/src/test/java/com/idea2strategy/backend/persistence/delegation/DelegationDisclosurePolicyMigrationIntegrationTest.java new file mode 100644 index 00000000..9a3b4304 --- /dev/null +++ b/modules/backend-persistence/src/test/java/com/idea2strategy/backend/persistence/delegation/DelegationDisclosurePolicyMigrationIntegrationTest.java @@ -0,0 +1,108 @@ +package com.idea2strategy.backend.persistence.delegation; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +/** + * Guards the disclosure a delegation is required to point at. + * + *
`identity.delegated_authorizations.disclosure_policy_document_id` is NOT NULL, so this + * document is not decoration: if the policy code resolves to nothing, delegation does not degrade, + * it stops. Both ways that has already happened are pinned here. + * + *
Publishing v2 with a future `published_at` retired v1 while v2 was not yet selectable and left + * the code with zero current documents — every grant failed. And publishing the disclosure as + * `is_required` put it in the set every account must consent to before it can finish + * authenticating, which blocked login for customers who never delegate anything. Neither failure + * is visible in the migration file being reviewed; both are visible here. + */ +@Testcontainers(disabledWithoutDocker = true) +@SpringBootTest(classes = DelegationDisclosurePolicyMigrationIntegrationTest.TestApplication.class) +class DelegationDisclosurePolicyMigrationIntegrationTest { + private static final String POLICY_CODE = "delegation.strategy-edit.disclosure"; + + @Container + static final PostgreSQLContainer POSTGRES = new PostgreSQLContainer("postgres:16-alpine"); + + @DynamicPropertySource + static void databaseProperties(DynamicPropertyRegistry registry) { + registry.add("spring.datasource.url", POSTGRES::getJdbcUrl); + registry.add("spring.datasource.username", POSTGRES::getUsername); + registry.add("spring.datasource.password", POSTGRES::getPassword); + registry.add("spring.jpa.hibernate.ddl-auto", () -> "none"); + registry.add("spring.flyway.enabled", () -> "true"); + } + + @Autowired + private JdbcTemplate jdbc; + + @Test + void resolvesToExactlyOneCurrentDocument() { + List