|
4 | 4 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
5 | 5 | import static org.junit.jupiter.api.Assertions.assertThrows; |
6 | 6 | import static org.mockito.ArgumentMatchers.any; |
| 7 | +import static org.mockito.ArgumentMatchers.anyBoolean; |
7 | 8 | import static org.mockito.ArgumentMatchers.anyInt; |
8 | 9 | import static org.mockito.ArgumentMatchers.anyString; |
9 | 10 | import static org.mockito.ArgumentMatchers.eq; |
|
23 | 24 | import java.util.Collections; |
24 | 25 | import java.util.List; |
25 | 26 | import java.util.Optional; |
| 27 | +import java.util.stream.Stream; |
26 | 28 | import org.junit.jupiter.api.BeforeEach; |
27 | 29 | import org.junit.jupiter.api.DisplayName; |
| 30 | +import org.junit.jupiter.api.Named; |
28 | 31 | import org.junit.jupiter.api.Test; |
29 | 32 | import org.junit.jupiter.api.extension.ExtendWith; |
30 | 33 | import org.junit.jupiter.api.function.Executable; |
| 34 | +import org.junit.jupiter.params.ParameterizedTest; |
| 35 | +import org.junit.jupiter.params.provider.Arguments; |
| 36 | +import org.junit.jupiter.params.provider.MethodSource; |
31 | 37 | import org.mockito.ArgumentCaptor; |
32 | 38 | import org.mockito.Captor; |
33 | 39 | import org.mockito.InjectMocks; |
|
36 | 42 | import uk.gov.companieshouse.api.exemptions.CompanyExemptions; |
37 | 43 | import uk.gov.companieshouse.api.exemptions.Exemptions; |
38 | 44 | import uk.gov.companieshouse.api.exemptions.PscExemptAsTradingOnUkRegulatedMarketItem; |
| 45 | +import uk.gov.companieshouse.api.metrics.CountsApi; |
39 | 46 | import uk.gov.companieshouse.api.metrics.MetricsApi; |
| 47 | +import uk.gov.companieshouse.api.metrics.PscApi; |
40 | 48 | import uk.gov.companieshouse.api.metrics.RegisterApi; |
41 | 49 | import uk.gov.companieshouse.api.metrics.RegistersApi; |
42 | 50 | import uk.gov.companieshouse.api.model.psc.PscIndividualFullRecordApi; |
@@ -875,4 +883,75 @@ void getIndividualFullRecordShouldReturnFullRecordWhenFound_FlagVerifyStateTrue( |
875 | 883 | verify(repository).getPscByCompanyNumberAndId(COMPANY_NUMBER, NOTIFICATION_ID); |
876 | 884 | verify(transformer).transformPscDocToIndividualFullRecord(pscDocument); |
877 | 885 | } |
| 886 | + |
| 887 | + @Test |
| 888 | + void shouldSetFieldsWhenRegisterViewIsTrue() { |
| 889 | + // given |
| 890 | + MetricsApi metricsApi = new MetricsApi().counts( |
| 891 | + new CountsApi().personsWithSignificantControl( |
| 892 | + new PscApi().activePscsCount(1))).registers( |
| 893 | + new RegistersApi().personsWithSignificantControl( |
| 894 | + new RegisterApi().registerMovedTo("public-register"))); |
| 895 | + |
| 896 | + Links links = new Links(); |
| 897 | + links.setSelf("/company/%s/persons-with-significant-control".formatted(COMPANY_NUMBER)); |
| 898 | + |
| 899 | + final PscList expected = new PscList() |
| 900 | + .itemsPerPage(25) |
| 901 | + .links(links) |
| 902 | + .startIndex(0) |
| 903 | + .items(List.of(new ListSummary())) |
| 904 | + .ceasedCount(0) |
| 905 | + .totalResults(1) |
| 906 | + .activeCount(1); |
| 907 | + |
| 908 | + when(companyMetricsApiService.getCompanyMetrics(anyString())).thenReturn(Optional.of(metricsApi)); |
| 909 | + when(repository.getListSummaryRegisterView(any(), any(), any(), any())).thenReturn( |
| 910 | + Collections.singletonList(pscDocument)); |
| 911 | + when(transformer.transformPscDocToListSummary(any(), anyBoolean())).thenReturn(new ListSummary()); |
| 912 | + |
| 913 | + // when |
| 914 | + final PscList actual = service.retrievePscListSummaryFromDb(COMPANY_NUMBER, 0, true, 25); |
| 915 | + |
| 916 | + // then |
| 917 | + assertEquals(expected, actual); |
| 918 | + } |
| 919 | + |
| 920 | + @ParameterizedTest |
| 921 | + @MethodSource("nullCompanyMetricsPscDataArgs") |
| 922 | + void shouldTestIfCompanyMetricsPscDataIsNull(MetricsApi metricsApi) { |
| 923 | + // given |
| 924 | + Links links = new Links(); |
| 925 | + links.setSelf("/company/%s/persons-with-significant-control".formatted(COMPANY_NUMBER)); |
| 926 | + |
| 927 | + final PscList expected = new PscList() |
| 928 | + .itemsPerPage(25) |
| 929 | + .links(links) |
| 930 | + .startIndex(0) |
| 931 | + .items(List.of(new ListSummary())); |
| 932 | + |
| 933 | + when(companyMetricsApiService.getCompanyMetrics(anyString())).thenReturn(Optional.of(metricsApi)); |
| 934 | + when(repository.getListSummaryRegisterView(any(), any(), any(), any())).thenReturn( |
| 935 | + Collections.singletonList(pscDocument)); |
| 936 | + when(transformer.transformPscDocToListSummary(any(), anyBoolean())).thenReturn(new ListSummary()); |
| 937 | + |
| 938 | + // when |
| 939 | + final PscList actual = service.retrievePscListSummaryFromDb(COMPANY_NUMBER, 0, true, 25); |
| 940 | + |
| 941 | + // then |
| 942 | + assertEquals(expected, actual); |
| 943 | + } |
| 944 | + |
| 945 | + private static Stream<Arguments> nullCompanyMetricsPscDataArgs() { |
| 946 | + return Stream.of( |
| 947 | + Arguments.of(Named.of("Metrics with counts but no psc data", |
| 948 | + new MetricsApi().counts(new CountsApi()).registers( |
| 949 | + new RegistersApi().personsWithSignificantControl( |
| 950 | + new RegisterApi().registerMovedTo("public-register"))))), |
| 951 | + Arguments.of(Named.of("Metrics without counts", |
| 952 | + new MetricsApi().registers( |
| 953 | + new RegistersApi().personsWithSignificantControl( |
| 954 | + new RegisterApi().registerMovedTo("public-register"))))) |
| 955 | + ); |
| 956 | + } |
878 | 957 | } |
0 commit comments