示例#1
0
def test_get_chats_by_user_id__last_read_id_none():
    user = create_user("00")
    other_party = create_user("10")

    chat_room = create_chat_room("01")
    create_user_chat_room_association(
        "02",
        user_id=user["id"],
        chat_room_id=chat_room["id"],
        is_archived=False,
        last_read_id=None,
    )
    create_user_chat_room_association(
        "12",
        user_id=other_party["id"],
        chat_room_id=chat_room["id"],
        is_archived=False,
        last_read_id=None,
    )

    create_chat("03",
                chat_room_id=chat_room["id"],
                author_id=other_party["id"])

    res = chat_service.get_chats_by_user_id(
        user_id=user["id"], as_buyer=True,
        as_seller=True)["unarchived"][chat_room["id"]]
    assert res["last_read_id"] is None
    assert res["unread_count"] == 1

    res_other = chat_service.get_chats_by_user_id(
        user_id=other_party["id"], as_buyer=True,
        as_seller=True)["unarchived"][chat_room["id"]]
    assert res_other["last_read_id"] is None
    assert res_other["unread_count"] == 0  # chat is made by other party
示例#2
0
def test_get_chats_by_user_id__chats():
    user = create_user("00")
    other_party = create_user("10")
    chat_room = create_chat_room("01")
    create_user_chat_room_association("02",
                                      user_id=user["id"],
                                      chat_room_id=chat_room["id"],
                                      is_archived=False)
    create_user_chat_room_association("12",
                                      user_id=other_party["id"],
                                      chat_room_id=chat_room["id"])
    chat = create_chat("03",
                       chat_room_id=chat_room["id"],
                       author_id=user["id"])
    other_chat = create_chat("13",
                             chat_room_id=chat_room["id"],
                             author_id=other_party["id"])

    res = chat_service.get_chats_by_user_id(user_id=user["id"],
                                            as_buyer=True,
                                            as_seller=True)

    res_room = res["unarchived"][chat_room["id"]]
    chat_room.pop("disband_by_user_id")
    chat_room.pop("disband_time")
    assert_dict_in(chat_room, res_room)

    res_chats = res_room["chats"]
    assert {**chat, "type": "chat"} in res_chats
    assert {**other_chat, "type": "chat"} in res_chats
示例#3
0
def test_get_chats_by_user_id__created_at_sort():
    user = create_user("00")
    other_party = create_user("10")

    chat_room = create_chat_room("01")
    create_user_chat_room_association("02",
                                      user_id=user["id"],
                                      chat_room_id=chat_room["id"],
                                      is_archived=False)
    create_user_chat_room_association("12",
                                      user_id=other_party["id"],
                                      chat_room_id=chat_room["id"])

    chat = create_chat(
        "03",
        chat_room_id=chat_room["id"],
        author_id=user["id"],
        created_at=datetime.now(),
    )
    offer = create_offer(
        "04",
        chat_room_id=chat_room["id"],
        author_id=user["id"],
        created_at=datetime.now() - timedelta(hours=1),
    )
    resp = create_offer_response("05",
                                 offer_id=offer["id"],
                                 created_at=datetime.now() +
                                 timedelta(hours=1))

    res_chats = chat_service.get_chats_by_user_id(
        user_id=user["id"], as_buyer=True,
        as_seller=True)["unarchived"][chat_room["id"]]["chats"]
    assert [r["id"]
            for r in res_chats] == [offer["id"], chat["id"], resp["id"]]
示例#4
0
def test_get_chats_by_user_id__as_buyer_seller():
    user = create_user("00")
    other_party = create_user("10")

    chat_room = create_chat_room("01")
    create_user_chat_room_association(
        "02",
        user_id=user["id"],
        chat_room_id=chat_room["id"],
        is_archived=False,
        role="BUYER",
    )
    create_user_chat_room_association("12",
                                      user_id=other_party["id"],
                                      chat_room_id=chat_room["id"],
                                      role="SELLER")
    create_chat(chat_room_id=chat_room["id"], author_id=user["id"])

    chat_room2 = create_chat_room("11")
    create_user_chat_room_association(
        "22",
        user_id=user["id"],
        chat_room_id=chat_room2["id"],
        is_archived=False,
        role="SELLER",
    )
    create_user_chat_room_association("32",
                                      user_id=other_party["id"],
                                      chat_room_id=chat_room2["id"],
                                      role="BUYER")
    create_chat(chat_room_id=chat_room2["id"], author_id=user["id"])

    res_buyer = chat_service.get_chats_by_user_id(user_id=user["id"],
                                                  as_buyer=True,
                                                  as_seller=False)
    assert len(res_buyer["unarchived"]) == 1
    assert chat_room["id"] in res_buyer["unarchived"]

    res_seller = chat_service.get_chats_by_user_id(user_id=user["id"],
                                                   as_buyer=False,
                                                   as_seller=True)
    assert len(res_seller["unarchived"]) == 1
    assert chat_room2["id"] in res_seller["unarchived"]
示例#5
0
def test_get_chats_by_user_id__hidden_buy_order():
    user = create_user("00")
    other_party = create_user("10")
    chat_room = create_chat_room("01")
    create_user_chat_room_association(
        "02",
        user_id=user["id"],
        chat_room_id=chat_room["id"],
        is_archived=False,
        role="BUYER",
    )
    create_user_chat_room_association("12",
                                      user_id=other_party["id"],
                                      chat_room_id=chat_room["id"])
    create_chat(chat_room_id=chat_room["id"], author_id=other_party["id"])

    res = chat_service.get_chats_by_user_id(user_id=user["id"],
                                            as_buyer=True,
                                            as_seller=False)
    assert res["unarchived"][chat_room["id"]]["sell_order"] is None