from src.items.conjured import ConjuredItem
import pytest

from src.items.conjured import ConjuredItem
from src.items.exceptions.invalid_quality_value import InvalidQualityValue

@pytest.fixture
def conjured_apple():
    return ConjuredItem('Conjured Apple', 11, 5)

@pytest.fixture
def old_conjured_apple():
    return ConjuredItem('Old Conjured Apple', -1, 5)

@pytest.fixture
def conjured_wine():
    return ConjuredItem('Conjured Wine', 0, 1)

def test_should_decrement_sell_in_when_updated(conjured_apple):
    conjured_apple.update_quality()
    assert conjured_apple.get_sell_in() == 10

def test_should_decrement_quality_by_two_when_updated_and_sell_in_date_not_passed(conjured_apple):
    conjured_apple.update_quality()
    assert conjured_apple.get_quality() == 3

def test_should_decrement_quality_by_four_when_updated_and_sell_in_date_passed(old_conjured_apple):
    old_conjured_apple.update_quality()
    assert old_conjured_apple.get_quality() == 1

def test_quality_should_be_zero_when_quality_update_and_item_quality_is_less_than_decremented_value(conjured_wine):
    conjured_wine.update_quality()
    assert conjured_wine.get_quality() == 0

def test_should_not_create_conjured_item_when_quality_value_is_greater_than_maximum_value():
    with pytest.raises(InvalidQualityValue):
        ConjuredItem('Invalid Conjured Item', 2, 51)

def test_should_not_create_backstage_passes_item_when_quality_value_is_less_than_minimum_value():
    with pytest.raises(InvalidQualityValue):
        ConjuredItem('Invalid Conjured Item', 2, -1)
