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 0713973 commit 2e22ab9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 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 @@ -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
24 changes: 13 additions & 11 deletions frontend/src/views/GuideContactExpert/ExpertSituation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { mgr } from "@/utils/authentication";
import { getContactDetails } from "@/api/api-client";
const getAccessToken: Ref<string> = ref("");
const authIDP: Ref<string> = ref("");
const userAuthIDP: 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;
userAuthIDP.value = user?.profile.auth_idp;
} catch (error) {
console.error(
"Erreur pendant la récupération des données de l'utilisateur :",
Expand All @@ -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(
Expand All @@ -38,7 +38,7 @@ const getIRCGNDetails = async () => {
onMounted(async () => {
await getUserData();
if (authIDP.value === "proxyma") {
if (userAuthIDP.value === "proxyma") {
await getIRCGNDetails();
}
});
Expand Down Expand Up @@ -72,15 +72,17 @@ 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-if="userAuthIDP === 'cheops'"
>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-if="userAuthIDP === 'cheops'">
<DsfrAlert type="error" title="Avertissement">
Basegun ne fournit pas de
<span class="font-bold"
Expand All @@ -104,7 +106,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 +167,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 2e22ab9

Please sign in to comment.