test(added): misc prompt onboarding (#1622)

Added tests for:

- Prompt
- Misc
- Onboarding
This commit is contained in:
Stan Girard 2023-11-13 19:02:10 +01:00 committed by GitHub
parent 6017fa2e9c
commit ee864e6441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 119 additions and 0 deletions

View File

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

View 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

View 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"}

View 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

View 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