fix(test): tear down the organization DetectiveIntegrationTest creates (#3229)

DetectiveIntegrationTest creates an organization on account 000000000000
through the injected OrganizationsService and never deletes it. Organizations
state is shared by every @QuarkusTest class in the same Surefire fork, so any
class that lands in the same shard and later creates an organization under the
default account (OrganizationsIntegrationTest's @Order(1) createOrganization)
fails with AlreadyInOrganizationException and every ordered test after it
cascades.

Delete the organization in @AfterEach, guarded by a flag so the teardown only
runs for the test that created one and a single-method run of the class still
works.

Fixes #3226
This commit is contained in:
BingEdward authored and GitHub committed 2026-09-08 09:51:49 -04:00
1 parent 172765a808
commit 1a804ae547
1 file changed
+17
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.services.organizations.OrganizationsService;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -19,14 +20,30 @@ class DetectiveIntegrationTest {
@Inject
OrganizationsService organizationsService;
private boolean createdOrganization;
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
/**
* Organizations state is shared by every test in the JVM and keyed by the management account,
* so an organization left behind here makes the next class that creates one under
* {@code 000000000000} (e.g. {@code OrganizationsIntegrationTest}) fail with
* AlreadyInOrganizationException.
*/
@AfterEach
void deleteTheOrganizationThisTestCreated() {
if (createdOrganization) {
organizationsService.deleteOrganization("000000000000");
}
}
@Test
void organizationGraphAndMemberLifecycleMatchesAwsContract() {
organizationsService.createOrganization("000000000000", "ALL");
createdOrganization = true;
String enableBody = post("/orgs/enableAdminAccount", "{\"AccountId\":\"000000000000\"}")
.statusCode(200).extract().asString();
assertTrue(enableBody.isEmpty());