invite_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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::Invite do
  5. subject(:form_updater) do
  6. described_class.new(
  7. context: context,
  8. meta: meta,
  9. data: data,
  10. relation_fields: [],
  11. )
  12. end
  13. let(:user) { create(:admin) }
  14. let(:context) { { current_user: user } }
  15. let(:meta) { { initial: true, form_id: SecureRandom.uuid } }
  16. let(:data) { {} }
  17. describe '#resolve' do
  18. it 'includes roles and preselects Agent role' do
  19. expect(form_updater.resolve[:fields]).to include(
  20. 'role_ids' => include(
  21. options: eq(
  22. Role.reorder(:id).map do |elem|
  23. {
  24. value: elem.id,
  25. label: elem.name,
  26. description: elem.note,
  27. }
  28. end
  29. )
  30. )
  31. )
  32. end
  33. it 'includes groups' do
  34. parent_group = Group.first
  35. children_group = create(:group, parent: parent_group)
  36. expect(form_updater.resolve[:fields]).to include(
  37. 'group_ids' => include(
  38. options: include(
  39. include(
  40. value: parent_group.id,
  41. label: parent_group.name_last,
  42. children: include(
  43. include(
  44. value: children_group.id,
  45. label: children_group.name_last,
  46. )
  47. )
  48. )
  49. )
  50. )
  51. )
  52. end
  53. end
  54. describe 'CoreWorkflow' do
  55. let(:resolved_result) { form_updater }
  56. include_examples 'FormUpdater::ChecksCoreWorkflow', object_name: 'User'
  57. end
  58. end