Skip to content

Commit

Permalink
test: ✅ add api test for contact-details endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
nutfdt committed Oct 8, 2024
1 parent 28ebd13 commit bd0feaf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 47 deletions.
16 changes: 13 additions & 3 deletions backend/src/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
13 changes: 13 additions & 0 deletions backend/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
59 changes: 15 additions & 44 deletions frontend/src/views/GuideContactExpert/ExpertSituation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,13 @@ import { DateTime } from "luxon";
import { mgr } from "@/utils/authentication";
import { getContactDetails } from "@/api/api-client";
const getAccessToken: Ref<string> = ref("");
const authIDP: Ref<string> = 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<any>(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 :",
Expand All @@ -37,16 +21,15 @@ const getIRCGNDetails = async () => {
};
onMounted(async () => {
await getUserData();
if (authIDP.value === "proxyma") {
const result = await mgr.getUser();
user.value = result;
if (user.value?.profile?.idp === "proxyma") {
await getIRCGNDetails();
}
});
const priority = ref("");
const IRCGN = {
email: "db.dcpc.ircgn@gendarmerie.interieur.gouv.fr",
fixe: "",
phone: "",
};
Expand All @@ -72,15 +55,15 @@ const currentPhone = computed(() => {
<div class="text-center mt-5 p-3">
<h1>
<VIcon name="ri-arrow-right-line" scale="1.7" />
<span v-if="authIDP === 'proxyma'"
<span v-if="user?.profile?.idp === 'proxyma'"
>Contacter un expert de l'IRCGN</span
>
<span v-if="authIDP === 'cheops'">Contacter un expert en arme</span>
<span v-else>Contacter un expert en arme</span>
</h1>
<div v-if="authIDP === 'proxyma'">
<div v-if="user?.profile?.idp === 'proxyma'">
<p>Sélectionnez votre situation actuelle :</p>
</div>
<div v-if="authIDP === 'cheops'">
<div v-else>
<DsfrAlert type="error" title="Avertissement">
Basegun ne fournit pas de
<span class="font-bold"
Expand All @@ -104,7 +87,7 @@ const currentPhone = computed(() => {
</div>
</div>
</div>
<div v-if="authIDP === 'proxyma'">
<div v-if="user?.profile?.idp === 'proxyma'">
<div class="fr-grid-row">
<div class="fr-col-12 fr-col-lg-6 mx-auto">
<div class="fr-grid-row">
Expand Down Expand Up @@ -139,33 +122,21 @@ const currentPhone = computed(() => {
permanence de l'IRCGN.<br /><br />
<span class="font-bold">{{ currentPhone }}</span>
</p>
<p v-if="priority === 'low'">
Veuilez cliquer sur l'adresse mail ci-dessous pour envoyer un
mail pré-rempli à l'IRCGN : <br /><br />
<span class="font-bold"
><a :href="buildMailto(IRCGN.email)">{{
IRCGN.email
}}</a></span
>
</p>
</div>
<div class="fr-col-11 fr-col-lg-6 footer-actions mx-auto">
<DsfrButton
class="m-1 flex justify-center"
icon="ri-arrow-left-line"
label="Précédent"
@click="
showIRCGNModal = false;
priority = '';
"
@click="showIRCGNModal = false"
/>
</div>
</div>
</div>
</DsfrModal>
</Teleport>
</div>
<div v-if="authIDP === 'proxyma'" class="fr-grid-row">
<div v-if="user?.profile?.idp === 'proxyma'" class="fr-grid-row">
<div class="fr-col text-center">
<div class="bg-purple p-8 fr-my-8w">
<p>Exemple de cas d'urgences :</p>
Expand Down

0 comments on commit bd0feaf

Please sign in to comment.