notifier_spec.rb 1.85 KB
Newer Older
1 2
# frozen_string_literal: true

Tiago Botelho's avatar
Tiago Botelho committed
3 4 5 6 7 8 9 10 11 12
require 'spec_helper'

describe MicrosoftTeams::Notifier do
  subject { described_class.new(webhook_url) }

  let(:webhook_url) { 'https://example.gitlab.com/'}
  let(:header) { { 'Content-Type' => 'application/json' } }
  let(:options) do
    {
      title: 'JohnDoe4/project2',
13
      summary: '[[JohnDoe4/project2](http://localhost/namespace2/gitlabhq)] Issue [#1 Awesome issue](http://localhost/namespace2/gitlabhq/issues/1) opened by user6',
Tiago Botelho's avatar
Tiago Botelho committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
      activity: {
        title: 'Issue opened by user6',
        subtitle: 'in [JohnDoe4/project2](http://localhost/namespace2/gitlabhq)',
        text: '[#1 Awesome issue](http://localhost/namespace2/gitlabhq/issues/1)',
        image: 'http://someimage.com'
      },
      attachments: 'please fix'
    }
  end

  let(:body) do
    {
      'sections' => [
        {
          'activityTitle' => 'Issue opened by user6',
          'activitySubtitle' => 'in [JohnDoe4/project2](http://localhost/namespace2/gitlabhq)',
          'activityText' => '[#1 Awesome issue](http://localhost/namespace2/gitlabhq/issues/1)',
          'activityImage' => 'http://someimage.com'
        },
        {
          'title' => 'Details',
          'facts' => [
            {
              'name' => 'Attachments',
              'value' => 'please fix'
            }
          ]
        }
      ],
      'title' => 'JohnDoe4/project2',
      'summary' => '[[JohnDoe4/project2](http://localhost/namespace2/gitlabhq)] Issue [#1 Awesome issue](http://localhost/namespace2/gitlabhq/issues/1) opened by user6'
    }
  end

  describe '#ping' do
    before do
      stub_request(:post, webhook_url).with(body: JSON(body), headers: { 'Content-Type' => 'application/json' }).to_return(status: 200, body: "", headers: {})
    end

53
    it 'expects to receive successful answer' do
Tiago Botelho's avatar
Tiago Botelho committed
54 55 56 57
      expect(subject.ping(options)).to be true
    end
  end
end