package models;

import com.neovisionaries.i18n.CountryCode;
import common.models.CommonDataBuilder;
import common.models.UserContext;
import io.sphere.sdk.models.LocalizedStrings;
import io.sphere.sdk.products.*;
import io.sphere.sdk.producttypes.ProductType;
import io.sphere.sdk.producttypes.ProductTypeBuilder;
import org.junit.Test;
import play.i18n.Lang;

import java.util.Arrays;
import java.util.List;

import static io.sphere.sdk.products.ProductProjectionType.CURRENT;
import static java.util.Collections.emptyList;
import static org.fest.assertions.Assertions.assertThat;

public class CommonDataTest {

    @Test
    public void hasProvidedProductList() {
        List<ProductProjection> productList = Arrays.asList(defaultProduct());
        CommonDataBuilder builder = CommonDataBuilder.of(defaultContext(), emptyList()).products(productList);
        assertThat(builder.build().products()).isEqualTo(productList);
    }

    @Test
    public void hasEmptyProductListWhenNoneProvided() {
        CommonDataBuilder builder = CommonDataBuilder.of(defaultContext(), emptyList());
        assertThat(builder.build().products()).isEmpty();
    }

    private UserContext defaultContext() {
        return UserContext.of(Lang.forCode("de"), CountryCode.DE);
    }

    private ProductProjection defaultProduct() {
        ProductType productType = ProductTypeBuilder.of("id", "product-type", "", emptyList()).build();
        LocalizedStrings locString = LocalizedStrings.ofEnglishLocale("text");
        ProductVariant variant = ProductVariantBuilder.of(1).build();
        ProductData productData = ProductDataBuilder.of(locString, locString, variant).build();
        ProductCatalogData catalogData = ProductCatalogDataBuilder.ofStaged(productData).build();
        return ProductBuilder.of(productType, catalogData).build().toProjection(CURRENT).get();
    }
}

@@ -463,23 +463,22 @@
 ionType.
-CURRENT
+STAGED
 ;%0Aimport
@@ -1845,15 +1845,14 @@
 ion(
-CURRENT
+STAGED
 ).ge

Fix test.