diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/HsOfficeUseCasesTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/HsOfficeUseCasesTest.java index 57ceef0a..97b76dc3 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/HsOfficeUseCasesTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/HsOfficeUseCasesTest.java @@ -1,6 +1,7 @@ package net.hostsharing.hsadminng.hs.office.usecases; import net.hostsharing.hsadminng.HsadminNgApplication; +import net.hostsharing.hsadminng.hs.office.usecases.debitor.CreateExternalDebitorForPartner; import net.hostsharing.hsadminng.hs.office.usecases.debitor.CreateSelfDebitorForPartner; import net.hostsharing.hsadminng.hs.office.usecases.membership.CreateMembership; import net.hostsharing.hsadminng.hs.office.usecases.partner.CreatePartner; @@ -61,12 +62,30 @@ class HsOfficeUseCasesTest extends UseCaseTest { .keep(); } + @Test + @Order(2011) + void shouldCreateExternalDebitorForPartner() { + new CreateExternalDebitorForPartner(this, "Debitor: Billing GmbH") + .given("partnerPersonUuid", "%{Person: Test AG}") + .given("billingContactCaption", "Billing GmbH - billing department") + .given("billingContactEmailAddress", "billing@test-ag.example.org") + .given("debitorNumberSuffix", "01") + .given("billable", true) + .given("vatId", "VAT123456") + .given("vatCountryCode", "DE") + .given("vatBusiness", true) + .given("vatReverseCharge", false) + .given("defaultPrefix", "tsx") + .doRun() + .keep(); + } + @Test @Order(2020) void shouldDeleteDebitor() { new DeleteDebitor(this) .given("partnerNumber", 31020) - .given("debitorSuffix", "01") + .given("debitorSuffix", "02") .doRun(); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCaseTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCaseTest.java index 1570039b..7f4541ac 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCaseTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/UseCaseTest.java @@ -9,6 +9,7 @@ import net.hostsharing.hsadminng.rbac.context.ContextBasedTest; import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.TestInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.web.server.LocalServerPort; @@ -67,7 +68,8 @@ public abstract class UseCaseTest extends ContextBasedTest { ); final var testMethodName = testInfo.getTestMethod().map(Method::getName).orElseThrow(); - markdownFile = new PrintWriter(new FileWriter(testMethodName + ".md")); + final var testMethodOrder = testInfo.getTestMethod().map(m -> m.getAnnotation(Order.class).value()).orElseThrow(); + markdownFile = new PrintWriter(new FileWriter( testMethodOrder + "-" + testMethodName + ".md")); log("## Testcase " + testMethodName.replaceAll("([a-z])([A-Z]+)", "$1 $2")); currentTestInfo = testInfo; // FIXME: remove? } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/debitor/CreateExternalDebitorForPartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/debitor/CreateExternalDebitorForPartner.java new file mode 100644 index 00000000..a611cdf8 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/debitor/CreateExternalDebitorForPartner.java @@ -0,0 +1,57 @@ +package net.hostsharing.hsadminng.hs.office.usecases.debitor; + +import net.hostsharing.hsadminng.hs.office.usecases.UseCase; +import net.hostsharing.hsadminng.hs.office.usecases.UseCaseTest; +import net.hostsharing.hsadminng.hs.office.usecases.person.CreatePerson; + +import static io.restassured.http.ContentType.JSON; +import static org.springframework.http.HttpStatus.CREATED; + +public class CreateExternalDebitorForPartner extends UseCase { + + public CreateExternalDebitorForPartner(final UseCaseTest testSuite, final String resultAlias) { + super(testSuite, resultAlias); + + requires("Person: Test AG"); + requires("Person: Billing GmbH", alias -> new CreatePerson(testSuite, alias) + .given("personType", "LEGAL_PERSON") + .given("tradeName", "Billing GmbH") + ); + } + + @Override + protected HttpResponse run() { + + keep("Contact: Billing GmbH - Test AG billing", () -> + httpPost("/api/hs/office/contacts", usingJsonBody(""" + { + "caption": "Billing GmbH, billing for Test AG", + "emailAddresses": { + "main": "test-ag@billing-GmbH.example.com" + } + } + """)) + .expecting(CREATED).expecting(JSON) + ); + + return httpPost("/api/hs/office/debitors", usingJsonBody(""" + { + "debitorRel": { + "type": "DEBITOR", // FIXME: should be defaulted to DEBITOR + "anchorUuid": ${partnerPersonUuid}, + "holderUuid": ${Person: Billing GmbH}, + "contactUuid": ${Contact: Billing GmbH - Test AG billing} + }, + "debitorNumberSuffix": ${debitorNumberSuffix}, + "billable": ${billable}, + "vatId": ${vatId}, + "vatCountryCode": ${vatCountryCode}, + "vatBusiness": ${vatBusiness}, + "vatReverseCharge": ${vatReverseCharge}, + "refundBankAccountUuid": ${BankAccount: Test AG - refund bank account}, + "defaultPrefix": ${defaultPrefix} + } + """)) + .expecting(CREATED).expecting(JSON); + } +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/debitor/DeleteDebitor.java b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/debitor/DeleteDebitor.java index c006ef77..527b23b6 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/debitor/DeleteDebitor.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/debitor/DeleteDebitor.java @@ -19,7 +19,7 @@ public class DeleteDebitor extends UseCase { .given("vatCountryCode", "DE") .given("vatBusiness", true) .given("vatReverseCharge", false) - .given("defaultPrefix", "tsx")); + .given("defaultPrefix", "tsy")); } @Override diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/person/CreatePerson.java b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/person/CreatePerson.java new file mode 100644 index 00000000..661f73b8 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/usecases/person/CreatePerson.java @@ -0,0 +1,25 @@ +package net.hostsharing.hsadminng.hs.office.usecases.person; + +import io.restassured.http.ContentType; +import net.hostsharing.hsadminng.hs.office.usecases.UseCase; +import net.hostsharing.hsadminng.hs.office.usecases.UseCaseTest; +import org.springframework.http.HttpStatus; + +public class CreatePerson extends UseCase { + + public CreatePerson(final UseCaseTest testSuite, final String resultAlias) { + super(testSuite, resultAlias); + } + + @Override + protected HttpResponse run() { + + return httpPost("/api/hs/office/persons", usingJsonBody(""" + { + "personType": ${personType}, + "tradeName": ${tradeName} + } + """)) + .expecting(HttpStatus.CREATED).expecting(ContentType.JSON); + } +}