github_spec.rb 1.9 KB

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