2021-05-27 17:38:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Onebox::Engine::GithubActionsOnebox do
|
2021-05-27 17:38:42 +08:00
|
|
|
describe "PR check run" do
|
2024-07-11 18:15:48 +08:00
|
|
|
let(:pr_run_uri) { "https://api.github.com/repos/discourse/discourse/pulls/13128" }
|
|
|
|
let(:run_uri) { "https://api.github.com/repos/discourse/discourse/check-runs/2660861130" }
|
2021-05-27 17:38:42 +08:00
|
|
|
|
2024-07-11 18:15:48 +08:00
|
|
|
before do
|
|
|
|
stub_request(:get, pr_run_uri).to_return(
|
2021-05-27 17:38:42 +08:00
|
|
|
status: 200,
|
|
|
|
body: onebox_response("githubactions_pr"),
|
|
|
|
)
|
2023-01-09 19:18:21 +08:00
|
|
|
|
2024-07-11 18:15:48 +08:00
|
|
|
stub_request(:get, run_uri).to_return(
|
2024-07-10 07:39:31 +08:00
|
|
|
status: 200,
|
|
|
|
body: onebox_response("githubactions_pr_run"),
|
|
|
|
)
|
2021-05-27 17:38:42 +08:00
|
|
|
end
|
|
|
|
|
2024-07-11 18:15:48 +08:00
|
|
|
include_context "with engines" do
|
|
|
|
let(:link) do
|
|
|
|
"https://github.com/discourse/discourse/pull/13128/checks?check_run_id=2660861130"
|
|
|
|
end
|
|
|
|
end
|
2021-05-27 17:38:42 +08:00
|
|
|
it_behaves_like "an engine"
|
|
|
|
|
|
|
|
describe "#to_html" do
|
|
|
|
it "includes status" do
|
|
|
|
expect(html).to include("success")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes title" do
|
|
|
|
expect(html).to include("simplify post and topic deletion language")
|
|
|
|
end
|
|
|
|
end
|
2024-07-10 07:39:31 +08:00
|
|
|
|
|
|
|
context "when github_onebox_access_token is configured" do
|
2024-07-15 11:07:36 +08:00
|
|
|
before { SiteSetting.github_onebox_access_tokens = "discourse|github_pat_1234" }
|
2024-07-10 07:39:31 +08:00
|
|
|
|
|
|
|
it "sends it as part of the request" do
|
|
|
|
html
|
2024-07-11 18:15:48 +08:00
|
|
|
expect(WebMock).to have_requested(:get, run_uri).with(
|
2024-07-10 07:39:31 +08:00
|
|
|
headers: {
|
2024-07-15 11:07:36 +08:00
|
|
|
"Authorization" => "Bearer github_pat_1234",
|
2024-07-10 07:39:31 +08:00
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2021-05-27 17:38:42 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "GitHub Actions run" do
|
2024-07-11 18:15:48 +08:00
|
|
|
let(:pr_run_uri) { "https://api.github.com/repos/discourse/discourse/actions/runs/873214216" }
|
2021-05-27 17:38:42 +08:00
|
|
|
|
2024-07-11 18:15:48 +08:00
|
|
|
before do
|
|
|
|
stub_request(:get, pr_run_uri).to_return(
|
2024-07-10 07:39:31 +08:00
|
|
|
status: 200,
|
|
|
|
body: onebox_response("githubactions_actions_run"),
|
|
|
|
)
|
2021-05-27 17:38:42 +08:00
|
|
|
end
|
|
|
|
|
2024-07-11 18:15:48 +08:00
|
|
|
include_context "with engines" do
|
|
|
|
let(:link) { "https://github.com/discourse/discourse/actions/runs/873214216" }
|
|
|
|
end
|
2021-05-27 17:38:42 +08:00
|
|
|
it_behaves_like "an engine"
|
|
|
|
|
|
|
|
describe "#to_html" do
|
|
|
|
it "includes status" do
|
|
|
|
expect(html).to include("success")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes title" do
|
|
|
|
expect(html).to include("Remove deleted_by_author key")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes action name" do
|
|
|
|
expect(html).to include("Linting")
|
|
|
|
end
|
|
|
|
end
|
2024-07-10 07:39:31 +08:00
|
|
|
|
|
|
|
context "when github_onebox_access_token is configured" do
|
2024-07-15 11:07:36 +08:00
|
|
|
before { SiteSetting.github_onebox_access_tokens = "discourse|github_pat_1234" }
|
2024-07-10 07:39:31 +08:00
|
|
|
|
|
|
|
it "sends it as part of the request" do
|
|
|
|
html
|
2024-07-11 18:15:48 +08:00
|
|
|
expect(WebMock).to have_requested(:get, pr_run_uri).with(
|
2024-07-10 07:39:31 +08:00
|
|
|
headers: {
|
2024-07-15 11:07:36 +08:00
|
|
|
"Authorization" => "Bearer github_pat_1234",
|
2024-07-10 07:39:31 +08:00
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2021-05-27 17:38:42 +08:00
|
|
|
end
|
|
|
|
end
|