github_spec.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe GitHub, integration: true, required_envs: %w[GITHUB_ENDPOINT GITHUB_APITOKEN] do
  4. let(:instance) { described_class.new(ENV['GITHUB_ENDPOINT'], ENV['GITHUB_APITOKEN']) }
  5. let(:issue_data) do
  6. {
  7. id: '1575',
  8. title: 'GitHub integration',
  9. url: ENV['GITHUB_ISSUE_LINK'],
  10. icon_state: 'closed',
  11. milestone: '4.0',
  12. assignees: ['Thorsten'],
  13. labels: [
  14. {
  15. color: '#84b6eb',
  16. text_color: '#000000',
  17. title: 'enhancement'
  18. },
  19. {
  20. color: '#bfdadc',
  21. text_color: '#000000',
  22. title: 'integration'
  23. }
  24. ],
  25. }
  26. end
  27. let(:invalid_issue_url) { 'https://github.com/organization/repository/issues/42' }
  28. describe '#issues_by_urls' do
  29. let(:result) { instance.issues_by_urls([ issue_url ]) }
  30. context 'when issue exists' do
  31. let(:issue_url) { ENV['GITHUB_ISSUE_LINK'] }
  32. it 'returns a result list' do
  33. expect(result.size).to eq(1)
  34. end
  35. it 'returns issue data in the result list' do
  36. expect(result[0]).to eq(issue_data)
  37. end
  38. end
  39. context 'when issue does not exists' do
  40. let(:issue_url) { invalid_issue_url }
  41. it 'returns no result' do
  42. expect(result.size).to eq(0)
  43. end
  44. end
  45. end
  46. describe '#issue_by_url' do
  47. let(:result) { instance.issue_by_url(issue_url) }
  48. context 'when issue exists' do
  49. let(:issue_url) { ENV['GITHUB_ISSUE_LINK'] }
  50. it 'returns issue data' do
  51. expect(result).to eq(issue_data)
  52. end
  53. end
  54. context 'when issue does not exists' do
  55. let(:issue_url) { invalid_issue_url }
  56. it 'returns nil' do
  57. expect(result).to be_nil
  58. end
  59. end
  60. end
  61. end