edit_spec.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'models/form_updater/concerns/checks_core_workflow_examples'
  4. RSpec.describe(FormUpdater::Updater::User::Edit) do
  5. subject(:resolved_result) do
  6. described_class.new(
  7. context: context,
  8. relation_fields: relation_fields,
  9. meta: meta,
  10. data: data,
  11. id: Gql::ZammadSchema.id_from_object(edit_user)
  12. )
  13. end
  14. let(:user) { create(:agent) }
  15. let(:context) { { current_user: user } }
  16. let(:meta) { { initial: true, form_id: SecureRandom.uuid } }
  17. let(:data) { {} }
  18. let(:organization) { create(:organization) }
  19. let(:secondary_organizations) { create_list(:organization, 5) }
  20. let(:edit_user) { create(:user, organization_id: organization.id, organization_ids: secondary_organizations.map(&:id)) }
  21. let(:relation_fields) { [] }
  22. context 'when resolving' do
  23. it 'has permission on the object' do
  24. expect(resolved_result.authorized?).to be true
  25. end
  26. it 'returns secondary organization options for current object in initial request' do
  27. # Triggers the object initialization from the id.
  28. resolved_result.authorized?
  29. expect(resolved_result.resolve[:fields]).to include(
  30. 'organization_ids' => include({
  31. initialValue: secondary_organizations.map(&:id),
  32. options: secondary_organizations.each_with_object([]) do |organization, options|
  33. options << {
  34. value: organization.id,
  35. label: organization.name,
  36. organization: {
  37. active: organization.active,
  38. }
  39. }
  40. end
  41. }),
  42. )
  43. end
  44. end
  45. include_examples 'FormUpdater::ChecksCoreWorkflow', object_name: 'User'
  46. end