unlock_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::System::Setup::Unlock, :aggregate_failures, type: :graphql do
  4. context 'when unlocking system setup' do
  5. let(:mutation) do
  6. <<~MUTATION
  7. mutation systemSetupUnlock($value: String!) {
  8. systemSetupUnlock(value: $value) {
  9. success
  10. errors {
  11. message
  12. field
  13. }
  14. }
  15. }
  16. MUTATION
  17. end
  18. let(:resource) { 'Zammad::System::Setup' }
  19. let(:value) { SecureRandom.uuid }
  20. let(:lock_info) { { resource: resource, value: value } }
  21. let(:variables) { { value: value } }
  22. it 'returns success true' do
  23. allow_any_instance_of(Redlock::Client).to receive(:locked?).with(resource).and_return(true)
  24. allow_any_instance_of(Redlock::Client).to receive(:unlock).with(lock_info).and_return(1)
  25. gql.execute(mutation, variables: variables)
  26. expect(gql.result.data).to include({ 'success' => true })
  27. end
  28. context 'when system setup is not locked' do
  29. it 'returns success false' do
  30. allow_any_instance_of(Redlock::Client).to receive(:locked?).with(resource).and_return(false)
  31. gql.execute(mutation, variables: variables)
  32. expect(gql.result.data).to include({ 'success' => false })
  33. end
  34. end
  35. end
  36. end