-
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.
chore: split organisation endpoint in create and update
- Loading branch information
1 parent
342a750
commit 5254f82
Showing
8 changed files
with
237 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,8 @@ | |
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.domain.request.OrganisationCreate; | ||
import org.cardanofoundation.lob.app.organisation.domain.request.OrganisationUpdate; | ||
import org.cardanofoundation.lob.app.organisation.repository.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
|
@@ -59,21 +59,23 @@ class OrganisationServiceTest { | |
@BeforeEach | ||
void setUp() { | ||
organisation = new Organisation(); | ||
organisation.setId("org-123"); | ||
organisation.setId("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0"); | ||
organisation.setCountryCode("IE"); | ||
organisation.setTaxIdNumber("1"); | ||
} | ||
|
||
@Test | ||
void testFindById_WhenOrganisationExists() { | ||
when(organisationRepository.findById("org-123")).thenReturn(Optional.of(organisation)); | ||
Optional<Organisation> result = organisationService.findById("org-123"); | ||
when(organisationRepository.findById("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0")).thenReturn(Optional.of(organisation)); | ||
Optional<Organisation> result = organisationService.findById("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0"); | ||
assertTrue(result.isPresent()); | ||
assertEquals("org-123", result.get().getId()); | ||
assertEquals("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0", result.get().getId()); | ||
} | ||
|
||
@Test | ||
void testFindById_WhenOrganisationDoesNotExist() { | ||
when(organisationRepository.findById("org-123")).thenReturn(Optional.empty()); | ||
Optional<Organisation> result = organisationService.findById("org-123"); | ||
when(organisationRepository.findById("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0")).thenReturn(Optional.empty()); | ||
Optional<Organisation> result = organisationService.findById("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0"); | ||
assertFalse(result.isPresent()); | ||
} | ||
|
||
|
@@ -88,44 +90,65 @@ void testFindAll() { | |
@Test | ||
void testGetAllCostCenter() { | ||
Set<OrganisationCostCenter> costCenters = new HashSet<>(); | ||
when(costCenterService.getAllCostCenter("org-123")).thenReturn(costCenters); | ||
Set<OrganisationCostCenter> result = organisationService.getAllCostCenter("org-123"); | ||
when(costCenterService.getAllCostCenter("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0")).thenReturn(costCenters); | ||
Set<OrganisationCostCenter> result = organisationService.getAllCostCenter("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0"); | ||
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"); | ||
when(projectMappingRepository.findAllByOrganisationId("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0")).thenReturn(projects); | ||
Set<OrganisationProject> result = organisationService.getAllProjects("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0"); | ||
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()); | ||
|
||
OrganisationUpdate organisationUpdate = new OrganisationUpdate(); | ||
organisationUpdate.setAddress("Street"); | ||
organisationUpdate.setName("Company name"); | ||
organisationUpdate.setAdminEmail("[email protected]"); | ||
organisationUpdate.setCity("City name"); | ||
organisationUpdate.setCurrencyId("ISO_4217:CHF"); | ||
organisationUpdate.setPostCode("A127"); | ||
organisationUpdate.setProvince("County co."); | ||
organisationUpdate.setReportCurrencyId("ISO_4217:CHF"); | ||
organisationUpdate.setPhoneNumber("0101010101"); | ||
|
||
when(organisationRepository.saveAndFlush(any())).thenReturn(organisation); | ||
|
||
Organisation result = organisationService.upsertOrganisation(organisation, organisationUpdate).get(); | ||
assertNotNull(result); | ||
assertEquals("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0",result.getId()); | ||
assertEquals("Street",result.getAddress()); | ||
assertEquals("City name",result.getCity()); | ||
assertEquals("County co.",result.getProvince()); | ||
} | ||
|
||
@Test | ||
void testCreateOrganisation_NewOrganisation() { | ||
OrganisationCreate organisationCreate = new OrganisationCreate(); | ||
organisationCreate.setAddress("Street"); | ||
organisationCreate.setCountryCode("IE"); | ||
organisationCreate.setTaxIdNumber("1"); | ||
organisationCreate.setName("Company name"); | ||
organisationCreate.setAdminEmail("[email protected]"); | ||
organisationCreate.setCity("City name"); | ||
organisationCreate.setCurrencyId("ISO_4217:CHF"); | ||
organisationCreate.setPostCode("A127"); | ||
organisationCreate.setProvince("County co."); | ||
organisationCreate.setReportCurrencyId("ISO_4217:CHF"); | ||
organisationCreate.setPhoneNumber("0101010101"); | ||
|
||
when(organisationRepository.saveAndFlush(any())).thenReturn(organisation); | ||
|
||
OrganisationView result = organisationService.upsertOrganisation(organisationUpsert); | ||
Organisation result = organisationService.createOrganisation(organisationCreate).get(); | ||
assertNotNull(result); | ||
assertEquals("6d50ed2208aba5047f54a0b4e603d77463db27f108de9a268bb1670fa9afef11",result.getId()); | ||
assertEquals("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0",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
46 changes: 46 additions & 0 deletions
46
...in/java/org/cardanofoundation/lob/app/organisation/domain/request/OrganisationUpdate.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,46 @@ | ||
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 OrganisationUpdate { | ||
|
||
@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 = "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; | ||
|
||
} |
Oops, something went wrong.