add_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::User::Current::TaskbarItem::Add, :aggregate_failures, type: :graphql do
  4. context 'when adding a taskbar item for an user' do
  5. let(:mutation) do
  6. <<~MUTATION
  7. mutation userCurrentTaskbarItemAdd($input: UserTaskbarItemInput!) {
  8. userCurrentTaskbarItemAdd(input: $input) {
  9. taskbarItem {
  10. id
  11. key
  12. }
  13. errors {
  14. message
  15. }
  16. }
  17. }
  18. MUTATION
  19. end
  20. let(:input) do
  21. {
  22. key: 'key',
  23. callback: 'TicketZoom',
  24. params: {},
  25. prio: 1,
  26. notify: false,
  27. app: 'desktop'
  28. }
  29. end
  30. def execute_graphql_mutation
  31. gql.execute(mutation, variables: { input: input })
  32. end
  33. context 'when user is not authenticated' do
  34. it 'returns an error' do
  35. execute_graphql_mutation
  36. expect(gql.result.error_message).to eq('Authentication required')
  37. end
  38. end
  39. context 'when user is authenticated', authenticated_as: :agent do
  40. let(:agent) { create(:agent) }
  41. it 'adds a taskbar item' do
  42. expect { execute_graphql_mutation }.to change(Taskbar, :count).by(1)
  43. end
  44. end
  45. end
  46. end