package shop;

import org.junit.jupiter.api.Test;

import java.math.BigDecimal;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * Acceptance tests written BEFORE the implementation, from the requirement plus the answers a human gave to four
 * questions: is "over" strict? does shipping count toward the threshold? is shipping discounted? how is it rounded?
 * The answers: strictly over 1000, goods subtotal only, shipping never discounted, round to paise HALF_UP.
 */
class PricingSpecTest {

    private final PricingService pricing = new PricingService();

    private static BigDecimal d(String s) { return new BigDecimal(s); }

    @Test
    void exactly1000GetsNoDiscount() {
        assertEquals(d("0.00"), pricing.quote(d("1000"), d("0")).discount());
    }

    @Test
    void justOver1000GetsTenPercentOfTheSubtotal() {
        var q = pricing.quote(d("1000.01"), d("0"));
        assertEquals(d("100.00"), q.discount());
        assertEquals(d("900.01"), q.total());
    }

    @Test
    void shippingIsNeverDiscounted() {
        var q = pricing.quote(d("1200"), d("100"));
        assertEquals(d("120.00"), q.discount());
        assertEquals(d("1180.00"), q.total());
    }

    @Test
    void shippingDoesNotPushAnOrderOverTheThreshold() {
        assertEquals(d("0.00"), pricing.quote(d("950"), d("100")).discount());
    }
}
