Sha256: 5c4e52e7fc7ec65508e2297f030a4942fa8854deed27c188ffc8e9dccbf850eb

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

require File.expand_path('../../spec_helper', __FILE__)
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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
danger-wcc-0.0.4 spec/wcc/github_spec.rb
danger-wcc-0.0.3 spec/wcc/github_spec.rb
danger-wcc-0.0.2 spec/wcc/github_spec.rb