# frozen_string_literal: true require File.expand_path('../spec_helper', __dir__) require 'webmock' module Danger include FixturesHelper API_URL = 'https://api.github.com' describe Danger::DangerWCC do before do @dangerfile = testing_dangerfile @my_plugin = @dangerfile.wcc @github = @dangerfile.github allow(@github).to receive(:pr_json) .and_return(JSON.parse(load_fixture('github_pr.json'))) end describe 'github' do before do stub_request(:get, API_URL + '/repos/watermarkchurch/danger-wcc/labels') .with(query: hash_excluding({ 'anything' => 1 })) .to_return( body: load_fixture('github/labels.json'), headers: { 'Content-Type' => 'application/json' } ) end it '#labels returns array of existing labels' do # act labels = @my_plugin.labels # assert expect(labels.length).to eq(10) end it '#add_labels adds existing labels to issue' do stub = stub_request( :post, API_URL + '/repos/watermarkchurch/danger-wcc/issues/2/labels' ) .with(body: '["backlog","bug","duplicate"]') # act @my_plugin.add_labels('backlog', 'bug', 'duplicate') # assert expect(stub).to have_been_requested end it '#add_labels creates new labels before adding to issue' do stub = stub_request( :post, API_URL + '/repos/watermarkchurch/danger-wcc/labels' ) .with(body: '{"name":"new_label","color":"ffffff"}') stub_request( :post, API_URL + '/repos/watermarkchurch/danger-wcc/issues/2/labels' ) .with(body: '["backlog","new_label"]') # act @my_plugin.add_labels('backlog', 'new_label') # assert expect(stub).to have_been_requested end end end end