Skip to content

Commit

Permalink
Release 5.1.0 (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
javierpoloe2y authored Jan 31, 2024
1 parent 072f169 commit c5a03ee
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 33 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/groovy/hmc.lib-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ bootJar {

dependencies {
api 'com.hyperwallet:sdk:2.4.3'
api 'com.mirakl:mmp-sdk-operator:6.8.0'
api 'com.mirakl:mmp-sdk-operator:6.37.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.mirakl.client.mmp.request.shop.document.MiraklDeleteShopDocumentRequest;
import com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest;
import com.mirakl.client.mmp.request.shop.document.MiraklGetShopDocumentsRequest;
import com.paypal.infrastructure.mirakl.client.filter.IgnoredShopsFilter;
import com.paypal.infrastructure.mirakl.client.filter.ShopsFilter;
import com.paypal.infrastructure.mirakl.configuration.MiraklApiClientConfig;
import org.springframework.stereotype.Component;

Expand All @@ -32,13 +32,13 @@ public class DirectMiraklClient implements MiraklClient {

private MiraklMarketplacePlatformOperatorApiClient miraklMarketplacePlatformOperatorApiClient;

private final IgnoredShopsFilter ignoredShopsFilter;
private final List<ShopsFilter> shopsFilter;

private final MiraklApiClientConfig config;

public DirectMiraklClient(final MiraklApiClientConfig config, final IgnoredShopsFilter ignoredShopsFilter) {
public DirectMiraklClient(final MiraklApiClientConfig config, final List<ShopsFilter> shopsFilter) {
this.config = config;
this.ignoredShopsFilter = ignoredShopsFilter;
this.shopsFilter = shopsFilter;
reloadHttpConfiguration();
}

Expand All @@ -51,7 +51,9 @@ public MiraklVersion getVersion() {
public MiraklShops getShops(final MiraklGetShopsRequest request) {
final MiraklShops shops = getUnfilteredMiraklShops(request);

return ignoredShopsFilter.filterIgnoredShops(shops);
shopsFilter.forEach(filter -> filter.filterShops(shops));

return shops;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest;
import com.paypal.infrastructure.changestaging.service.ChangeStagingService;
import com.paypal.infrastructure.mirakl.client.converters.MiraklStageChangeConverter;
import com.paypal.infrastructure.mirakl.client.filter.IgnoredShopsFilter;
import com.paypal.infrastructure.mirakl.client.filter.ShopsFilter;
import com.paypal.infrastructure.mirakl.configuration.MiraklApiClientConfig;
import com.paypal.infrastructure.mirakl.settings.MiraklClientSettingsHolder;
import org.springframework.context.annotation.Primary;
Expand All @@ -20,10 +20,10 @@ public class StageChangesMiraklClient extends DirectMiraklClient {

private final MiraklStageChangeConverter miraklStageChangeConverter;

public StageChangesMiraklClient(final MiraklApiClientConfig config, final IgnoredShopsFilter ignoredShopsFilter,
public StageChangesMiraklClient(final MiraklApiClientConfig config, final List<ShopsFilter> shopsFilters,
final ChangeStagingService changeStagingService,
final MiraklStageChangeConverter miraklStageChangeConverter) {
super(config, ignoredShopsFilter);
super(config, shopsFilters);
this.changeStagingService = changeStagingService;
this.miraklStageChangeConverter = miraklStageChangeConverter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@

@Slf4j
@Component
public class IgnoredShopsFilter {
public class IgnoredShopsFilter implements ShopsFilter {

private final HyperwalletProgramsConfiguration hyperwalletProgramsConfiguration;

public IgnoredShopsFilter(final HyperwalletProgramsConfiguration hyperwalletProgramsConfiguration) {
this.hyperwalletProgramsConfiguration = hyperwalletProgramsConfiguration;
}

public MiraklShops filterIgnoredShops(final MiraklShops shops) {
public void filterShops(final MiraklShops shops) {
final List<MiraklShop> validShops = shops.getShops().stream().filter(Predicate.not(this::isIgnored))
.collect(Collectors.toList());

shops.setShops(validShops);
shops.setTotalCount((long) validShops.size());

return shops;
}

private boolean isIgnored(final MiraklShop miraklShop) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.paypal.infrastructure.mirakl.client.filter;

import com.mirakl.client.mmp.domain.shop.MiraklShops;

public interface ShopsFilter {

void filterShops(final MiraklShops shops);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.paypal.infrastructure.mirakl.client.filter;

import com.mirakl.client.mmp.domain.shop.MiraklShop;
import com.mirakl.client.mmp.domain.shop.MiraklShopState;
import com.mirakl.client.mmp.domain.shop.MiraklShops;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Component
public class TerminatedShopsFilter implements ShopsFilter {

public void filterShops(final MiraklShops shops) {
final List<MiraklShop> validShops = shops.getShops().stream().filter(this::isNotShopStatusTerminated)
.collect(Collectors.toList());

shops.setShops(validShops);
shops.setTotalCount((long) validShops.size());
}

private boolean isNotShopStatusTerminated(final MiraklShop miraklShop) {
return miraklShop.getState() != MiraklShopState.TERMINATED;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.mirakl.client.mmp.request.shop.document.MiraklDownloadShopsDocumentsRequest;
import com.mirakl.client.mmp.request.shop.document.MiraklGetShopDocumentsRequest;
import com.paypal.infrastructure.mirakl.client.filter.IgnoredShopsFilter;
import com.paypal.infrastructure.mirakl.client.filter.TerminatedShopsFilter;
import com.paypal.infrastructure.mirakl.configuration.MiraklApiClientConfig;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -45,12 +46,16 @@ class DirectMiraklClientTest {
@Mock
private IgnoredShopsFilter ignoredShopsFilterMock;

@Mock
private TerminatedShopsFilter terminatedShopsFilterMock;

@BeforeEach
void setUp() {
final MiraklApiClientConfig config = new MiraklApiClientConfig();
config.setOperatorApiKey("OPERATOR-KEY");
config.setEnvironment("environment");
testObj = Mockito.spy(new DirectMiraklClient(config, ignoredShopsFilterMock));
testObj = Mockito
.spy(new DirectMiraklClient(config, List.of(ignoredShopsFilterMock, terminatedShopsFilterMock)));
ReflectionTestUtils.setField(testObj, "miraklMarketplacePlatformOperatorApiClient",
miraklMarketplacePlatformOperatorApiClientMock);
}
Expand All @@ -72,19 +77,18 @@ void getVersion_shouldDelegateOnMiraklSdkClient() {
@Test
void getShops_shouldCallSdkClient_andFilterShops() {
// given
final MiraklShops unfilteredMiraklShops = mock(MiraklShops.class);
final MiraklShops filteredMiraklShops = mock(MiraklShops.class);
when(ignoredShopsFilterMock.filterIgnoredShops(unfilteredMiraklShops)).thenReturn(filteredMiraklShops);
final MiraklShops miraklShops = mock(MiraklShops.class);
final MiraklGetShopsRequest miraklGetShopsRequest = mock(MiraklGetShopsRequest.class);
when(miraklMarketplacePlatformOperatorApiClientMock.getShops(miraklGetShopsRequest))
.thenReturn(unfilteredMiraklShops);
when(miraklMarketplacePlatformOperatorApiClientMock.getShops(miraklGetShopsRequest)).thenReturn(miraklShops);

// when
final MiraklShops result = testObj.getShops(miraklGetShopsRequest);

// then
assertThat(result).isEqualTo(filteredMiraklShops);
assertThat(result).isEqualTo(miraklShops);
verify(miraklMarketplacePlatformOperatorApiClientMock).getShops(miraklGetShopsRequest);
verify(ignoredShopsFilterMock).filterShops(miraklShops);
verify(terminatedShopsFilterMock).filterShops(miraklShops);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.paypal.infrastructure.mirakl.client;

import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop;
import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShops;
import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops;
import com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest;
import com.paypal.infrastructure.changestaging.model.Change;
import com.paypal.infrastructure.changestaging.service.ChangeStagingService;
import com.paypal.infrastructure.mirakl.client.converters.MiraklStageChangeConverter;
import com.paypal.infrastructure.mirakl.client.filter.IgnoredShopsFilter;
import com.paypal.infrastructure.mirakl.client.filter.ShopsFilter;
import com.paypal.infrastructure.mirakl.configuration.MiraklApiClientConfig;
import com.paypal.infrastructure.mirakl.settings.MiraklClientSettings;
import com.paypal.infrastructure.mirakl.settings.MiraklClientSettingsExecutor;
import com.paypal.infrastructure.mirakl.settings.MiraklClientSettingsHolder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -19,8 +17,6 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.InjectMocks;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.List;

Expand All @@ -38,13 +34,16 @@ class StageChangesMiraklClientTest {
@Mock
private MiraklStageChangeConverter miraklStageChangeConverterMock;

@Mock
private List<ShopsFilter> shopsFiltersMock;

@BeforeEach
void setUp() {
final MiraklApiClientConfig config = new MiraklApiClientConfig();
config.setOperatorApiKey("OPERATOR-KEY");
config.setEnvironment("environment");
testObj = Mockito.spy(new StageChangesMiraklClient(config, mock(IgnoredShopsFilter.class),
changeStagingServiceMock, miraklStageChangeConverterMock));
testObj = Mockito.spy(new StageChangesMiraklClient(config, shopsFiltersMock, changeStagingServiceMock,
miraklStageChangeConverterMock));
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ void getShops_shouldFilterShopsBelongingToIgnoredPrograms() {
mockIgnoreProgram(2, true);
mockIgnoreProgram(3, false);

final MiraklShops result = testObj.filterIgnoredShops(miraklShopsMock);
testObj.filterShops(miraklShopsMock);

verify(result, times(1)).setShops(argThat(x -> x.size() == 2));
verify(result, times(1)).setShops(argThat(x -> x.containsAll(List.of(miraklShop1Mock, miraklShop3Mock))));
verify(miraklShopsMock, times(1)).setShops(argThat(x -> x.size() == 2));
verify(miraklShopsMock, times(1))
.setShops(argThat(x -> x.containsAll(List.of(miraklShop1Mock, miraklShop3Mock))));
}

private void mockShop(final MiraklShop miraklShopMock, final int id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.paypal.infrastructure.mirakl.client.filter;

import com.mirakl.client.mmp.domain.shop.MiraklShop;
import com.mirakl.client.mmp.domain.shop.MiraklShopState;
import com.mirakl.client.mmp.domain.shop.MiraklShops;
import com.paypal.infrastructure.mirakl.configuration.MiraklApiClientConfig;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.List;

import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
class TerminatedShopsFilterTest {

@InjectMocks
private TerminatedShopsFilter testObj;

@Mock
private MiraklShops miraklShopsMock;

@Mock
private MiraklShop miraklShop1Mock, miraklShop2Mock, miraklShop3Mock;

@BeforeEach
void setUp() {
final MiraklApiClientConfig config = new MiraklApiClientConfig();
config.setOperatorApiKey("OPERATOR-KEY");
config.setEnvironment("environment");
}

@Test
void getShops_shouldFilterShopsHaveStateAsTerminated() {
when(miraklShopsMock.getShops()).thenReturn(List.of(miraklShop1Mock, miraklShop2Mock, miraklShop3Mock));
when(miraklShop1Mock.getState()).thenReturn(MiraklShopState.TERMINATED);
when(miraklShop2Mock.getState()).thenReturn(MiraklShopState.OPEN);
when(miraklShop3Mock.getState()).thenReturn(MiraklShopState.SUSPENDED);

testObj.filterShops(miraklShopsMock);

verify(miraklShopsMock, times(1)).setShops(argThat(x -> x.size() == 2));
verify(miraklShopsMock, times(1))
.setShops(argThat(x -> x.containsAll(List.of(miraklShop2Mock, miraklShop3Mock))));
}

}
2 changes: 1 addition & 1 deletion hmc-observability/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {

inpath 'org.apache.httpcomponents:httpclient'
inpath 'com.hyperwallet:sdk:2.4.3'
inpath 'com.mirakl:mmp-sdk-operator:6.8.0'
inpath 'com.mirakl:mmp-sdk-operator:6.37.0'

testImplementation project(":hmc-testsupport")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public enum MiraklFieldPermissions {

INVISIBLE, READ_ONLY, READ_WRITE
INVISIBLE, READ_ONLY, READ_WRITE, UNKNOWN_ENUM_VALUE

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public enum MiraklFieldType {

TEXT, DATE, NUMERIC, BOOLEAN, LINK, REGULAR_EXPRESSION, TEXT_AREA, SINGLE_VALUE_LIST, MULTIPLE_VALUES_LIST
TEXT, DATE, NUMERIC, BOOLEAN, LINK, REGULAR_EXPRESSION, TEXT_AREA, SINGLE_VALUE_LIST, MULTIPLE_VALUES_LIST, UNKNOWN_ENUM_VALUE

}

0 comments on commit c5a03ee

Please sign in to comment.