From 75582cb84cf46a007eb567eb55f43bfd97ff3175 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 | 22 ++++++- backend/tests/test_api.py | 13 ++++ .../GuideContactExpert/ExpertSituation.vue | 60 +++++-------------- 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/backend/src/router.py b/backend/src/router.py index 64374a887..e71204da3 100644 --- a/backend/src/router.py +++ b/backend/src/router.py @@ -17,12 +17,19 @@ Request, Response, UploadFile, + status, ) 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 +44,20 @@ 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 + if current_user.get("idp") != "proxyma": + raise HTTPException( + status_code=status.HTTP_403_FORBIDDEN, + detail="Access forbidden: Invalid idp", + ) + 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..3e4f82b4d 100644 --- a/frontend/src/views/GuideContactExpert/ExpertSituation.vue +++ b/frontend/src/views/GuideContactExpert/ExpertSituation.vue @@ -5,29 +5,13 @@ import { DateTime } from "luxon"; import { mgr } from "@/utils/authentication"; import { getContactDetails } from "@/api/api-client"; -const getAccessToken: Ref = ref(""); -const authIDP: 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; - } catch (error) { - console.error( - "Erreur pendant la récupération des données de l'utilisateur :", - error, - ); - } -}; +const user = ref(null); const getIRCGNDetails = async () => { try { - const response = await getContactDetails(getAccessToken.value); - IRCGN.fixe = response[0]; - IRCGN.phone = response[1]; - console.log("Détails de contact récupérés avec succès :", response); + const response = await getContactDetails(user.value?.access_token); + IRCGN.fixe = response.cellphone; + IRCGN.phone = response.phone; } catch (error) { console.error( "Erreur lors de la récupération des détails de contact :", @@ -37,16 +21,12 @@ const getIRCGNDetails = async () => { }; onMounted(async () => { - await getUserData(); - if (authIDP.value === "proxyma") { - await getIRCGNDetails(); - } -}); + user.value = await mgr.getUser(); -const priority = ref(""); + await getIRCGNDetails(); +}); const IRCGN = { - email: "db.dcpc.ircgn@gendarmerie.interieur.gouv.fr", fixe: "", phone: "", }; @@ -72,15 +52,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 {
-
+
@@ -139,25 +119,13 @@ const currentPhone = computed(() => { permanence de l'IRCGN.

{{ currentPhone }}

-

- Veuilez cliquer sur l'adresse mail ci-dessous pour envoyer un - mail pré-rempli à l'IRCGN :

- {{ - IRCGN.email - }} -

@@ -165,7 +133,7 @@ const currentPhone = computed(() => {
-
+

Exemple de cas d'urgences :