From 2e22ab92b505c03e394553fe50e0d0fcf07ee225 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 | 24 ++++++++++--------- 3 files changed, 39 insertions(+), 14 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 11b25701c..f609322b2 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -186,3 +186,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..39ca5b5ce 100644 --- a/frontend/src/views/GuideContactExpert/ExpertSituation.vue +++ b/frontend/src/views/GuideContactExpert/ExpertSituation.vue @@ -6,14 +6,14 @@ import { mgr } from "@/utils/authentication"; import { getContactDetails } from "@/api/api-client"; const getAccessToken: Ref = ref(""); -const authIDP: Ref = ref(""); +const userAuthIDP: Ref = ref(""); // 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; + userAuthIDP.value = user?.profile.auth_idp; } catch (error) { console.error( "Erreur pendant la récupération des données de l'utilisateur :", @@ -25,8 +25,8 @@ const getUserData = async () => { 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( @@ -38,7 +38,7 @@ const getIRCGNDetails = async () => { onMounted(async () => { await getUserData(); - if (authIDP.value === "proxyma") { + if (userAuthIDP.value === "proxyma") { await getIRCGNDetails(); } }); @@ -72,15 +72,17 @@ 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 +167,7 @@ const currentPhone = computed(() => {
-
+

Exemple de cas d'urgences :