def test_select_house_ok(service: AttachContactToReservation, context: Context,
                         house):
    service._houses_repo = Mock(get=Mock(return_value=Some(house)))

    result = service.select_house(context)
    assert is_successful(result), result.failure()
    assert result.unwrap().house == house
def test_select_house_fail(service: AttachContactToReservation,
                           context: Context):
    service._houses_repo = Mock(get=Mock(return_value=Nothing))

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_house
def test_select_house_error(service: AttachContactToReservation,
                            context: Context):
    service._houses_repo = Mock(get=Mock(side_effect=RuntimeError("ERR")))

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == "ERR"
def test_select_reservation_ok(service: AttachContactToReservation,
                               context: Context, house, reservation):
    service._reservations_repo = Mock(get=Mock(return_value=Some(reservation)))
    context.house = house

    result = service.select_reservation(context)
    assert is_successful(result)
    assert result.unwrap().reservation == reservation
def test_save_fail(service: AttachContactToReservation, context: Context,
                   house, reservation):
    service._reservations_repo = Mock(save=Mock(return_value=(Nothing, False)))
    context.house = house
    context.reservation = reservation

    result = service.save(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.save
    assert result.failure().error.startswith("Error save Reservation")
def test_save_error(service: AttachContactToReservation, context: Context,
                    house, reservation):
    service._reservations_repo = Mock(save=Mock(
        side_effect=RuntimeError("ERR")))
    context.house = house
    context.reservation = reservation

    result = service.save(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == "ERR"
def test_success(service: AttachContactToReservation, context: Context, house,
                 reservation):
    _reservation = attr.evolve(reservation,
                               guest_contact_id=200,
                               guest_contact_ids=[200])
    service._houses_repo = Mock(get=Mock(return_value=Some(house)))
    service._reservations_repo = Mock(
        get=Mock(return_value=Some(reservation)),
        save=Mock(return_value=(Some(_reservation), True)))

    result = service.execute(house.id, reservation.id, 200)
    assert is_successful(result)
    assert result.unwrap()
def test_save_reservation_ok(service: AttachContactToReservation,
                             context: Context, house, reservation):
    _reservation = attr.evolve(reservation,
                               guest_contact_id=200,
                               guest_contact_ids=[200])
    service._reservations_repo = Mock(save=Mock(
        return_value=(Some(_reservation), True)))
    context.house = house
    context.reservation = reservation

    result = service.save(context)
    assert is_successful(result)
    assert result.unwrap().reservation == _reservation
def test_missed_house_id(service: AttachContactToReservation,
                         context: Context):
    context.house_id = None

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_house
def test_check_reservation_ok(service: AttachContactToReservation,
                              context: Context, house, reservation):
    context.house = house
    context.reservation = reservation

    result = service.check_reservation(context)
    assert is_successful(result)
def test_check_reservation_room_close(service: AttachContactToReservation,
                                      context: Context, house, reservation):
    context.house = house
    context.reservation = attr.evolve(reservation,
                                      status=ReservationStatuses.CLOSE)

    result = service.check_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
def test_add_contact_duplicated(service: AttachContactToReservation,
                                context: Context, reservation):
    context.reservation = attr.evolve(reservation,
                                      guest_contact_id=10,
                                      guest_contact_ids=[10, 200])

    result = service.add_contact(context)
    assert is_successful(result)
    assert result.unwrap().reservation.guest_contact_id == 10
    assert result.unwrap().reservation.guest_contact_ids == [10, 200]
def test_add_contact_first(service: AttachContactToReservation,
                           context: Context, reservation):
    context.reservation = attr.evolve(reservation,
                                      guest_contact_id=None,
                                      guest_contact_ids=[])

    result = service.add_contact(context)
    assert is_successful(result)
    assert result.unwrap().reservation.guest_contact_id == 200
    assert result.unwrap().reservation.guest_contact_ids == [200]
def service() -> AttachContactToReservation:
    return AttachContactToReservation()