Skip to content

Commit

Permalink
Add spec for Token::Workflow restore and destroy scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
vpereira authored and Dany Marcoux committed Sep 13, 2021
1 parent bf311f7 commit 72a7b57
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/api/spec/models/token/workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,46 @@
RSpec.describe Token::Workflow, vcr: true do
let(:token_user) { create(:confirmed_user, :with_home, login: 'Iggy') }
let(:workflow_token) { create(:workflow_token, user: token_user) }
let(:github_payload_closed) do
{
action: 'closed',
pull_request: {
head: {
repo: {
full_name: 'username/test_repo'
}
},
base: {
ref: 'main'
}
},
number: 4,
sender: {
url: 'https://api.github.com'
}
}
end

let(:github_payload_reopened) do
{
action: 'reopened',
pull_request: {
head: {
repo: {
full_name: 'username/test_repo'
}
},
base: {
ref: 'main'
}
},
number: 4,
sender: {
url: 'https://api.github.com'
}
}
end

let(:github_payload) do
{
action: 'opened',
Expand Down Expand Up @@ -72,6 +112,40 @@
end

describe '#call' do
context 'PR was reopened' do
let(:scm) { 'github' }
let(:event) { 'pull_request' }
let(:payload) { github_payload_reopened }
let(:workflows_yml_file) { File.expand_path(Rails.root.join('spec/support/files/workflows.yml')) }
let(:downloader) { instance_double(Workflows::YAMLDownloader) }

before do
allow(Workflows::YAMLDownloader).to receive(:new).and_return(downloader)
allow(downloader).to receive(:call).and_return(workflows_yml_file)
allow(Project).to receive(:restore)
subject
end

it { expect(Project).to have_received(:restore) }
end

context 'PR was closed' do
let(:scm) { 'github' }
let(:event) { 'pull_request' }
let(:payload) { github_payload_closed }
let(:workflows_yml_file) { File.expand_path(Rails.root.join('spec/support/files/workflows.yml')) }
let(:downloader) { instance_double(Workflows::YAMLDownloader) }

before do
allow(Workflows::YAMLDownloader).to receive(:new).and_return(downloader)
allow(downloader).to receive(:call).and_return(workflows_yml_file)
allow(workflow_token).to receive(:destroy_all_target_projects)
subject
end

it { expect(workflow_token).to have_received(:destroy_all_target_projects) }
end

context "when the webhook's event is not the expected one" do
context 'when the SCM is GitHub' do
it_behaves_like 'not-allowed event or action' do
Expand Down

0 comments on commit 72a7b57

Please sign in to comment.