# frozen_string_literal: true

require "swagger_helper"

RSpec.describe "Passwords", type: :request do
  let!(:resource) do
    user = FactoryBot.create(:user)
    user.generate_reset_token
    user
  end

  path "/passwords" do
    include_examples "an API create request",
                      factory: :user,
                      resource_name: "Password",
                      summary: "Send a reset password message",
                      parameters: [
                        { name: "email", in: :query, type: :string },
                      ],
                      success_response_code: 204,
                      success_description: "No body returned for response",
                      response_body: false do
                        let(:email) { resource.email }
                      end
  end

  path "/passwords/update" do
    include_examples "an API update request",
                      model: User,
                      summary: "Update a password",
                      tags: "Passwords",
                      parameters: [
                        { name: "reset_token", in: :query, type: :string, description: "A token generated by the back-end to authorize a password reset" },
                        { name: "password", in: :query, type: :string },
                        { name: "password_confirmation", in: :query, type: :string },
                      ] do
                        let(:reset_token) { resource[:reset_password_token] }
                        let(:password) { "manifold" }
                        let(:password_confirmation) { "manifold" }
                      end
  end

  path "/passwords/admin_reset_password" do
    include_examples "an API create request",
                      model: User,
                      tags: "Passwords",
                      parameters: [
                        { name: "id", in: :query, type: :string, description: "the ID of the user who's password you want to reset" },
                      ],
                      success_response_code: 200,
                      authorized_user: :admin do
                        let(:id) { resource.id }
                      end
  end
end
