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_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