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 7, 2024
1 parent e232c19 commit 49b808a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 46 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
60 changes: 17 additions & 43 deletions frontend/src/views/GuideContactExpert/ExpertSituation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,14 @@ 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 access_token = ref<string>("");
const idp = ref<string>("");
const getIRCGNDetails = async () => {
try {
const response = await getContactDetails(getAccessToken.value);
IRCGN.fixe = response[0];
IRCGN.phone = response[1];
const response = await getContactDetails(access_token.value);
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(
Expand All @@ -37,16 +23,18 @@ const getIRCGNDetails = async () => {
};
onMounted(async () => {
await getUserData();
if (authIDP.value === "proxyma") {
const user = await mgr.getUser();
access_token.value = user?.access_token;
idp.value = user.profile?.idp;
if (idp.value === "proxyma") {
await getIRCGNDetails();
}
});
const priority = ref("");
const IRCGN = {
email: "db.dcpc.ircgn@gendarmerie.interieur.gouv.fr",
fixe: "",
phone: "",
};
Expand All @@ -72,15 +60,13 @@ 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'"
>Contacter un expert de l'IRCGN</span
>
<span v-if="authIDP === 'cheops'">Contacter un expert en arme</span>
<span v-if="idp === 'proxyma'">Contacter un expert de l'IRCGN</span>
<span v-else>Contacter un expert en arme</span>
</h1>
<div v-if="authIDP === 'proxyma'">
<div v-if="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 +90,7 @@ const currentPhone = computed(() => {
</div>
</div>
</div>
<div v-if="authIDP === 'proxyma'">
<div v-if="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 +125,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="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 49b808a

Please sign in to comment.