-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from cardano-foundation/feat/organisation_crud
feat: organisation create and edit endpoint
- Loading branch information
Showing
9 changed files
with
375 additions
and
51 deletions.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
...test/java/org/cardanofoundation/lob/app/organisation/service/OrganisationServiceTest.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,131 @@ | ||
package org.cardanofoundation.lob.app.organisation.service; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import org.cardanofoundation.lob.app.organisation.domain.entity.Organisation; | ||
import org.cardanofoundation.lob.app.organisation.domain.entity.OrganisationCostCenter; | ||
import org.cardanofoundation.lob.app.organisation.domain.entity.OrganisationProject; | ||
import org.cardanofoundation.lob.app.organisation.domain.request.OrganisationUpsert; | ||
import org.cardanofoundation.lob.app.organisation.domain.view.OrganisationView; | ||
import org.cardanofoundation.lob.app.organisation.repository.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class OrganisationServiceTest { | ||
|
||
@Mock | ||
private OrganisationRepository organisationRepository; | ||
|
||
@Mock | ||
private CostCenterService costCenterService; | ||
|
||
@Mock | ||
private ProjectMappingRepository projectMappingRepository; | ||
|
||
@Mock | ||
private OrganisationChartOfAccountTypeRepository organisationChartOfAccountTypeRepository; | ||
|
||
@Mock | ||
private ChartOfAccountRepository organisationChartOfAccountRepository; | ||
|
||
@Mock | ||
private OrganisationChartOfAccountSubTypeRepository organisationChartOfAccountSubTypeRepository; | ||
|
||
@Mock | ||
private AccountEventRepository accountEventRepository; | ||
|
||
@Mock | ||
private OrganisationCurrencyService organisationCurrencyService; | ||
|
||
@InjectMocks | ||
private OrganisationService organisationService; | ||
|
||
private Organisation organisation; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
organisation = new Organisation(); | ||
organisation.setId("org-123"); | ||
} | ||
|
||
@Test | ||
void testFindById_WhenOrganisationExists() { | ||
when(organisationRepository.findById("org-123")).thenReturn(Optional.of(organisation)); | ||
Optional<Organisation> result = organisationService.findById("org-123"); | ||
assertTrue(result.isPresent()); | ||
assertEquals("org-123", result.get().getId()); | ||
} | ||
|
||
@Test | ||
void testFindById_WhenOrganisationDoesNotExist() { | ||
when(organisationRepository.findById("org-123")).thenReturn(Optional.empty()); | ||
Optional<Organisation> result = organisationService.findById("org-123"); | ||
assertFalse(result.isPresent()); | ||
} | ||
|
||
@Test | ||
void testFindAll() { | ||
List<Organisation> organisations = List.of(organisation); | ||
when(organisationRepository.findAll()).thenReturn(organisations); | ||
List<Organisation> result = organisationService.findAll(); | ||
assertEquals(1, result.size()); | ||
} | ||
|
||
@Test | ||
void testGetAllCostCenter() { | ||
Set<OrganisationCostCenter> costCenters = new HashSet<>(); | ||
when(costCenterService.getAllCostCenter("org-123")).thenReturn(costCenters); | ||
Set<OrganisationCostCenter> result = organisationService.getAllCostCenter("org-123"); | ||
assertEquals(costCenters, result); | ||
} | ||
|
||
@Test | ||
void testGetAllProjects() { | ||
Set<OrganisationProject> projects = new HashSet<>(); | ||
when(projectMappingRepository.findAllByOrganisationId("org-123")).thenReturn(projects); | ||
Set<OrganisationProject> result = organisationService.getAllProjects("org-123"); | ||
assertEquals(projects, result); | ||
} | ||
|
||
@Test | ||
void testUpsertOrganisation_NewOrganisation() { | ||
OrganisationUpsert organisationUpsert = new OrganisationUpsert(); | ||
organisationUpsert.setCountryCode("US"); | ||
organisationUpsert.setTaxIdNumber("12345"); | ||
organisationUpsert.setAddress("Street"); | ||
organisationUpsert.setName("Company name"); | ||
organisationUpsert.setAdminEmail("[email protected]"); | ||
organisationUpsert.setCity("City name"); | ||
organisationUpsert.setCountry("Country name"); | ||
organisationUpsert.setCurrencyId("ISO_4217:CHF"); | ||
organisationUpsert.setPostCode("A127"); | ||
organisationUpsert.setProvince("County co."); | ||
organisationUpsert.setReportCurrencyId("ISO_4217:CHF"); | ||
organisationUpsert.setPhoneNumber("0101010101"); | ||
|
||
when(organisationRepository.findById(any())).thenReturn(Optional.empty()); | ||
when(organisationRepository.saveAndFlush(any())).thenReturn(organisation); | ||
|
||
OrganisationView result = organisationService.upsertOrganisation(organisationUpsert); | ||
assertNotNull(result); | ||
assertEquals("6d50ed2208aba5047f54a0b4e603d77463db27f108de9a268bb1670fa9afef11",result.getId()); | ||
assertEquals("Street",result.getAddress()); | ||
assertEquals("City name",result.getCity()); | ||
assertEquals("Country name",result.getCountry()); | ||
assertEquals("County co.",result.getProvince()); | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
...in/java/org/cardanofoundation/lob/app/organisation/domain/request/OrganisationUpsert.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,55 @@ | ||
package org.cardanofoundation.lob.app.organisation.domain.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class OrganisationUpsert { | ||
|
||
@Schema(example = "My company name") | ||
private String name; | ||
|
||
@Schema(example = "Ballyhealy") | ||
private String city; | ||
|
||
@Schema(example = "Y35 C6KC") | ||
private String postCode; | ||
|
||
@Schema(example = "Co. Wexford") | ||
private String province; | ||
|
||
@Schema(example = "Ireland") | ||
private String country; | ||
|
||
@Schema(example = "IE") | ||
private String countryCode; | ||
|
||
@Schema(example = "Ballyhealy Cottage") | ||
private String address; | ||
|
||
@Schema(example = "0035863286566") | ||
private String phoneNumber; | ||
|
||
@Schema(example = "[email protected]") | ||
private String adminEmail; | ||
|
||
@Schema(example = "http://cardanofoundation.org") | ||
private String websiteUrl; | ||
|
||
@Schema(example = "ISO_4217:CHF") | ||
private String currencyId; | ||
|
||
@Schema(example = "ISO_4217:CHF") | ||
private String reportCurrencyId; | ||
|
||
@Schema(example = "CHE-184477354") | ||
private String taxIdNumber; | ||
|
||
} |
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 |
---|---|---|
|
@@ -42,6 +42,24 @@ public class OrganisationView { | |
@Schema(example = "[email protected]") | ||
private String adminEmail; | ||
|
||
@Schema(example = "0035863286566") | ||
private String phoneNumber; | ||
|
||
@Schema(example = "Street name and number") | ||
private String address; | ||
|
||
@Schema(example = "Ballyhealy") | ||
private String city; | ||
|
||
@Schema(example = "Y35 C6KC") | ||
private String postCode; | ||
|
||
@Schema(example = "Co. Wexford") | ||
private String province; | ||
|
||
@Schema(example = "Ireland") | ||
private String country; | ||
|
||
private Set<OrganisationCostCenterView> costCenter; | ||
|
||
private Set<OrganisationCostCenterView> projects; | ||
|
Oops, something went wrong.