diff --git a/backend/models/databases/supabase/onboarding.py b/backend/models/databases/supabase/onboarding.py index 3e49bf3a9..4837cee96 100644 --- a/backend/models/databases/supabase/onboarding.py +++ b/backend/models/databases/supabase/onboarding.py @@ -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 diff --git a/backend/repository/onboarding/create_user_onboarding.py b/backend/repository/onboarding/create_user_onboarding.py new file mode 100644 index 000000000..7ddb1e2bf --- /dev/null +++ b/backend/repository/onboarding/create_user_onboarding.py @@ -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 diff --git a/backend/tests/test_misc.py b/backend/tests/test_misc.py new file mode 100644 index 000000000..e1b93a8be --- /dev/null +++ b/backend/tests/test_misc.py @@ -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"} diff --git a/backend/tests/test_onboarding.py b/backend/tests/test_onboarding.py new file mode 100644 index 000000000..4cfdd5306 --- /dev/null +++ b/backend/tests/test_onboarding.py @@ -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 diff --git a/backend/tests/test_prompt.py b/backend/tests/test_prompt.py new file mode 100644 index 000000000..59ac7ab10 --- /dev/null +++ b/backend/tests/test_prompt.py @@ -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