password_check_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2024 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. errors {
  12. message
  13. field
  14. }
  15. }
  16. }
  17. GQL
  18. end
  19. let(:variables) { { password: } }
  20. before { gql.execute(mutation, variables: variables) }
  21. context 'when user is not authenticated' do
  22. it 'returns an error' do
  23. expect(gql.result.error).to include('message' => 'Authentication required')
  24. end
  25. end
  26. context 'when user is authenticated', authenticated_as: :user do
  27. context 'when password is correct' do
  28. it 'returns success' do
  29. expect(gql.result.data).to include('success' => be_truthy)
  30. end
  31. end
  32. context 'when password is not correct' do
  33. let(:password) { '' }
  34. it 'returns an error' do
  35. expect(gql.result.data['errors'])
  36. .to include(
  37. include('field' => 'password', 'message' => 'The provided password is incorrect.')
  38. )
  39. end
  40. end
  41. end
  42. end