Skip to content

Commit

Permalink
✨ (#177): Add PersistOrganizationDelegate and its tests
Browse files Browse the repository at this point in the history
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
d135-1r43 committed Dec 8, 2024
1 parent 9f78399 commit bfbf79a
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ with children_query as (
""")
})
public class Bommel extends PanacheEntity {
public static final String DEFAULT_ROOT_BOMMEL_EMOJI="\uD83C\uDF33"; // tree

private String name;
private String emoji;
Expand Down
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"))));
}
}

0 comments on commit bfbf79a

Please sign in to comment.