github_spec.rb 2.2 KB

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