Skip to content

Commit

Permalink
Adapt the specs related to the reporters
Browse files Browse the repository at this point in the history
Co-authored-by: Rubhan Azeem <rubhan.azeem@suse.com>
  • Loading branch information
saraycp and rubhanazeem committed Jul 15, 2022
1 parent fd76b4e commit 806d822
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/api/spec/models/token/workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
allow(Workflows::YAMLToWorkflowsService).to receive(:new).with(yaml_file: yaml_file, scm_webhook: scm_webhook, token: workflow_token,
workflow_run: workflow_run).and_return(yaml_to_workflows_service)
allow(yaml_to_workflows_service).to receive(:call).and_return(workflows)
allow(ScmInitialStatusReporter).to receive(:new).and_return(proc { true })
allow(SCMStatusReporter).to receive(:new).and_return(proc { true })
end

subject { workflow_token.call(workflow_run: workflow_run, scm_webhook: scm_extractor.call) }
Expand All @@ -100,9 +100,9 @@

it { expect { subject }.to change(workflow_token, :triggered_at) & change(workflow_run, :response_url).to('https://api.github.com') }

it do
it 'sends the initial report twice' do
subject
expect(ScmInitialStatusReporter).to have_received(:new).twice
expect(SCMStatusReporter).to have_received(:new).twice
end
end

Expand Down
14 changes: 11 additions & 3 deletions src/api/spec/services/github_status_reporter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
require 'rails_helper'

RSpec.describe GithubStatusReporter, type: :service do
let(:scm_status_reporter) { GithubStatusReporter.new(event_payload, event_subscription_payload, token, event_type) }
let(:scm_status_reporter) { GithubStatusReporter.new(event_payload, event_subscription_payload, token, state, workflow_run, initial_report: initial_report) }

describe '.new' do
context 'status pending when event_type is missing' do
let(:event_payload) { {} }
let(:event_subscription_payload) { {} }
let(:token) { 'XYCABC' }
let(:event_type) { nil }
let(:state) { 'pending' }
let(:workflow_run) { nil }
let(:initial_report) { false }

subject { scm_status_reporter }

Expand All @@ -20,6 +23,9 @@
let(:event_subscription_payload) { { scm: 'github' } }
let(:token) { 'XYCABC' }
let(:event_type) { 'Event::BuildFail' }
let(:state) { 'failure' }
let(:workflow_run) { nil }
let(:initial_report) { false }

subject { scm_status_reporter }

Expand All @@ -29,7 +35,7 @@

describe '#call' do
context 'when sending a report back to SCM fails' do
let(:scm_status_reporter) { GithubStatusReporter.new(event_payload, event_subscription_payload, token, event_type, workflow_run) }
let(:scm_status_reporter) { GithubStatusReporter.new(event_payload, event_subscription_payload, token, state, workflow_run, initial_report: false) }

let!(:user) { create(:confirmed_user, :with_home, login: 'jane_doe') }
let!(:package) { create(:package, name: 'bye', project: user.home_project) }
Expand All @@ -43,8 +49,8 @@
end

let(:event_subscription_payload) { { scm: 'github' } }

let(:event_type) { 'Event::BuildSuccess' }
let(:state) { 'success' }

let!(:event_subscription) do
EventSubscription.create(channel: 'scm', package: package, eventtype: event_type, receiver_role: 'reader', token: workflow_token, workflow_run: workflow_run)
Expand Down Expand Up @@ -112,6 +118,8 @@
let(:token) { 'XYCABC' }
let(:event_type) { nil }
let(:state) { 'pending' }
let(:workflow_run) { nil }
let(:initial_report) { false }
let(:status_options) do
{
context: 'OBS: hello_world - openSUSE_Tumbleweed/x86_64',
Expand Down
10 changes: 9 additions & 1 deletion src/api/spec/services/gitlab_status_reporter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
require 'rails_helper'

RSpec.describe GitlabStatusReporter, type: :service do
let(:scm_status_reporter) { GitlabStatusReporter.new(event_payload, event_subscription_payload, token, event_type) }
let(:scm_status_reporter) { GitlabStatusReporter.new(event_payload, event_subscription_payload, token, state, workflow_run, initial_report: initial_report) }

describe '.new' do
context 'status pending when event_type is missing' do
let(:event_payload) { {} }
let(:event_subscription_payload) { {} }
let(:token) { 'XYCABC' }
let(:event_type) { nil }
let(:workflow_run) { nil }
let(:state) { 'pending' }
let(:initial_report) { false }

subject { scm_status_reporter }

Expand All @@ -20,6 +23,9 @@
let(:event_subscription_payload) { { scm: 'gitlab' } }
let(:token) { 'XYCABC' }
let(:event_type) { 'Event::BuildFail' }
let(:workflow_run) { nil }
let(:state) { 'failed' }
let(:initial_report) { false }

subject { scm_status_reporter }

Expand All @@ -39,6 +45,8 @@
let(:token) { 'XYCABC' }
let(:event_type) { nil }
let(:state) { 'pending' }
let(:workflow_run) { nil }
let(:initial_report) { false }
let(:status_options) do
{
context: 'OBS: hello_world - openSUSE_Tumbleweed/x86_64',
Expand Down

0 comments on commit 806d822

Please sign in to comment.