Skip to content

Commit

Permalink
test: ✅ add e2e and api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nutfdt committed Aug 30, 2024
1 parent 136dab6 commit d29b3ae
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 11 deletions.
Binary file added backend/tests/blank_gun.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/tests/low_quality.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/tests/no_text.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions backend/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,41 @@ def test_403(self):
response = client.post("/api/expert-contact")
response.data = response.json()
assert response.status_code == 403


class TestBlankGunUpload:
def test_blank_gun(self):
with open("./tests/blank_gun.jpg", "rb") as f:
response = client.post(
"/api/identification-blank-gun",
files={"image": f},
)
response.data = response.json()
assert response.status_code == 200
assert response.data["alarm_model"] == "Alarm_model"
assert response.data["missing_text"] == False
assert response.data["low_quality"] == False

def test_bad_quality(self):
with open("./tests/low_quality.jpg", "rb") as f:
response = client.post(
"/api/identification-blank-gun",
files={"image": f},
)
response.data = response.json()
assert response.status_code == 200
assert response.data["alarm_model"] == None
assert response.data["missing_text"] == False
assert response.data["low_quality"] == True

def test_missing_text(self):
with open("./tests/no_text.jpg", "rb") as f:
response = client.post(
"/api/identification-blank-gun",
files={"image": f},
)
response.data = response.json()
assert response.status_code == 200
assert response.data["alarm_model"] == None
assert response.data["missing_text"] == True
assert response.data["low_quality"] == False
1 change: 1 addition & 0 deletions frontend/cypress/e2e/firearm-confidence.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe("Firearm Confidence", () => {
});
cy.getByDataTestid("next-step").click();
cy.IdentificationPistoletSemiAuto();
cy.wait(5000);
cy.url().should("contain", "/guide-identification/resultat-final");
cy.getByDataTestid("arm-category").should("contain", "Catégorie B");
});
Expand Down
1 change: 1 addition & 0 deletions frontend/cypress/e2e/firearm-identification.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe("Firearm Identification", () => {
});
cy.getByDataTestid("next-step").click();
cy.IdentificationPistoletSemiAuto();
cy.wait(5000);
cy.url().should("contain", "/guide-identification/resultat-final");
cy.getByDataTestid("arm-category").should("contain", "Catégorie B");
cy.getByDataTestid("return-to-home-end").click();
Expand Down
1 change: 1 addition & 0 deletions frontend/cypress/e2e/firearm-securing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("Securing Firearm and Identification", () => {
cy.contains("p", "Basegun a identifié votre arme");
cy.getByDataTestid("next-step").click();
cy.IdentificationPistoletSemiAuto();
cy.wait(5000);
cy.url().should("contain", "/guide-identification/resultat-final");
cy.getByDataTestid("arm-category").should("contain", "Catégorie B");
cy.getByDataTestid("return-to-home-end").click();
Expand Down
15 changes: 5 additions & 10 deletions frontend/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ Cypress.Commands.add("IdentificationPistoletSemiAuto", () => {
cy.contains("Cartouches").first().click();
cy.getByDataTestid("next-step").should("not.have.attr", "disabled");
cy.getByDataTestid("next-step").click();
cy.url().should("contain", "/guide-identification/armes-alarme");
cy.getByDataTestid("instruction-armeAlarme").should("contain", "Votre arme");
cy.getByDataTestid("next-step").click();
cy.getByDataTestid("aucune-correspondance").click();
cy.getByDataTestid("next-step").click();
cy.url().should("contain", "/guide-identification/qualite-image");
cy.getByDataTestid("title-page").should("contain", "Identification d'une arme d'alarme");
});

Cypress.Commands.add("IdentificationRevolver", () => {
Expand All @@ -133,11 +130,9 @@ Cypress.Commands.add("IdentificationRevolver", () => {
cy.contains("Balles").first().click();
cy.getByDataTestid("next-step").should("not.have.attr", "disabled");
cy.getByDataTestid("next-step").click();
cy.url().should("contain", "/guide-identification/armes-alarme");
cy.getByDataTestid("instruction-armeAlarme").should("contain", "Votre arme");
cy.getByDataTestid("next-step").click();
cy.getByDataTestid("aucune-correspondance").click();
cy.getByDataTestid("next-step").click();
cy.url().should("contain", "/guide-identification/qualite-image");
cy.getByDataTestid("title-page").should("contain", "Marquages non détéctés");
cy.getByDataTestid("button-resultPage").click();
});

Cypress.Commands.add("arrierePlatRevolver", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ watch(alarmModel, (newVal) => {
:icon-right="true"
icon="ri-checkbox-circle-line"
secondary
data-testid="button-resultPage"
@click="
currentStep++;
goToNewRouteWithArmeAlarme();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const alert = computed(() => {
</script>
<template>
<h2 class="fr-mt-3w flex justify-center titlePage">
<span> {{ title }}</span>
<span data-testid="title-page"> {{ title }}</span>
</h2>

<div class="fr-p-1w">
Expand Down

0 comments on commit d29b3ae

Please sign in to comment.