-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Manuel Klaus
committed
Dec 7, 2024
1 parent
9f78399
commit 0915e89
Showing
9 changed files
with
120 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
backend/app.hopps.org/src/main/java/app/hopps/org/rest/model/NewOrganizationInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package app.hopps.org.rest.model; | ||
|
||
import app.hopps.org.jpa.Member; | ||
import app.hopps.org.jpa.Organization; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public record NewOrganizationInput(@NotNull OwnerInput owner, @NotNull OrganizationInput organization) { | ||
public Map<String, Object> toModel() { | ||
Map<String, Object> parameters = new HashMap<>(); | ||
|
||
Organization jpaOrg = new Organization(); | ||
jpaOrg.setSlug(organization().slug()); | ||
jpaOrg.setName(organization().name()); | ||
jpaOrg.setType(organization().type()); | ||
jpaOrg.setWebsite(organization().website()); | ||
jpaOrg.setAddress(organization().address()); | ||
jpaOrg.setProfilePicture(organization().profilePicture()); | ||
parameters.put("organization", jpaOrg); | ||
|
||
Member member = new Member(); | ||
member.setEmail(owner().email()); | ||
member.setFirstName(owner().firstName()); | ||
member.setLastName(owner().lastName()); | ||
parameters.put("owner", member); | ||
|
||
return parameters; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
backend/app.hopps.org/src/main/java/app/hopps/org/rest/model/OrganizationInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package app.hopps.org.rest.model; | ||
|
||
import app.hopps.org.jpa.Address; | ||
import app.hopps.org.jpa.Organization.TYPE; | ||
|
||
import java.net.URL; | ||
|
||
public record OrganizationInput(String name, | ||
String slug, | ||
TYPE type, | ||
URL website, | ||
URL profilePicture, | ||
Address address) { | ||
} |
4 changes: 4 additions & 0 deletions
4
backend/app.hopps.org/src/main/java/app/hopps/org/rest/model/OwnerInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package app.hopps.org.rest.model; | ||
|
||
public record OwnerInput(String email, String firstName, String lastName) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
package app.hopps.org.rest; | ||
|
||
import app.hopps.org.jpa.Organization; | ||
import app.hopps.org.rest.model.NewOrganizationInput; | ||
import app.hopps.org.rest.model.OrganizationInput; | ||
import app.hopps.org.rest.model.OwnerInput; | ||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.RestAssured; | ||
import jakarta.ws.rs.core.MediaType; | ||
import org.instancio.Instancio; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(OrganizationResource.class) | ||
class OrganizationResourceTests { | ||
|
||
@Test | ||
@DisplayName("should validate valid verein") | ||
void shouldValidateValidVerein() { | ||
|
@@ -24,8 +29,8 @@ void shouldValidateValidVerein() { | |
organization.setSlug("foobar"); | ||
organization.setId(null); | ||
|
||
RestAssured.given() | ||
.contentType("application/json") | ||
given() | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(organization) | ||
.when() | ||
.post("/validate") | ||
|
@@ -43,8 +48,8 @@ void shouldInvalidateVereinWithoutName() { | |
organization.setId(null); | ||
organization.setName(""); | ||
|
||
RestAssured.given() | ||
.contentType("application/json") | ||
given() | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(organization) | ||
.when() | ||
.post("/validate") | ||
|
@@ -54,4 +59,22 @@ void shouldInvalidateVereinWithoutName() { | |
.body("violations[0].propertyPath", equalTo("name")) | ||
.body("violations[0].message", equalTo("must not be blank")); | ||
} | ||
|
||
@Test | ||
void shouldStartCreatingOrganization() throws MalformedURLException { | ||
OrganizationInput organizationInput = new OrganizationInput("Schützenverein", "schuetzenverein", | ||
Organization.TYPE.EINGETRAGENER_VEREIN, URI.create("https://hopps.cloud").toURL(), | ||
URI.create("https://hopps.cloud").toURL(), null); | ||
OwnerInput ownerInput = new OwnerInput("[email protected]", "Test", "User"); | ||
NewOrganizationInput newOrganizationInput = new NewOrganizationInput(ownerInput, organizationInput); | ||
|
||
given() | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(newOrganizationInput) | ||
.when() | ||
.post() | ||
.then() | ||
.statusCode(202) | ||
.body(any(String.class)); | ||
} | ||
} |