summaryrefslogtreecommitdiff
path: root/lib/tasks/contracts/pipelines.rake
blob: 55a7baa45392b0046456471c4744810dc9d02409 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true

return if Rails.env.production?

require 'pact/tasks/verification_task'

provider = File.expand_path('../../../spec/contracts/provider', __dir__)

namespace :contracts do
  require_relative "../../../spec/contracts/provider/helpers/contract_source_helper"

  namespace :pipelines do
    Pact::VerificationTask.new(:create_a_new_pipeline) do |pact|
      pact_helper_location = "pact_helpers/project/pipelines/new/post_create_a_new_pipeline_helper.rb"

      pact.uri(
        Provider::ContractSourceHelper.contract_location(:rake, pact_helper_location),
        pact_helper: "#{provider}/#{pact_helper_location}"
      )
    end

    Pact::VerificationTask.new(:get_list_project_pipelines) do |pact|
      pact_helper_location = "pact_helpers/project/pipelines/index/get_list_project_pipelines_helper.rb"

      pact.uri(
        Provider::ContractSourceHelper.contract_location(:rake, pact_helper_location),
        pact_helper: "#{provider}/#{pact_helper_location}"
      )
    end

    Pact::VerificationTask.new(:get_pipeline_header_data) do |pact|
      pact_helper_location = "pact_helpers/project/pipelines/show/get_pipeline_header_data_helper.rb"

      pact.uri(
        Provider::ContractSourceHelper.contract_location(:rake, pact_helper_location),
        pact_helper: "#{provider}/#{pact_helper_location}"
      )
    end

    Pact::VerificationTask.new(:delete_pipeline) do |pact|
      pact_helper_location = "pact_helpers/project/pipelines/show/delete_pipeline_helper.rb"

      pact.uri(
        Provider::ContractSourceHelper.contract_location(:rake, pact_helper_location),
        pact_helper: "#{provider}/#{pact_helper_location}"
      )
    end

    desc 'Run all pipeline contract tests'
    task 'test:pipelines', :contract_pipelines do |_t, arg|
      errors = %w[
        create_a_new_pipeline
        get_list_project_pipelines
        get_pipeline_header_data
        delete_pipeline
      ].each_with_object([]) do |task, err|
        Rake::Task["contracts:pipelines:pact:verify:#{task}"].execute
      rescue StandardError, SystemExit
        err << "contracts:pipelines:pact:verify:#{task}"
      end

      raise StandardError, "Errors in tasks #{errors.join(', ')}" unless errors.empty?
    end
  end
end