Skip to content

Commit

Permalink
Use utility method to mock graphql request
Browse files Browse the repository at this point in the history
  • Loading branch information
salander85 committed Oct 25, 2023
1 parent c325130 commit ce26a52
Showing 1 changed file with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.commercetools.project.sync.util.TestUtils.createBadGatewayException;
import static com.commercetools.project.sync.util.TestUtils.getMockedClock;
import static com.commercetools.project.sync.util.TestUtils.mockResourceIdsGraphQlRequest;
import static com.commercetools.project.sync.util.TestUtils.readObjectFromResource;
import static com.commercetools.project.sync.util.TestUtils.withTestClient;
import static java.util.Collections.singletonList;
Expand All @@ -16,7 +17,6 @@
import com.commercetools.api.client.ProjectApiRoot;
import com.commercetools.api.defaultconfig.ApiRootBuilder;
import com.commercetools.api.models.graph_ql.GraphQLRequest;
import com.commercetools.api.models.graph_ql.GraphQLResponse;
import com.commercetools.api.models.product.Product;
import com.commercetools.api.models.product.ProductDraft;
import com.commercetools.api.models.product.ProductMixin;
Expand Down Expand Up @@ -205,21 +205,8 @@ void transform_WithDiscountedPrices_ShouldRemoveDiscountedPrices() {
readObjectFromResource("product-key-10.json", Product.class),
ProductProjectionType.STAGED);

final String jsonStringProductTypes =
"{\"data\":{\"productTypes\":{\"results\":[{\"id\":\"53c4a8b4-754f-4b95-b6f2-3e1e70e3d0d3\","
+ "\"key\":\"prodType1\"}]}}}";
final GraphQLResponse graphQLResponse =
JsonUtils.fromJsonString(jsonStringProductTypes, GraphQLResponse.class);
final ApiHttpResponse apiHttpResponse = mock(ApiHttpResponse.class);
when(apiHttpResponse.getBody()).thenReturn(graphQLResponse);

final ByProjectKeyGraphqlPost byProjectKeyGraphqlPost = mock(ByProjectKeyGraphqlPost.class);
when(byProjectKeyGraphqlPost.execute())
.thenReturn(CompletableFuture.completedFuture(apiHttpResponse));

when(sourceClient.graphql()).thenReturn(mock());
when(sourceClient.graphql().post(any(GraphQLRequest.class)))
.thenReturn(byProjectKeyGraphqlPost);
mockResourceIdsGraphQlRequest(
sourceClient, "productTypes", "53c4a8b4-754f-4b95-b6f2-3e1e70e3d0d3", "prodType1");

// test
final List<ProductDraft> draftsFromPageStage =
Expand Down

0 comments on commit ce26a52

Please sign in to comment.