-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: seed app with example data on first startup
- Loading branch information
Showing
8 changed files
with
245 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"consumer": { | ||
"name": "Zoo App" | ||
}, | ||
"provider": { | ||
"name": "Animal Service" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "a request for an alligator", | ||
"providerState": "there is an alligator named Mary", | ||
"request": { | ||
"method": "get", | ||
"path": "/alligators/Mary", | ||
"headers": { | ||
"Accept": "application/json" | ||
} | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json;charset=utf-8" | ||
}, | ||
"body": { | ||
"name": "Mary" | ||
} | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"pactSpecification": { | ||
"version": "2.0.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"consumer": { | ||
"name": "Zoo App" | ||
}, | ||
"provider": { | ||
"name": "Animal Service" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "a request for an alligator", | ||
"providerState": "there is an alligator named Mary", | ||
"request": { | ||
"method": "get", | ||
"path": "/alligators/Mary", | ||
"headers": { | ||
"Accept": "application/json" | ||
} | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json;charset=utf-8" | ||
}, | ||
"body": { | ||
"name": "Mary" | ||
}, | ||
"matchingRules": { | ||
"$.body.name": { | ||
"match": "type" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"pactSpecification": { | ||
"version": "2.0.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"consumer": { | ||
"name": "Zoo App" | ||
}, | ||
"provider": { | ||
"name": "Animal Service" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "a request for an alligator", | ||
"providerState": "there is an alligator named Mary", | ||
"request": { | ||
"method": "get", | ||
"path": "/alligators/Mary", | ||
"headers": { | ||
"Accept": "application/json" | ||
} | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json;charset=utf-8" | ||
}, | ||
"body": { | ||
"name": "Mary" | ||
}, | ||
"matchingRules": { | ||
"$.body.name": { | ||
"match": "type" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"description": "a request for an alligator", | ||
"providerState": "there is not an alligator named Mary", | ||
"request": { | ||
"method": "get", | ||
"path": "/alligators/Mary", | ||
"headers": { | ||
"Accept": "application/json" | ||
} | ||
}, | ||
"response": { | ||
"status": 404, | ||
"headers": { | ||
} | ||
} | ||
}, | ||
{ | ||
"description": "a request for an alligator", | ||
"providerState": "an error occurs retrieving an alligator", | ||
"request": { | ||
"method": "get", | ||
"path": "/alligators/Mary", | ||
"headers": { | ||
"Accept": "application/json" | ||
} | ||
}, | ||
"response": { | ||
"status": 500, | ||
"headers": { | ||
"Content-Type": "application/json;charset=utf-8" | ||
}, | ||
"body": { | ||
"error": "Argh!!!" | ||
} | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"pactSpecification": { | ||
"version": "2.0.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require 'pact_broker/test/test_data_builder' | ||
|
||
module PactBroker | ||
module DB | ||
class SeedExampleData | ||
def self.call | ||
new.call | ||
end | ||
|
||
def call | ||
PactBroker::Test::TestDataBuilder.new | ||
.create_consumer("Example App", created_at: days_ago(16)) | ||
.create_provider("Example API", created_at: days_ago(16)) | ||
.create_consumer_version("e15da45d3943bf10793a6d04cfb9f5dabe430fe2", created_at: days_ago(16)) | ||
.create_consumer_version_tag("prod", created_at: days_ago(16)) | ||
.create_consumer_version_tag("dev", created_at: days_ago(16)) | ||
.create_pact(json_content: pact_1, created_at: days_ago(16)) | ||
.create_verification(provider_version: "1315e0b1924cb6f42751f977789be3559373033a", success: false, execution_date: days_ago(15)) | ||
.create_provider_version_tag("dev", created_at: days_ago(14)) | ||
.create_verification(provider_version: "480e5aeb30467856ca995d0024d2c1800b0719e5", number: 2, execution_date: days_ago(14)) | ||
.create_provider_version_tag("prod", created_at: days_ago(14)) | ||
.create_provider_version_tag("dev", created_at: days_ago(14)) | ||
.create_consumer_version("725c6ccb7cf7efc51b4394f9828585eea9c379d9", 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("7bd4d9173522826dc3e8704fd62dde0424f4c827", created_at: days_ago(1)) | ||
.create_consumer_version_tag("dev", created_at: days_ago(1)) | ||
.create_pact(json_content: pact_3, created_at: days_ago(1)) | ||
.create_verification(provider_version: "4fdf20082263d4c5038355a3b734be1c0054d1e1", execution_date: days_ago(1)) | ||
.create_provider_version_tag("dev", created_at: days_ago(1)) | ||
end | ||
|
||
def pact_1 | ||
seed_data_file("pact_1.json") | ||
end | ||
|
||
def pact_2 | ||
seed_data_file("pact_2.json") | ||
end | ||
|
||
def pact_3 | ||
seed_data_file("pact_3.json") | ||
end | ||
|
||
def seed_data_dir | ||
File.join(File.dirname(__FILE__), "seed") | ||
end | ||
|
||
def seed_data_file(name) | ||
File.read(File.join(seed_data_dir, name)) | ||
end | ||
|
||
def days_ago(days) | ||
DateTime.now - days | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters