Skip to content

Commit

Permalink
Bugfix + create chat with random user
Browse files Browse the repository at this point in the history
  • Loading branch information
KrySeyt committed Feb 19, 2024
1 parent eb8718b commit 29b5512
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/just_chat/main/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
from passlib.handlers.argon2 import argon2

from just_chat.adapters.security.password_provider import HashingPasswordProvider
from just_chat.application.common.id_provider import IdProvider
from just_chat.application.common.password_provider import PasswordProvider
from just_chat.main.ioc import ChatIoC, UserIoC
from just_chat.presentation.interactor_factory.chat import ChatInteractorFactory
from just_chat.presentation.interactor_factory.user import UserInteractorFactory
from just_chat.presentation.web_api.chat import chat_router
from just_chat.presentation.web_api.dependencies.id_provider import get_session_id_provider
from just_chat.presentation.web_api.user import user_router

DependencyT = TypeVar("DependencyT")
Expand All @@ -30,5 +32,6 @@ def create_app() -> FastAPI:
app.dependency_overrides[ChatInteractorFactory] = singleton(chat_ioc)
app.dependency_overrides[UserInteractorFactory] = singleton(user_ioc)
app.dependency_overrides[PasswordProvider] = singleton(HashingPasswordProvider(argon2))
app.dependency_overrides[IdProvider] = get_session_id_provider

return app
1 change: 1 addition & 0 deletions src/just_chat/presentation/web_api/chat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from . import get_chat # noqa F401
from . import create_chat # noqa F401
from . import delete_chat # noqa F401
from . import create_chat_with_random_user # noqa F401
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@chat_router.post("/random")
def create_chat(
def create_chat_with_random_user(
interactor_factory: Annotated[ChatInteractorFactory, Depends()],
id_provider: Annotated[IdProvider, Depends(Stub(IdProvider))],
data: NewChatDTO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ def get_session_id_provider(
ioc: Annotated[UserInteractorFactory, Depends()],
token: Annotated[str, Cookie()]
) -> Generator[SessionIdProvider, None, None]:
_, token = token.split(" ")
with ioc.get_user_id_by_token() as get_user_id_by_token_interactor:
yield SessionIdProvider(SessionToken(token), get_user_id_by_token_interactor)
9 changes: 7 additions & 2 deletions tests/web/test_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,19 @@ def test_create_chat_with_random_user(
assert response.status_code == 200
assert "token" in response.cookies

response = client.post(r"/chat/random")
response = client.post(
r"/chat/random",
json={
"title": "Title",
}
)

assert response.status_code == 200

response_json = response.json()

assert isinstance(response_json["id"], int)
assert response_json["users_ids"] == [user1.id, user2.id]
assert len(response_json["users_ids"]) == 2
assert response_json["title"] == "Title"

chat = chat_gateway.get_chat_by_id(response_json["id"])
Expand Down

0 comments on commit 29b5512

Please sign in to comment.