import pytest

from src.items.aged_brie import AgedBrieItem
from src.items.exceptions.invalid_quality_value import InvalidQualityValue

@pytest.fixture
def aged_brie():
    return  AgedBrieItem('Aged Brie', 3, 5)

@pytest.fixture
def old_aged_brie():
    return AgedBrieItem('Old Aged Brie', -1, 35)

@pytest.fixture
def great_aged_brie():
    return AgedBrieItem('Great Aged Brie', -1, 50)

def test_should_decrement_sell_in_when_updated(aged_brie):
    aged_brie.update_quality()
    assert aged_brie.get_sell_in() == 2

def test_should_increment_quality_by_one_when_updated(aged_brie):
    aged_brie.update_quality()
    assert aged_brie.get_quality() == 6

def test_should_increment_quality_by_one_when_sell_in_date_has_passed(old_aged_brie):
    old_aged_brie.update_quality()
    assert old_aged_brie.get_quality() == 36

def test_should_not_create_aged_brie_item_when_quality_value_is_less_than_minimum_value():
    with pytest.raises(InvalidQualityValue):
        AgedBrieItem('Invalid Aged Brie', 2, -1)

def test_should_not_create_aged_brie_item_when_quality_value_is_greater_than_maximum_value():
    with pytest.raises(InvalidQualityValue):
        AgedBrieItem('Invalid Aged Brie', 2, 51)

def test_should_not_update_quality_when_reached_its_maximum_value(great_aged_brie):
    great_aged_brie.update_quality()
    assert great_aged_brie.get_quality() == 50