gitlab_spec.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. require 'rails_helper'
  2. RSpec.describe GitLab, type: :integration do # rubocop:disable RSpec/FilePath
  3. before(:all) do # rubocop:disable RSpec/BeforeAfterAll
  4. required_envs = %w[GITLAB_ENDPOINT GITLAB_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['GITLAB_ENDPOINT'], ENV['GITLAB_APITOKEN']) }
  10. let(:issue_data) do
  11. {
  12. id: '1',
  13. title: 'Example issue',
  14. url: ENV['GITLAB_ISSUE_LINK'],
  15. icon_state: 'open',
  16. milestone: 'important milestone',
  17. assignees: ['zammad-robot'],
  18. labels: [
  19. {
  20. color: '#FF0000',
  21. text_color: '#FFFFFF',
  22. title: 'critical'
  23. },
  24. {
  25. color: '#0033CC',
  26. text_color: '#FFFFFF',
  27. title: 'label1'
  28. },
  29. {
  30. color: '#D1D100',
  31. text_color: '#FFFFFF',
  32. title: 'special'
  33. }
  34. ],
  35. }
  36. end
  37. let(:invalid_issue_url) { "https://#{URI.parse(ENV['GITLAB_ISSUE_LINK']).host}/group/project/-/issues/1" }
  38. describe '#issues_by_urls' do
  39. let(:result) { instance.issues_by_urls([ issue_url ]) }
  40. context 'when issue exists' do
  41. let(:issue_url) { ENV['GITLAB_ISSUE_LINK'] }
  42. it 'returns a result list' do
  43. expect(result.size).to eq(1)
  44. end
  45. it 'returns issue data in the result list' do
  46. expect(result[0]).to eq(issue_data)
  47. end
  48. end
  49. context 'when issue does not exists' do
  50. let(:issue_url) { invalid_issue_url }
  51. it 'returns no result' do
  52. expect(result.size).to eq(0)
  53. end
  54. end
  55. end
  56. describe '#issue_by_url' do
  57. let(:result) { instance.issue_by_url(issue_url) }
  58. context 'when issue exists' do
  59. let(:issue_url) { ENV['GITLAB_ISSUE_LINK'] }
  60. it 'returns issue data' do
  61. expect(result).to eq(issue_data)
  62. end
  63. end
  64. context 'when issue does not exists' do
  65. let(:issue_url) { invalid_issue_url }
  66. it 'returns nil' do
  67. expect(result).to be_nil
  68. end
  69. end
  70. end
  71. end