spec/unit/lita/handlers/github_pr_spec.rb in lita-github-0.0.5 vs spec/unit/lita/handlers/github_pr_spec.rb in lita-github-0.0.6

- old
+ new

@@ -364,10 +364,20 @@ expect(github_pr).to receive(:build_pr_comments!).with({}, pr_obj).and_return(nil) github_pr.send(:build_pr_info, pr_obj, full_name) end end + describe '.list_line' do + let(:pr) { { title: 'Test', number: 42, html_url: 'nothtml' } } + let(:full_name) { 'GrapeDuty/lita-test' } + + it 'should return a PR header' do + l = github_pr.send(:list_line, pr, full_name) + expect(l).to eql "GrapeDuty/lita-test #42: Test :: nothtml\n" + end + end + #### # Handlers #### describe '.merge_pr' do before do @@ -544,9 +554,100 @@ expect(replies.last) .to eql( 'An unexpected exception was hit during the GitHub API operation. Please make sure all ' \ 'arguments are proper and try again, or try checking the GitHub status (gh status)' ) + end + end + end + + describe '.pr_list' do + before do + cfg_obj = double('Lita::Configuration') + octo_obj = double('Octokit::Client', pull_requests: []) + allow(github_pr).to receive(:octo).and_return(octo_obj) + allow(github_pr).to receive(:config).and_return(cfg_obj) + end + + context 'when there are no pull requests' do + it 'should state that there are no pull requests' do + send_command("gh pr list #{github_org}/#{github_repo}") + expect(replies.last).to eql 'This repo has no open pull requests; good job!' + end + end + + context 'when there are less than 20 prs' do + before do + pr = [ + { title: 'Test2', number: 84, html_url: 'nohtmlurl' }, + { title: 'Test1', number: 42, html_url: 'htmlurl' } + ] + octo_obj = double('Octokit::Client', pull_requests: pr) + allow(github_pr).to receive(:octo).and_return(octo_obj) + end + + it 'should reply with the PRs' do + send_command("gh pr list #{github_org}/#{github_repo}") + expect(replies.last).to eql "GrapeDuty/lita-test #84: Test2 :: nohtmlurl\n" \ + "GrapeDuty/lita-test #42: Test1 :: htmlurl\n" + end + end + + context 'when there are more than 20 prs' do + before do + pr = [ + { title: 'Test21', number: 84, html_url: 'xxx' }, + { title: 'Test20', number: 83, html_url: 'xxx' }, + { title: 'Test19', number: 82, html_url: 'xxx' }, + { title: 'Test18', number: 80, html_url: 'xxx' }, + { title: 'Test17', number: 78, html_url: 'xxx' }, + { title: 'Test16', number: 74, html_url: 'xxx' }, + { title: 'Test15', number: 68, html_url: 'xxx' }, + { title: 'Test14', number: 66, html_url: 'xxx' }, + { title: 'Test13', number: 64, html_url: 'xxx' }, + { title: 'Test12', number: 55, html_url: 'xxx' }, + { title: 'Test11', number: 52, html_url: 'xxx' }, + { title: 'Test10', number: 51, html_url: 'xxx' }, + { title: 'Test9', number: 50, html_url: 'xxx' }, + { title: 'Test8', number: 49, html_url: 'xxx' }, + { title: 'Test7', number: 48, html_url: 'xxx' }, + { title: 'Test6', number: 47, html_url: 'xxx' }, + { title: 'Test5', number: 46, html_url: 'xxx' }, + { title: 'Test4', number: 45, html_url: 'xxx' }, + { title: 'Test3', number: 44, html_url: 'xxx' }, + { title: 'Test2', number: 43, html_url: 'xxx' }, + { title: 'Test1', number: 42, html_url: 'xxx' } + ] + octo_obj = double('Octokit::Client', pull_requests: pr) + allow(github_pr).to receive(:octo).and_return(octo_obj) + end + + it 'should return the list of ten oldest & ten newest' do + send_command("gh pr list #{github_org}/#{github_repo}") + expect(replies.last) + .to eql "You have more than 20 open pull requests :(! Here are the ten newest oldest: +GrapeDuty/lita-test #84: Test21 :: xxx +GrapeDuty/lita-test #83: Test20 :: xxx +GrapeDuty/lita-test #82: Test19 :: xxx +GrapeDuty/lita-test #80: Test18 :: xxx +GrapeDuty/lita-test #78: Test17 :: xxx +GrapeDuty/lita-test #74: Test16 :: xxx +GrapeDuty/lita-test #68: Test15 :: xxx +GrapeDuty/lita-test #66: Test14 :: xxx +GrapeDuty/lita-test #64: Test13 :: xxx +GrapeDuty/lita-test #55: Test12 :: xxx +---- +GrapeDuty/lita-test #51: Test10 :: xxx +GrapeDuty/lita-test #50: Test9 :: xxx +GrapeDuty/lita-test #49: Test8 :: xxx +GrapeDuty/lita-test #48: Test7 :: xxx +GrapeDuty/lita-test #47: Test6 :: xxx +GrapeDuty/lita-test #46: Test5 :: xxx +GrapeDuty/lita-test #45: Test4 :: xxx +GrapeDuty/lita-test #44: Test3 :: xxx +GrapeDuty/lita-test #43: Test2 :: xxx +GrapeDuty/lita-test #42: Test1 :: xxx +" end end end end