-
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.
✨ (#177): Add PersistOrganizationDelegate and its tests
Implemented PersistOrganizationDelegate to handle the persistence of organizations, their owners, and root Bommels. Added unit tests to verify that organizations, members, and root Bommels are correctly persisted, ensuring integrity and expected behavior. Introduced a default emoji for root Bommels to standardize their representation.
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
backend/app.hopps.org/src/main/java/app/hopps/org/delegates/PersistOrganizationDelegate.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,35 @@ | ||
package app.hopps.org.delegates; | ||
|
||
import app.hopps.org.jpa.*; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.validation.Valid; | ||
|
||
@ApplicationScoped | ||
public class PersistOrganizationDelegate { | ||
|
||
@Inject | ||
OrganizationRepository organizationRepository; | ||
|
||
@Inject | ||
MemberRespository memberRepository; | ||
|
||
@Inject | ||
BommelRepository bommelRepository; | ||
|
||
@Transactional | ||
public void persistOrg(@Valid Organization organization, @Valid Member owner) { | ||
memberRepository.persist(owner); | ||
organizationRepository.persist(organization); | ||
|
||
Bommel rootBommel = new Bommel(); | ||
rootBommel.setName(organization.getName()); | ||
rootBommel.setParent(null); | ||
rootBommel.setOrganization(organization); | ||
rootBommel.setEmoji(Bommel.DEFAULT_ROOT_BOMMEL_EMOJI); | ||
rootBommel.setResponsibleMember(owner); | ||
|
||
bommelRepository.persist(rootBommel); | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
...app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.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,62 @@ | ||
package app.hopps.org.delegates; | ||
|
||
import app.hopps.org.jpa.*; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.hasProperty; | ||
import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize; | ||
|
||
@QuarkusTest | ||
public class PersistOrganizationDelegateTests { | ||
|
||
@Inject | ||
PersistOrganizationDelegate persistOrganizationDelegate; | ||
|
||
@Inject | ||
BommelRepository bommelRepository; | ||
|
||
@Inject | ||
OrganizationRepository organizationRepository; | ||
|
||
@Inject | ||
MemberRespository memberRepository; | ||
|
||
@BeforeEach | ||
@Transactional | ||
void cleanupDB() | ||
{ | ||
bommelRepository.deleteAll(); | ||
organizationRepository.deleteAll(); | ||
memberRepository.deleteAll(); | ||
} | ||
|
||
@Test | ||
void shouldCreateRootBommel() | ||
{ | ||
// given | ||
Organization kegelclub = new Organization(); | ||
kegelclub.setName("Kegelklub 777"); | ||
kegelclub.setType(Organization.TYPE.EINGETRAGENER_VEREIN); | ||
kegelclub.setSlug("kegelklub-777"); | ||
|
||
Member kevin = new Member(); | ||
kevin.setFirstName("Kevin"); | ||
kevin.setLastName("Kegelkönig"); | ||
kevin.setEmail("[email protected]"); | ||
|
||
// when | ||
persistOrganizationDelegate.persistOrg(kegelclub, kevin); | ||
|
||
// then | ||
assertThat(organizationRepository.listAll(), iterableWithSize(1)); | ||
assertThat(bommelRepository.listAll(), iterableWithSize(1)); | ||
assertThat(bommelRepository.listAll(), hasItem(hasProperty("emoji", equalTo("\uD83C\uDF33")))); | ||
} | ||
} |