form_updater_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }
  11. QUERY
  12. end
  13. let(:variables) { { formUpdaterId: 'FormUpdater__Updater__Ticket__Create', meta: { formId: '5570fac8-8868-40b7-89e7-1cdabbd954ba' }, data: {}, relationFields: relation_fields } }
  14. let(:relation_fields) do
  15. [
  16. {
  17. name: 'state_id',
  18. relation: 'TicketState',
  19. }
  20. ]
  21. end
  22. let(:expected) do
  23. {
  24. 'state_id' => {
  25. options: Ticket::State.by_category(:viewable_agent_new).reorder(name: :asc).map { |state| { value: state.id, label: state.name } },
  26. rejectNonExistentValues: true,
  27. clearable: true,
  28. disabled: false,
  29. hidden: false,
  30. required: true,
  31. show: true,
  32. },
  33. 'title' => {
  34. disabled: false,
  35. hidden: false,
  36. required: true,
  37. show: true,
  38. }
  39. }
  40. end
  41. before do
  42. gql.execute(query, variables: variables)
  43. end
  44. it 'returns form updater data' do
  45. expect(gql.result.data).to include(expected)
  46. end
  47. end
  48. end