2021-05-26 05:41:35 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Onebox::Engine::GithubPullRequestOnebox do
|
2021-05-26 05:41:35 -04:00
|
|
|
before do
|
|
|
|
@link = "https://github.com/discourse/discourse/pull/1253/"
|
|
|
|
@uri = "https://api.github.com/repos/discourse/discourse/pulls/1253"
|
|
|
|
|
|
|
|
stub_request(:get, @uri).to_return(status: 200, body: onebox_response(described_class.onebox_name))
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
include_context "with engines"
|
2021-05-26 05:41:35 -04:00
|
|
|
it_behaves_like "an engine"
|
|
|
|
|
|
|
|
describe "#to_html" do
|
|
|
|
it "includes pull request author" do
|
|
|
|
expect(html).to include("jamesaanderson")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes repository name" do
|
|
|
|
expect(html).to include("discourse")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes commit author gravatar" do
|
|
|
|
expect(html).to include("b3e9977094ce189bbb493cf7f9adea21")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes commit time and date" do
|
|
|
|
expect(html).to include("02:05AM - 26 Jul 13")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes number of commits" do
|
|
|
|
expect(html).to include("1")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes number of files changed" do
|
|
|
|
expect(html).to include("4")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes number of additions" do
|
|
|
|
expect(html).to include("19")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes number of deletions" do
|
|
|
|
expect(html).to include("1")
|
|
|
|
end
|
|
|
|
|
2021-05-27 05:38:42 -04:00
|
|
|
it "includes the body without comments" do
|
2021-05-26 05:41:35 -04:00
|
|
|
expect(html).to include("http://meta.discourse.org/t/audio-html5-tag/8168")
|
2021-05-27 05:38:42 -04:00
|
|
|
expect(html).not_to include("test comment")
|
2021-05-26 05:41:35 -04:00
|
|
|
end
|
|
|
|
end
|
2022-10-06 13:26:04 -04:00
|
|
|
|
|
|
|
context "with commit links" do
|
|
|
|
before do
|
|
|
|
@link = "https://github.com/discourse/discourse/pull/1253/commits/d7d3be1130c665cc7fab9f05dbf32335229137a6"
|
|
|
|
@uri = "https://api.github.com/repos/discourse/discourse/commits/d7d3be1130c665cc7fab9f05dbf32335229137a6"
|
|
|
|
|
|
|
|
stub_request(:get, @uri).to_return(status: 200, body: onebox_response(described_class.onebox_name + "_commit"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes commit name" do
|
2022-10-24 15:26:48 -04:00
|
|
|
doc = Nokogiri::HTML5(html)
|
|
|
|
expect(doc.css('h4').text.strip).to eq("Add audio onebox")
|
|
|
|
expect(doc.css('.github-body-container').text).to include("http://meta.discourse.org/t/audio-html5-tag/8168")
|
2022-10-06 13:26:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with comment links" do
|
|
|
|
before do
|
|
|
|
@link = "https://github.com/discourse/discourse/pull/1253/#issuecomment-21597425"
|
|
|
|
@uri = "https://api.github.com/repos/discourse/discourse/issues/comments/21597425"
|
|
|
|
|
|
|
|
stub_request(:get, @uri).to_return(status: 200, body: onebox_response(described_class.onebox_name + "_comment"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes comment" do
|
|
|
|
expect(html).to include("You've signed the CLA")
|
|
|
|
end
|
|
|
|
end
|
2021-05-26 05:41:35 -04:00
|
|
|
end
|