form_updater_spec.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::FormUpdater, authenticated_as: :agent, type: :graphql do
  4. let(:agent) { create(:agent) }
  5. context 'when fetching form updater data' do
  6. let(:query) do
  7. <<~QUERY
  8. query formUpdater($formUpdaterId: EnumFormUpdaterId!, $relationFields: [FormUpdaterRelationField!]!, $meta: FormUpdaterMetaInput!, $data: JSON!, $id: ID) {
  9. formUpdater(formUpdaterId: $formUpdaterId, relationFields: $relationFields, meta: $meta, data: $data, id: $id) {
  10. fields
  11. flags
  12. }
  13. }
  14. QUERY
  15. end
  16. let(:variables) { { formUpdaterId: 'FormUpdater__Updater__Ticket__Create', meta: { formId: '5570fac8-8868-40b7-89e7-1cdabbd954ba' }, data: {}, relationFields: relation_fields } }
  17. let(:relation_fields) do
  18. [
  19. {
  20. name: 'state_id',
  21. relation: 'TicketState',
  22. }
  23. ]
  24. end
  25. let(:expected) do
  26. {
  27. 'fields' => include({
  28. 'state_id' => {
  29. options: Ticket::State.by_category(:viewable_agent_new).reorder(name: :asc).map { |state| { value: state.id, label: state.name } },
  30. rejectNonExistentValues: true,
  31. clearable: true,
  32. disabled: false,
  33. hidden: false,
  34. required: true,
  35. show: true,
  36. },
  37. 'title' => {
  38. disabled: false,
  39. hidden: false,
  40. required: true,
  41. show: true,
  42. }
  43. }),
  44. 'flags' => {}
  45. }
  46. end
  47. before do
  48. gql.execute(query, variables: variables)
  49. end
  50. it 'returns form updater data' do
  51. expect(gql.result.data).to include(expected)
  52. end
  53. end
  54. end