test for creation of ex-partner relation

This commit is contained in:
Michael Hoennig 2024-04-08 12:00:59 +02:00
parent 038d60b789
commit d09b1638b3

View File

@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.UUID;
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.EX_PARTNER;
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
import static net.hostsharing.test.JsonMatcher.lenientlyEquals;
import static org.assertj.core.api.Assertions.assertThat;
@ -41,7 +42,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
HsOfficePartnerRepository partnerRepo;
@Autowired
HsOfficeRelationRepository relationRepository;
HsOfficeRelationRepository relationRepo;
@Autowired
HsOfficePersonRepository personRepo;
@ -376,6 +377,45 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
});
}
@Test
void patchingThePartnerRelCreatesExPartnerRel() {
context.define("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler(20011);
final var givenPartnerRel = givenSomeTemporaryPartnerRel("Third OHG", "third contact");
RestAssured // @formatter:off
.given()
.header("current-user", "superuser-alex@hostsharing.net")
.contentType(ContentType.JSON)
.body("""
{
"partnerRelUuid": "%s"
}
""".formatted(givenPartnerRel.getUuid()))
.port(port)
.when()
.patch("http://localhost/api/hs/office/partners/" + givenPartner.getUuid())
.then().log().body()
.assertThat().statusCode(200);
// @formatter:on
// then the partner got actually updated
context.define("superuser-alex@hostsharing.net");
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isPresent().get()
.matches(partner -> {
assertThat(partner.getPartnerRel().getHolder().getTradeName()).isEqualTo("Third OHG");
assertThat(partner.getPartnerRel().getContact().getLabel()).isEqualTo("third contact");
return true;
});
// and an ex-partner-relation got created
final var partnerPersonUUid = givenPartner.getPartnerRel().getAnchor().getUuid();
assertThat(relationRepo.findRelationRelatedToPersonUuidAndRelationType(partnerPersonUUid, EX_PARTNER))
.map(HsOfficeRelationEntity::toShortString)
.contains("xxx");
}
@Test
void globalAdmin_withoutAssumedRole_canPatchPartialPropertiesOfArbitraryPartner() {
@ -442,7 +482,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
// then the given partner is gone
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isEmpty();
assertThat(relationRepository.findByUuid(givenPartner.getPartnerRel().getUuid())).isEmpty();
assertThat(relationRepo.findByUuid(givenPartner.getPartnerRel().getUuid())).isEmpty();
}
@Test