|
| 1 | +require 'pact_broker/api/decorators/triggered_webhook_decorator' |
| 2 | + |
| 3 | +module PactBroker |
| 4 | + module Api |
| 5 | + module Decorators |
| 6 | + describe TriggeredWebhookDecorator do |
| 7 | + let(:triggered_webhook) do |
| 8 | + double('PactBroker::Webhooks::TriggeredWebhook', |
| 9 | + trigger_type: PactBroker::Webhooks::TriggeredWebhook::TRIGGER_TYPE_RESOURCE_CREATION, |
| 10 | + status: status, |
| 11 | + failure?: failure, |
| 12 | + retrying?: retrying, |
| 13 | + trigger_uuid: '1234', |
| 14 | + webhook_uuid: '4321', |
| 15 | + request_description: "GET http://foo", |
| 16 | + pact_publication: pact, |
| 17 | + number_of_attempts_made: 1, |
| 18 | + number_of_attempts_remaining: 2, |
| 19 | + created_at: DateTime.new(2017), |
| 20 | + updated_at: DateTime.new(2017) |
| 21 | + ) |
| 22 | + end |
| 23 | + |
| 24 | + let(:pact) do |
| 25 | + double('pact', |
| 26 | + provider: double(name: 'provider'), |
| 27 | + consumer: double(name: 'consumer'), |
| 28 | + consumer_version_number: '1', |
| 29 | + name: 'foo ' |
| 30 | + ) |
| 31 | + end |
| 32 | + |
| 33 | + let(:failure) { false } |
| 34 | + let(:retrying) { false } |
| 35 | + let(:status) { PactBroker::Webhooks::TriggeredWebhook::STATUS_SUCCESS } |
| 36 | + let(:logs_url) { "http://example.org/webhooks/4321/trigger/1234/logs" } |
| 37 | + let(:user_options) { { base_url: "http://example.org" } } |
| 38 | + |
| 39 | + let(:json) do |
| 40 | + TriggeredWebhookDecorator.new(triggered_webhook).to_json(user_options: user_options) |
| 41 | + end |
| 42 | + |
| 43 | + subject { JSON.parse(json, symbolize_names: true) } |
| 44 | + |
| 45 | + it "includes a link to the logs" do |
| 46 | + expect(subject[:_links][:logs][:href]).to eq logs_url |
| 47 | + end |
| 48 | + |
| 49 | + it "includes a link to the webhook" do |
| 50 | + expect(subject[:_links][:'pb:webhook'][:href]).to eq "http://example.org/webhooks/4321" |
| 51 | + end |
| 52 | + |
| 53 | + it "includes the triggered webhooks properties" do |
| 54 | + expect(subject).to include( |
| 55 | + status: 'success', |
| 56 | + triggerType: 'resource_creation', |
| 57 | + attemptsMade: 1, |
| 58 | + attemptsRemaining: 2 |
| 59 | + ) |
| 60 | + end |
| 61 | + end |
| 62 | + end |
| 63 | + end |
| 64 | +end |
0 commit comments