# Path: rocketchat_API/APIExceptions/RocketExceptions.py
# class RocketMissingParamException(Exception):
#     pass


import pytest
from rocketchat_API.APIExceptions.RocketExceptions import RocketMissingParamException


def test_im_list_everyone(logged_rocket):
    im_list_everyone = logged_rocket.im_list_everyone().json()
    assert im_list_everyone.get("success")


def test_im_history(logged_rocket, recipient_user):
    im_create = logged_rocket.im_create(recipient_user).json()
    room_id = im_create.get("room").get("_id")
    im_history = logged_rocket.im_history(room_id).json()
    assert im_history.get("success")


def test_im_members(logged_rocket, recipient_user):
    im_create = logged_rocket.im_create(recipient_user).json()
    room_id = im_create.get("room").get("_id")
    im_members = logged_rocket.im_members(room_id=room_id).json()
    assert im_members.get("success")
    assert im_members.get("members")[0].get("name") == "user1"


def test_im_messages(logged_rocket, recipient_user):
    im_message = logged_rocket.im_messages(username=recipient_user).json()
    assert im_message.get("success")
    im_create = logged_rocket.im_create(recipient_user).json()
    room_id = im_create.get("room").get("_id")
    im_message = logged_rocket.im_messages(room_id=room_id).json()
    assert im_message.get("success")


# Path: rocketchat_API/APIExceptions/RocketExceptions.py
# class RocketMissingParamException(Exception):
#     pass


# Path: tests/test_ims.py
import pytest
from rocketchat_API.APIExceptions.RocketExceptions import RocketMissingParamException



def test_im_list_everyone(logged_rocket):
    im_list_everyone = logged_rocket.im_list_everyone().json()
    assert im_list_everyone.get("success")


def test_im_history(logged_rocket, recipient_user):
    im_create = logged_rocket.im_create(recipient_user).json()
    room_id = im_create.get("room").get("_id")
    im_history = logged_rocket.im_history(room_id).json()
    assert im_history.get("success")


def test_im_members(logged_rocket, recipient_user):
    im_create = logged_rocket.im_create(recipient_user).json()
    room_id = im_create.get("room").get("_id")
    im_members = logged_rocket.im_members(room_id=room_id).json()
    assert im_members.get("success")
    assert im_members.get("members")[0].get("name") == "user1"


def test_im_messages(logged_rocket, recipient_user):
    im_message = logged_rocket.im_messages(username=recipient_user).json()
    assert im_message.get("success")
    im_create = logged_rocket.im_create(recipient_user).json()
    room_id = im_create.get("room").get("_id")
    im_message = logged_rocket.im_messages(room_id=room_id).json()
    assert im_message.get("success")


    with pytest.raises(RocketMissingParamException):