Skip to content

Commit 5254f82

Browse files
committed
chore: split organisation endpoint in create and update
1 parent 342a750 commit 5254f82

File tree

8 files changed

+237
-79
lines changed

8 files changed

+237
-79
lines changed

accounting_reporting_core/src/test/java/org/cardanofoundation/lob/app/organisation/service/OrganisationServiceTest.java

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import org.cardanofoundation.lob.app.organisation.domain.entity.Organisation;
2121
import org.cardanofoundation.lob.app.organisation.domain.entity.OrganisationCostCenter;
2222
import org.cardanofoundation.lob.app.organisation.domain.entity.OrganisationProject;
23-
import org.cardanofoundation.lob.app.organisation.domain.request.OrganisationUpsert;
24-
import org.cardanofoundation.lob.app.organisation.domain.view.OrganisationView;
23+
import org.cardanofoundation.lob.app.organisation.domain.request.OrganisationCreate;
24+
import org.cardanofoundation.lob.app.organisation.domain.request.OrganisationUpdate;
2525
import org.cardanofoundation.lob.app.organisation.repository.*;
2626

2727
@ExtendWith(MockitoExtension.class)
@@ -59,21 +59,23 @@ class OrganisationServiceTest {
5959
@BeforeEach
6060
void setUp() {
6161
organisation = new Organisation();
62-
organisation.setId("org-123");
62+
organisation.setId("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0");
63+
organisation.setCountryCode("IE");
64+
organisation.setTaxIdNumber("1");
6365
}
6466

6567
@Test
6668
void testFindById_WhenOrganisationExists() {
67-
when(organisationRepository.findById("org-123")).thenReturn(Optional.of(organisation));
68-
Optional<Organisation> result = organisationService.findById("org-123");
69+
when(organisationRepository.findById("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0")).thenReturn(Optional.of(organisation));
70+
Optional<Organisation> result = organisationService.findById("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0");
6971
assertTrue(result.isPresent());
70-
assertEquals("org-123", result.get().getId());
72+
assertEquals("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0", result.get().getId());
7173
}
7274

7375
@Test
7476
void testFindById_WhenOrganisationDoesNotExist() {
75-
when(organisationRepository.findById("org-123")).thenReturn(Optional.empty());
76-
Optional<Organisation> result = organisationService.findById("org-123");
77+
when(organisationRepository.findById("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0")).thenReturn(Optional.empty());
78+
Optional<Organisation> result = organisationService.findById("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0");
7779
assertFalse(result.isPresent());
7880
}
7981

@@ -88,44 +90,65 @@ void testFindAll() {
8890
@Test
8991
void testGetAllCostCenter() {
9092
Set<OrganisationCostCenter> costCenters = new HashSet<>();
91-
when(costCenterService.getAllCostCenter("org-123")).thenReturn(costCenters);
92-
Set<OrganisationCostCenter> result = organisationService.getAllCostCenter("org-123");
93+
when(costCenterService.getAllCostCenter("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0")).thenReturn(costCenters);
94+
Set<OrganisationCostCenter> result = organisationService.getAllCostCenter("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0");
9395
assertEquals(costCenters, result);
9496
}
9597

9698
@Test
9799
void testGetAllProjects() {
98100
Set<OrganisationProject> projects = new HashSet<>();
99-
when(projectMappingRepository.findAllByOrganisationId("org-123")).thenReturn(projects);
100-
Set<OrganisationProject> result = organisationService.getAllProjects("org-123");
101+
when(projectMappingRepository.findAllByOrganisationId("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0")).thenReturn(projects);
102+
Set<OrganisationProject> result = organisationService.getAllProjects("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0");
101103
assertEquals(projects, result);
102104
}
103105

104106
@Test
105107
void testUpsertOrganisation_NewOrganisation() {
106-
OrganisationUpsert organisationUpsert = new OrganisationUpsert();
107-
organisationUpsert.setCountryCode("US");
108-
organisationUpsert.setTaxIdNumber("12345");
109-
organisationUpsert.setAddress("Street");
110-
organisationUpsert.setName("Company name");
111-
organisationUpsert.setAdminEmail("[email protected]");
112-
organisationUpsert.setCity("City name");
113-
organisationUpsert.setCountry("Country name");
114-
organisationUpsert.setCurrencyId("ISO_4217:CHF");
115-
organisationUpsert.setPostCode("A127");
116-
organisationUpsert.setProvince("County co.");
117-
organisationUpsert.setReportCurrencyId("ISO_4217:CHF");
118-
organisationUpsert.setPhoneNumber("0101010101");
119-
120-
when(organisationRepository.findById(any())).thenReturn(Optional.empty());
108+
109+
OrganisationUpdate organisationUpdate = new OrganisationUpdate();
110+
organisationUpdate.setAddress("Street");
111+
organisationUpdate.setName("Company name");
112+
organisationUpdate.setAdminEmail("[email protected]");
113+
organisationUpdate.setCity("City name");
114+
organisationUpdate.setCurrencyId("ISO_4217:CHF");
115+
organisationUpdate.setPostCode("A127");
116+
organisationUpdate.setProvince("County co.");
117+
organisationUpdate.setReportCurrencyId("ISO_4217:CHF");
118+
organisationUpdate.setPhoneNumber("0101010101");
119+
120+
when(organisationRepository.saveAndFlush(any())).thenReturn(organisation);
121+
122+
Organisation result = organisationService.upsertOrganisation(organisation, organisationUpdate).get();
123+
assertNotNull(result);
124+
assertEquals("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0",result.getId());
125+
assertEquals("Street",result.getAddress());
126+
assertEquals("City name",result.getCity());
127+
assertEquals("County co.",result.getProvince());
128+
}
129+
130+
@Test
131+
void testCreateOrganisation_NewOrganisation() {
132+
OrganisationCreate organisationCreate = new OrganisationCreate();
133+
organisationCreate.setAddress("Street");
134+
organisationCreate.setCountryCode("IE");
135+
organisationCreate.setTaxIdNumber("1");
136+
organisationCreate.setName("Company name");
137+
organisationCreate.setAdminEmail("[email protected]");
138+
organisationCreate.setCity("City name");
139+
organisationCreate.setCurrencyId("ISO_4217:CHF");
140+
organisationCreate.setPostCode("A127");
141+
organisationCreate.setProvince("County co.");
142+
organisationCreate.setReportCurrencyId("ISO_4217:CHF");
143+
organisationCreate.setPhoneNumber("0101010101");
144+
121145
when(organisationRepository.saveAndFlush(any())).thenReturn(organisation);
122146

123-
OrganisationView result = organisationService.upsertOrganisation(organisationUpsert);
147+
Organisation result = organisationService.createOrganisation(organisationCreate).get();
124148
assertNotNull(result);
125-
assertEquals("6d50ed2208aba5047f54a0b4e603d77463db27f108de9a268bb1670fa9afef11",result.getId());
149+
assertEquals("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0",result.getId());
126150
assertEquals("Street",result.getAddress());
127151
assertEquals("City name",result.getCity());
128-
assertEquals("Country name",result.getCountry());
129152
assertEquals("County co.",result.getProvince());
130153
}
131154
}

organisation/src/main/java/org/cardanofoundation/lob/app/organisation/domain/entity/Organisation.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ public class Organisation extends CommonEntity implements Persistable<String> {
4646
@Column(name = "province", nullable = false)
4747
private String province;
4848

49-
@Column(name = "country", nullable = false)
50-
private String country;
51-
5249
@Column(name = "address", nullable = false)
5350
private String address;
5451

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@Setter
1212
@AllArgsConstructor
1313
@NoArgsConstructor
14-
public class OrganisationUpsert {
14+
public class OrganisationCreate {
1515

1616
@Schema(example = "My company name")
1717
private String name;
@@ -25,9 +25,6 @@ public class OrganisationUpsert {
2525
@Schema(example = "Co. Wexford")
2626
private String province;
2727

28-
@Schema(example = "Ireland")
29-
private String country;
30-
3128
@Schema(example = "IE")
3229
private String countryCode;
3330

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.cardanofoundation.lob.app.organisation.domain.request;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
import lombok.Setter;
7+
8+
import io.swagger.v3.oas.annotations.media.Schema;
9+
10+
@Getter
11+
@Setter
12+
@AllArgsConstructor
13+
@NoArgsConstructor
14+
public class OrganisationUpdate {
15+
16+
@Schema(example = "My company name")
17+
private String name;
18+
19+
@Schema(example = "Ballyhealy")
20+
private String city;
21+
22+
@Schema(example = "Y35 C6KC")
23+
private String postCode;
24+
25+
@Schema(example = "Co. Wexford")
26+
private String province;
27+
28+
@Schema(example = "Ballyhealy Cottage")
29+
private String address;
30+
31+
@Schema(example = "0035863286566")
32+
private String phoneNumber;
33+
34+
@Schema(example = "[email protected]")
35+
private String adminEmail;
36+
37+
@Schema(example = "http://cardanofoundation.org")
38+
private String websiteUrl;
39+
40+
@Schema(example = "ISO_4217:CHF")
41+
private String currencyId;
42+
43+
@Schema(example = "ISO_4217:CHF")
44+
private String reportCurrencyId;
45+
46+
}

0 commit comments

Comments
 (0)