api_error_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe MicrosoftGraph::ApiError do
  4. subject(:instance) { described_class.new(error_hash) }
  5. let(:error_hash) do
  6. {
  7. code: 'badRequest',
  8. message: 'Uploaded fragment overlaps with existing data.',
  9. innerError: {
  10. code: 'invalidRange',
  11. 'request-id': 'request-id',
  12. date: 'date-time'
  13. }
  14. }
  15. end
  16. describe '#message' do
  17. context 'with full error hash' do
  18. it 'generates correct message' do
  19. expect(instance.message).to eq("Uploaded fragment overlaps with existing data. (badRequest)\nMicrosoft Graph API Request ID: request-id")
  20. end
  21. end
  22. context 'with incomplete error hash' do
  23. let(:error_hash) do
  24. {
  25. message: 'Uploaded fragment overlaps with existing data.',
  26. }
  27. end
  28. it 'generates correct message' do
  29. expect(instance.message).to eq('Uploaded fragment overlaps with existing data. (no error code present)')
  30. end
  31. end
  32. context 'without error hash' do
  33. let(:error_hash) { {} }
  34. it 'generates correct message' do
  35. expect(instance.message).to eq('An unknown error occurred. (no error code present)')
  36. end
  37. end
  38. end
  39. describe '#inspect' do
  40. it 'generates a correct object representation' do
  41. expect(instance.inspect).to eq('#<MicrosoftGraph::ApiError: "Uploaded fragment overlaps with existing data. (badRequest)\\nMicrosoft Graph API Request ID: request-id">')
  42. end
  43. end
  44. end