Commit 30c2d8ad authored by Khai Yuan ​Liew's avatar Khai Yuan ​Liew

[AFP-60] Finish work on bulkSearchSKU endpoint + test

parent 11f308f3
...@@ -4,11 +4,15 @@ import com.nisum.ascend.promotions.dto.PromotionDto; ...@@ -4,11 +4,15 @@ import com.nisum.ascend.promotions.dto.PromotionDto;
import com.nisum.ascend.promotions.repository.PromotionRepository; import com.nisum.ascend.promotions.repository.PromotionRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.BodyInserters;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers; import reactor.core.scheduler.Schedulers;
import java.util.List; import java.util.List;
import static org.springframework.http.ResponseEntity.notFound;
import static org.springframework.http.ResponseEntity.ok;
@Service @Service
public class PromotionService { public class PromotionService {
...@@ -25,16 +29,8 @@ public class PromotionService { ...@@ -25,16 +29,8 @@ public class PromotionService {
public Flux<PromotionDto> bulkSearchSKU(List<String> skus){ public Flux<PromotionDto> bulkSearchSKU(List<String> skus){
// skus.stream().map(sku -> findPromotionsByProductSku(sku)); return Flux.fromIterable(skus)
.flatMap(sku -> findPromotionsByProductSku(sku));
// return Flux.fromStream(skus.stream().map(sku -> findPromotionsByProductSku(sku)));
return null;
// return Flux.fromIterable(skus)
// .map(sku -> {
// return findPromotionsByProductSku(sku);
// });
} }
} }
...@@ -14,7 +14,10 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -14,7 +14,10 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
...@@ -86,4 +89,32 @@ class PromotionsControllerTest { ...@@ -86,4 +89,32 @@ class PromotionsControllerTest {
promos.forEach(p -> assertEquals(skuWithMultiplePromos, p.getProductSku())); promos.forEach(p -> assertEquals(skuWithMultiplePromos, p.getProductSku()));
}); });
} }
@Test
public void bulkSearchTest(){
List<String> skus = Arrays.asList("AFP-1", "AFP-2");
webTestClient.post().uri("/api/promos/bulkSearch")
.contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
.body(Mono.just(skus), List.class)
.exchange()
.expectStatus().isOk()
.expectBodyList(PromotionDto.class)
.consumeWith(promo ->{
List<PromotionDto> promos = promo.getResponseBody();
assert promos != null;
promos.forEach(p -> {
String sku = p.getProductSku();
String promotionId = p.getPromotionId();
assertTrue(skus.contains(sku));
System.out.println("Product SKU: " + sku);
System.out.println("Promotion ID: " + promotionId);
} );
});
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment