20
20
import org .cardanofoundation .lob .app .organisation .domain .entity .Organisation ;
21
21
import org .cardanofoundation .lob .app .organisation .domain .entity .OrganisationCostCenter ;
22
22
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 ;
25
25
import org .cardanofoundation .lob .app .organisation .repository .*;
26
26
27
27
@ ExtendWith (MockitoExtension .class )
@@ -59,21 +59,23 @@ class OrganisationServiceTest {
59
59
@ BeforeEach
60
60
void setUp () {
61
61
organisation = new Organisation ();
62
- organisation .setId ("org-123" );
62
+ organisation .setId ("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0" );
63
+ organisation .setCountryCode ("IE" );
64
+ organisation .setTaxIdNumber ("1" );
63
65
}
64
66
65
67
@ Test
66
68
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 " );
69
71
assertTrue (result .isPresent ());
70
- assertEquals ("org-123 " , result .get ().getId ());
72
+ assertEquals ("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0 " , result .get ().getId ());
71
73
}
72
74
73
75
@ Test
74
76
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 " );
77
79
assertFalse (result .isPresent ());
78
80
}
79
81
@@ -88,44 +90,65 @@ void testFindAll() {
88
90
@ Test
89
91
void testGetAllCostCenter () {
90
92
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 " );
93
95
assertEquals (costCenters , result );
94
96
}
95
97
96
98
@ Test
97
99
void testGetAllProjects () {
98
100
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 " );
101
103
assertEquals (projects , result );
102
104
}
103
105
104
106
@ Test
105
107
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
+
121
145
when (organisationRepository .saveAndFlush (any ())).thenReturn (organisation );
122
146
123
- OrganisationView result = organisationService .upsertOrganisation ( organisationUpsert );
147
+ Organisation result = organisationService .createOrganisation ( organisationCreate ). get ( );
124
148
assertNotNull (result );
125
- assertEquals ("6d50ed2208aba5047f54a0b4e603d77463db27f108de9a268bb1670fa9afef11 " ,result .getId ());
149
+ assertEquals ("f3b7485e96cc45b98e825a48a80d856be260b53de5fe45f23287da5b4970b9b0 " ,result .getId ());
126
150
assertEquals ("Street" ,result .getAddress ());
127
151
assertEquals ("City name" ,result .getCity ());
128
- assertEquals ("Country name" ,result .getCountry ());
129
152
assertEquals ("County co." ,result .getProvince ());
130
153
}
131
154
}
0 commit comments