password_check_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::User::Current::PasswordCheck, type: :graphql do
  4. let(:user) { create(:agent, password: 'lorem') }
  5. let(:password) { 'lorem' }
  6. let(:mutation) do
  7. <<~GQL
  8. mutation userCurrentPasswordCheck($password: String!) {
  9. userCurrentPasswordCheck(password: $password) {
  10. success
  11. token
  12. errors {
  13. message
  14. field
  15. }
  16. }
  17. }
  18. GQL
  19. end
  20. let(:variables) { { password: } }
  21. before { gql.execute(mutation, variables: variables) }
  22. context 'when user is not authenticated' do
  23. it 'returns an error' do
  24. expect(gql.result.error).to include('message' => 'Authentication required')
  25. end
  26. end
  27. context 'when user is authenticated', authenticated_as: :user do
  28. context 'when password is correct' do
  29. it 'returns true for success and includes a token' do
  30. expect(gql.result.data).to include('success' => true, 'token' => be_a(String))
  31. end
  32. end
  33. context 'when password is not correct' do
  34. let(:password) { '' }
  35. it 'returns an error' do
  36. expect(gql.result.data[:errors])
  37. .to include(
  38. include('field' => 'password', 'message' => 'The provided password is incorrect.')
  39. )
  40. end
  41. end
  42. end
  43. end