mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-15 01:21:48 +03:00
test(added): misc prompt onboarding (#1622)
Added tests for: - Prompt - Misc - Onboarding
This commit is contained in:
parent
6017fa2e9c
commit
ee864e6441
@ -92,6 +92,24 @@ class Onboarding(Repository):
|
||||
|
||||
return OnboardingStates(**onboarding_data[0])
|
||||
|
||||
def create_user_onboarding(self, user_id: UUID) -> OnboardingStates:
|
||||
"""
|
||||
Create user onboarding information by user_id
|
||||
"""
|
||||
onboarding_data = (
|
||||
self.db.from_("onboardings")
|
||||
.insert(
|
||||
[
|
||||
{
|
||||
"user_id": str(user_id),
|
||||
}
|
||||
]
|
||||
)
|
||||
.execute()
|
||||
).data
|
||||
|
||||
return OnboardingStates(**onboarding_data[0])
|
||||
|
||||
def remove_onboarding_more_than_x_days(self, days: int):
|
||||
"""
|
||||
Remove onboarding if it is older than x days
|
||||
|
15
backend/repository/onboarding/create_user_onboarding.py
Normal file
15
backend/repository/onboarding/create_user_onboarding.py
Normal file
@ -0,0 +1,15 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.databases.supabase.onboarding import (
|
||||
OnboardingStates,
|
||||
)
|
||||
from models.settings import get_supabase_db
|
||||
|
||||
|
||||
def create_user_onboarding(user_id: UUID) -> OnboardingStates:
|
||||
"""Update user onboarding information by user_id"""
|
||||
|
||||
supabase_db = get_supabase_db()
|
||||
created_user_onboarding = supabase_db.create_user_onboarding(user_id)
|
||||
|
||||
return created_user_onboarding
|
10
backend/tests/test_misc.py
Normal file
10
backend/tests/test_misc.py
Normal file
@ -0,0 +1,10 @@
|
||||
def test_heatlhz(client):
|
||||
response = client.get("/healthz")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"status": "ok"}
|
||||
|
||||
|
||||
def test_heatlhz_home(client):
|
||||
response = client.get("/")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"status": "OK"}
|
69
backend/tests/test_onboarding.py
Normal file
69
backend/tests/test_onboarding.py
Normal file
@ -0,0 +1,69 @@
|
||||
from repository.onboarding.create_user_onboarding import create_user_onboarding
|
||||
|
||||
|
||||
def test_remove_onboarding(client, api_key):
|
||||
response = client.put(
|
||||
"/onboarding",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
json={
|
||||
"onboarding_a": False,
|
||||
"onboarding_b1": False,
|
||||
"onboarding_b2": False,
|
||||
"onboarding_b3": False,
|
||||
},
|
||||
)
|
||||
assert response.status_code == 404
|
||||
assert response.json() == {"detail": "User onboarding not updated"}
|
||||
|
||||
|
||||
def test_create_onboarding(client, api_key):
|
||||
response = client.get("/user", headers={"Authorization": "Bearer " + api_key})
|
||||
|
||||
create_user_onboarding_response = create_user_onboarding(response.json().get("id"))
|
||||
assert create_user_onboarding_response == {
|
||||
"onboarding_a": True,
|
||||
"onboarding_b1": True,
|
||||
"onboarding_b2": True,
|
||||
"onboarding_b3": True,
|
||||
}
|
||||
|
||||
|
||||
def test_get_onboarding(client, api_key):
|
||||
response = client.get(
|
||||
"/onboarding",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert "onboarding_a" in response.json()
|
||||
assert "onboarding_b1" in response.json()
|
||||
assert "onboarding_b2" in response.json()
|
||||
assert "onboarding_b3" in response.json()
|
||||
|
||||
|
||||
def test_update_onboarding_to_false(client, api_key):
|
||||
response = client.put(
|
||||
"/onboarding",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
json={
|
||||
"onboarding_a": False,
|
||||
"onboarding_b1": False,
|
||||
"onboarding_b2": False,
|
||||
"onboarding_b3": False,
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {
|
||||
"onboarding_a": False,
|
||||
"onboarding_b1": False,
|
||||
"onboarding_b2": False,
|
||||
"onboarding_b3": False,
|
||||
}
|
||||
|
||||
|
||||
def test_onboarding_empty(client, api_key):
|
||||
response = client.get(
|
||||
"/onboarding",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == None
|
7
backend/tests/test_prompt.py
Normal file
7
backend/tests/test_prompt.py
Normal file
@ -0,0 +1,7 @@
|
||||
def test_get_public_prompts(client, api_key):
|
||||
response = client.get(
|
||||
"/prompts",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert len(response.json()) == 0
|
Loading…
Reference in New Issue
Block a user