Class: PactBroker::DB::SeedExampleData

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/db/seed_example_data.rb

Constant Summary collapse

CONSUMER_NAME =
"Example App"
PROVIDER_NAME =
"Example API"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.callObject



10
11
12
# File 'lib/pact_broker/db/seed_example_data.rb', line 10

def self.call
  new.call
end

Instance Method Details

#call(consumer_name: CONSUMER_NAME, provider_name: PROVIDER_NAME) ⇒ Object

rubocop: disable Metrics/MethodLength



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
# File 'lib/pact_broker/db/seed_example_data.rb', line 15

def call(consumer_name: CONSUMER_NAME, provider_name: PROVIDER_NAME)
  return unless database_empty?
  PactBroker::Test::TestDataBuilder.new
    .create_environment("test", display_name: "Test", production: false)
    .create_environment("production", display_name: "Production", production: true)
    .create_consumer(consumer_name, created_at: days_ago(16))
    .create_provider(provider_name, created_at: days_ago(16))
    .create_consumer_version("e15da45d3943bf10793a6d04cfb9f5dabe430fe2", branch: "main", created_at: days_ago(16))
    .create_consumer_version_tag("prod", created_at: days_ago(16))
    .create_consumer_version_tag("main", created_at: days_ago(16))
    .create_deployed_version_for_consumer_version(environment_name: "production", currently_deployed: false, created_at: days_ago(16))
    .create_pact(json_content: pact_1, created_at: days_ago(16))
    .create_verification(provider_version: "1315e0b1924cb6f42751f977789be3559373033a", branch: "main", execution_date: days_ago(15))
    .create_deployed_version_for_provider_version(environment_name: "production", currently_deployed: true, created_at: days_ago(15))
    .create_deployed_version_for_consumer_version(environment_name: "production", currently_deployed: true, created_at: days_ago(14))
    .create_verification(provider_version: "480e5aeb30467856ca995d0024d2c1800b0719e5", branch: "main", success: false, number: 2, execution_date: days_ago(14))
    .create_provider_version_tag("main", created_at: days_ago(14))
    .create_consumer_version("725c6ccb7cf7efc51b4394f9828585eea9c379d9", branch: "feat/new-thing", created_at: days_ago(7))
    .create_consumer_version_tag("feat-new-thing", created_at: days_ago(7))
    .create_pact(json_content: pact_2, created_at: days_ago(7))
    .create_consumer_version("6c992f831da299364cf31be6008ee4752189f6d4", branch: "feat/new-thing", created_at: days_ago(6))
    .create_consumer_version_tag("feat-new-thing", created_at: days_ago(6))
    .create_pact(json_content: pact_2, created_at: days_ago(7))
    .create_consumer_version("7bd4d9173522826dc3e8704fd62dde0424f4c827", branch: "main", created_at: days_ago(1))
    .create_consumer_version_tag("main", created_at: days_ago(1))
    .create_pact(json_content: pact_3, created_at: days_ago(1))
    .create_verification(provider_version: "4fdf20082263d4c5038355a3b734be1c0054d1e1", branch: "main", execution_date: days_ago(1))
    .create_deployed_version_for_provider_version(environment_name: "test", created_at: days_ago(1))
    .create_provider_version_tag("main", created_at: days_ago(1))
    .create_consumer_version("5556b8149bf8bac76bc30f50a8a2dd4c22c85f30", branch: "main", created_at: days_ago(0.5))
    .create_consumer_version_tag("main", created_at: days_ago(0.5))
    .create_deployed_version_for_consumer_version(environment_name: "test", created_at: days_ago(0.5))
    .republish_same_pact(created_at: days_ago(0.5))
end

#database_empty?Boolean

rubocop: enable Metrics/MethodLength

Returns:

  • (Boolean)


51
52
53
# File 'lib/pact_broker/db/seed_example_data.rb', line 51

def database_empty?
  PactBroker::Pacticipants::Service.find_all_pacticipants.empty?
end

#days_ago(days) ⇒ Object



75
76
77
# File 'lib/pact_broker/db/seed_example_data.rb', line 75

def days_ago(days)
  DateTime.now - days
end

#pact_1Object



55
56
57
# File 'lib/pact_broker/db/seed_example_data.rb', line 55

def pact_1
  seed_data_file("pact_1.json")
end

#pact_2Object



59
60
61
# File 'lib/pact_broker/db/seed_example_data.rb', line 59

def pact_2
  seed_data_file("pact_2.json")
end

#pact_3Object



63
64
65
# File 'lib/pact_broker/db/seed_example_data.rb', line 63

def pact_3
  seed_data_file("pact_3.json")
end

#seed_data_dirObject



67
68
69
# File 'lib/pact_broker/db/seed_example_data.rb', line 67

def seed_data_dir
  File.join(File.dirname(__FILE__), "seed")
end

#seed_data_file(name) ⇒ Object



71
72
73
# File 'lib/pact_broker/db/seed_example_data.rb', line 71

def seed_data_file(name)
  File.read(File.join(seed_data_dir, name))
end