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 0f2081b commit e8c24c3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 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
45 changes: 15 additions & 30 deletions frontend/src/views/GuideContactExpert/ExpertSituation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,25 @@ 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("");
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();
}
});
Expand Down Expand Up @@ -72,15 +57,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="userAuthIDP === '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="userAuthIDP === '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 +89,7 @@ const currentPhone = computed(() => {
</div>
</div>
</div>
<div v-if="authIDP === 'proxyma'">
<div v-if="userAuthIDP === '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 @@ -165,7 +150,7 @@ const currentPhone = computed(() => {
</DsfrModal>
</Teleport>
</div>
<div v-if="authIDP === 'proxyma'" class="fr-grid-row">
<div v-if="userAuthIDP === '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 e8c24c3

Please sign in to comment.