From e8c24c35013e53522a1b6839f91e6a5f0d6e55fa Mon Sep 17 00:00:00 2001 From: David MENDY Date: Fri, 9 Aug 2024 16:57:43 +0200 Subject: [PATCH] test: :white_check_mark: add api test for contact-details endpoint --- backend/src/router.py | 16 +++++-- backend/tests/test_api.py | 13 ++++++ .../GuideContactExpert/ExpertSituation.vue | 45 +++++++------------ 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/backend/src/router.py b/backend/src/router.py index 64374a887..b8b63fd0b 100644 --- a/backend/src/router.py +++ b/backend/src/router.py @@ -21,8 +21,14 @@ from fastapi.responses import PlainTextResponse from user_agents import parse -from .config import APP_VERSION, S3_PREFIX, TYPOLOGIES_MEASURED, get_base_logs, PHONE_NUMBER, CELLPHONE_NUMBER -from .models import EmailData +from .config import ( + APP_VERSION, + CELLPHONE_NUMBER, + PHONE_NUMBER, + S3_PREFIX, + TYPOLOGIES_MEASURED, + get_base_logs, +) from .utils import get_current_user, send_mail, upload_image router = APIRouter(prefix="/api") @@ -37,11 +43,15 @@ def home(): def version(): return APP_VERSION + @router.get("/contact-details") async def phone_number( current_user: Annotated[dict, Depends(get_current_user)], ): - return PHONE_NUMBER, CELLPHONE_NUMBER + return { + "phone": PHONE_NUMBER, + "cellphone": CELLPHONE_NUMBER, + } @router.post("/upload") diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index 36727d95d..c3dc6ed0f 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -187,3 +187,16 @@ def test_403(self): response = client.post("/api/expert-contact") response.data = response.json() assert response.status_code == 403 + + +class TestExpertDetails: + @pytest.mark.skip("Need to authenticate to run that test.") + def test_success(self): + response = client.get("/api/contact-details") + response.data = response.json() + assert response.status_code == 200 + + def test_403(self): + response = client.get("/api/contact-details") + response.data = response.json() + assert response.status_code == 403 diff --git a/frontend/src/views/GuideContactExpert/ExpertSituation.vue b/frontend/src/views/GuideContactExpert/ExpertSituation.vue index 8577a62e6..82e5712a6 100644 --- a/frontend/src/views/GuideContactExpert/ExpertSituation.vue +++ b/frontend/src/views/GuideContactExpert/ExpertSituation.vue @@ -5,40 +5,25 @@ import { DateTime } from "luxon"; import { mgr } from "@/utils/authentication"; import { getContactDetails } from "@/api/api-client"; -const getAccessToken: Ref = ref(""); -const authIDP: Ref = ref(""); +const user = ref(Object || null); +mgr.getUser().then((data) => (user.value = data)); -// Récupération des données de l'utilisateur -const getUserData = async () => { - try { - const user = await mgr.getUser(); - getAccessToken.value = user?.access_token; - authIDP.value = user?.profile.auth_idp; - } catch (error) { - console.error( - "Erreur pendant la récupération des données de l'utilisateur :", - error, - ); - } -}; +const getAccessToken = user?.access_token; +const userAuthIDP = user.profile?.idp; const getIRCGNDetails = async () => { try { const response = await getContactDetails(getAccessToken.value); - IRCGN.fixe = response[0]; - IRCGN.phone = response[1]; + IRCGN.fixe = response.cellphone; + IRCGN.phone = response.phone; console.log("Détails de contact récupérés avec succès :", response); - } catch (error) { - console.error( - "Erreur lors de la récupération des détails de contact :", - error, - ); + } catch (error: any) { + console.log(error.toJSON()); } }; onMounted(async () => { - await getUserData(); - if (authIDP.value === "proxyma") { + if (userAuthIDP.value === "proxyma") { await getIRCGNDetails(); } }); @@ -72,15 +57,15 @@ const currentPhone = computed(() => {

- Contacter un expert de l'IRCGN - Contacter un expert en arme + Contacter un expert en arme

-
+

Sélectionnez votre situation actuelle :

-
+
Basegun ne fournit pas de {
-
+
@@ -165,7 +150,7 @@ const currentPhone = computed(() => {
-
+

Exemple de cas d'urgences :