Skip to content

Commit

Permalink
VIC-660: CRUD Agencies
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanalicic committed May 17, 2022
1 parent 838f828 commit b44da57
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
23 changes: 23 additions & 0 deletions services/useradminservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ paths:
required: true
schema:
type: integer
- name: sort
in: query
description: The sort parameter containing field and order the response should be sorted
schema:
$ref: '#/components/schemas/Sort'
responses:
200:
description: OK - successfull operation
Expand Down Expand Up @@ -668,6 +673,24 @@ components:
absent:
type: boolean

Sort:
type: object
properties:
field:
type: string
example: 'firstName|lastName|username|email'
enum:
- 'firstName'
- 'lastName'
- 'username'
- 'email'
order:
type: string
example: 'ASC|DESC'
enum:
- 'ASC'
- 'DESC'

ConsultantAgencyAdminResultDTO:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.AgencyTypeDTO.AgencyTypeEnum;
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.ConsultantAdminResponseDTO;
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.ConsultantFilter;
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.Sort.FieldEnum;
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.Sort.OrderEnum;
import java.util.List;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.Sort;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -56,8 +59,13 @@ public List<ConsultantAdminResponseDTO> getConsultantsOfAgency(Long agencyId, in
int perPage) {
addDefaultHeaders(this.adminUserControllerApi.getApiClient());
ConsultantFilter consultantFilter = new ConsultantFilter().agencyId(agencyId);

Sort sortBy = new Sort();
sortBy.setField(FieldEnum.LASTNAME);
sortBy.setOrder(OrderEnum.ASC);

return this.adminUserControllerApi
.getConsultants(currentPage, perPage, consultantFilter)
.getConsultants(currentPage, perPage, consultantFilter, sortBy)
.getEmbedded();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.caritas.cob.agencyservice.api.admin.service;

import static de.caritas.cob.agencyservice.useradminservice.generated.web.model.AgencyTypeDTO.AgencyTypeEnum.TEAM_AGENCY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
Expand All @@ -15,6 +16,9 @@
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.AgencyTypeDTO;
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.ConsultantFilter;
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.ConsultantSearchResultDTO;
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.Sort;
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.Sort.FieldEnum;
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.Sort.OrderEnum;
import java.util.List;
import org.jeasy.random.EasyRandom;
import org.junit.Before;
Expand All @@ -25,7 +29,6 @@
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.http.HttpHeaders;
import org.springframework.test.util.ReflectionTestUtils;
import static org.junit.jupiter.api.Assertions.assertEquals;

@RunWith(MockitoJUnitRunner.class)
public class UserAdminServiceTest {
Expand Down Expand Up @@ -70,13 +73,13 @@ public void getConsultantsOfAgency_Should_callServicesCorrectly() {
Long agencyId = 1L;
int currentPage = 1;
int perPage = 1;
when(this.adminUserControllerApi.getConsultants(any(), any(), any()))
when(this.adminUserControllerApi.getConsultants(any(), any(), any(), any()))
.thenReturn(new EasyRandom().nextObject(ConsultantSearchResultDTO.class));
this.userAdminService.getConsultantsOfAgency(agencyId, currentPage, perPage);

verify(this.adminUserControllerApi, times(1))
.getConsultants(eq(currentPage), eq(perPage),
eq(new ConsultantFilter().agencyId(agencyId)));
eq(new ConsultantFilter().agencyId(agencyId)), any());
verify(this.apiClient, times(this.httpHeaders.size())).addDefaultHeader(any(), any());
}

Expand All @@ -86,12 +89,21 @@ public void addTenantHeader_WhenMultitenacy_Enabled() {
ApiClient apiClient = new ApiClient();
TenantHeaderSupplier tenantHeaderSupplier = new TenantHeaderSupplier();
ReflectionTestUtils.setField(tenantHeaderSupplier, "multitenancy", true);
ReflectionTestUtils.setField(this.userAdminService, "tenantHeaderSupplier", tenantHeaderSupplier);
ReflectionTestUtils
.setField(this.userAdminService, "tenantHeaderSupplier", tenantHeaderSupplier);
this.userAdminService.addDefaultHeaders(apiClient);
HttpHeaders httpHeaders = (HttpHeaders) ReflectionTestUtils.getField(apiClient, "defaultHeaders");
HttpHeaders httpHeaders = (HttpHeaders) ReflectionTestUtils
.getField(apiClient, "defaultHeaders");
List<String> tenantId = httpHeaders.get("tenantId");
assertEquals(tenantId.get(0), TenantContext.getCurrentTenant().toString());
TenantContext.clear();
}


private Sort getSort() {
Sort sortBy = new Sort();
sortBy.setField(FieldEnum.LASTNAME);
sortBy.setOrder(OrderEnum.ASC);
return sortBy;
}
}

0 comments on commit b44da57

Please sign in to comment.