update_spec.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::User::Current::TaskbarItem::Update, type: :graphql do
  4. context 'when updating a taskbar item for the logged-in user', authenticated_as: :agent do
  5. let(:agent) { create(:agent) }
  6. let(:variables) { { id: id, input: input } }
  7. let(:execute_query) { true }
  8. let(:taskbar_item) { create(:taskbar, user_id: agent.id) }
  9. let(:input) do
  10. {
  11. key: 'key',
  12. callback: 'TicketZoom',
  13. params: {},
  14. prio: 1,
  15. notify: false,
  16. app: 'desktop'
  17. }
  18. end
  19. let(:id) { gql.id(taskbar_item) }
  20. let(:query) do
  21. <<~QUERY
  22. mutation userCurrentTaskbarItemUpdate($id: ID!, $input: UserTaskbarItemInput!) {
  23. userCurrentTaskbarItemUpdate(id: $id, input: $input) {
  24. taskbarItem {
  25. app
  26. key
  27. }
  28. errors {
  29. message
  30. field
  31. }
  32. }
  33. }
  34. QUERY
  35. end
  36. before do
  37. next if !execute_query
  38. gql.execute(query, variables: variables)
  39. end
  40. context 'with existing taskbar item', :aggregate_failures do
  41. it 'returns the updated taskbar item' do
  42. expect(taskbar_item.reload.key).to eq('key')
  43. expect(gql.result.data[:taskbarItem]).to eq(
  44. { 'app' => 'desktop', 'key' => 'key' }
  45. )
  46. end
  47. end
  48. context 'with not existing taskbar item' do
  49. let(:id) { Gql::ZammadSchema.id_from_internal_id(Taskbar, Faker::Number.unique.number) }
  50. it 'fails with error' do
  51. expect(gql.result.error_type).to eq(ActiveRecord::RecordNotFound)
  52. end
  53. end
  54. it_behaves_like 'graphql responds with error if unauthenticated'
  55. end
  56. end