github_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. require 'rails_helper'
  2. RSpec.describe GitHub, type: :integration do # rubocop:disable RSpec/FilePath
  3. before(:all) do # rubocop:disable RSpec/BeforeAfterAll
  4. required_envs = %w[GITHUB_ENDPOINT GITHUB_APITOKEN]
  5. required_envs.each do |key|
  6. skip("NOTICE: Missing environment variable #{key} for test! (Please fill up: #{required_envs.join(' && ')})") if ENV[key].blank?
  7. end
  8. end
  9. let(:instance) { described_class.new(ENV['GITHUB_ENDPOINT'], ENV['GITHUB_APITOKEN']) }
  10. let(:issue_data) do
  11. {
  12. id: '1575',
  13. title: 'GitHub integration',
  14. url: ENV['GITHUB_ISSUE_LINK'],
  15. icon_state: 'closed',
  16. milestone: '4.0',
  17. assignees: ['Thorsten'],
  18. labels: [
  19. {
  20. color: '#fef2c0',
  21. text_color: '#000000',
  22. title: 'feature backlog'
  23. },
  24. {
  25. color: '#bfdadc',
  26. text_color: '#000000',
  27. title: 'integration'
  28. }
  29. ],
  30. }
  31. end
  32. let(:invalid_issue_url) { 'https://github.com/organization/repository/issues/42' }
  33. describe '#issues_by_urls' do
  34. let(:result) { instance.issues_by_urls([ issue_url ]) }
  35. context 'when issue exists' do
  36. let(:issue_url) { ENV['GITHUB_ISSUE_LINK'] }
  37. it 'returns a result list' do
  38. expect(result.size).to eq(1)
  39. end
  40. it 'returns issue data in the result list' do
  41. expect(result[0]).to eq(issue_data)
  42. end
  43. end
  44. context 'when issue does not exists' do
  45. let(:issue_url) { invalid_issue_url }
  46. it 'returns no result' do
  47. expect(result.size).to eq(0)
  48. end
  49. end
  50. end
  51. describe '#issue_by_url' do
  52. let(:result) { instance.issue_by_url(issue_url) }
  53. context 'when issue exists' do
  54. let(:issue_url) { ENV['GITHUB_ISSUE_LINK'] }
  55. it 'returns issue data' do
  56. expect(result).to eq(issue_data)
  57. end
  58. end
  59. context 'when issue does not exists' do
  60. let(:issue_url) { invalid_issue_url }
  61. it 'returns nil' do
  62. expect(result).to be_nil
  63. end
  64. end
  65. end
  66. end