Sha256: dd41ac6bc5403eac7ff79922486f200405409edebe99e4ea3c3667c8eeecd4ae

Contents?: true

Size: 1.89 KB

Versions: 6

Compression:

Stored size: 1.89 KB

Contents

# 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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
danger-wcc-0.1.4 spec/wcc/github_spec.rb
danger-wcc-0.1.3 spec/wcc/github_spec.rb
danger-wcc-0.1.2 spec/wcc/github_spec.rb
danger-wcc-0.1.1 spec/wcc/github_spec.rb
danger-wcc-0.1.0 spec/wcc/github_spec.rb
danger-wcc-0.0.6 spec/wcc/github_spec.rb