Feature: Account deletion
  As a signed-in user
  I want to permanently delete my account
  So that I stay in control of my data

  Background:
    Given I am signed in as "Alice" "Martin"

  Scenario: Shows an error and keeps the session when the password is wrong
    Given the account deletion request will fail because the credentials are invalid
    When I visit "/parametres/compte"
    And I click the button "Supprimer mon compte"
    And I fill in the "deleteAccountPassword" field with "wrong-password"
    And I click the button "Confirmer la suppression"
    Then the account deletion request should have been made
    And I should see "Email ou mot de passe incorrect"
    And the URL should include "/parametres/compte"

  Scenario: Deletes the account and returns to the login page
    Given the account deletion request will succeed
    When I visit "/parametres/compte"
    And I click the button "Supprimer mon compte"
    And I fill in the "deleteAccountPassword" field with "correct-horse-battery-staple"
    And I click the button "Confirmer la suppression"
    Then the account deletion request should have been made with password "correct-horse-battery-staple"
    And the URL should include "/login"

  Scenario: Cancels the deletion without calling the API
    Given the account deletion request is being watched
    When I visit "/parametres/compte"
    And I click the button "Supprimer mon compte"
    And I click the button "Annuler"
    Then I should not see "Confirmer la suppression"
    And the account deletion request should not have been made
