newman_scenario 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d60c8eac8bd0c964e9e3b8de49d4ef6c1f9d01dd74b8a06b4e09f30b5ab52c25
4
- data.tar.gz: 4556d9ae5231ef5ff852f2efebbf3f931115ee0a2624d01733c4b83b494efba5
3
+ metadata.gz: 559c5e124ccffa5e4f98839bc34a87351203e13f977dbc07820fe7f7cdf9720b
4
+ data.tar.gz: a0935c087ed1e143699f7932c04965845b90c90cecd66cedfe21a58056e9861f
5
5
  SHA512:
6
- metadata.gz: 2e8f88228bc646bf1a3f6f0f18aa7834f17a60c7b0fdc2eabc6ad47f1165bc8757bf4b450ef0a2308c913bfe9e7cb4a912115cb1099c8cb64ba0938edd10dbb5
7
- data.tar.gz: 61c3fd0c42f480b401e33864fe3ce2edc643657ea323f9c9085e7bc6877dd51dc31f5f43567dbdac76553d1a9e0eef4ebc1406762a9ffff26056e8662c9c5b07
6
+ metadata.gz: 5da5a15b5291c5a38224b6e352181f876a2451c202af0e396dbb3500884e63e329a4512c9110bf1438e573955356fee7d353a1685f55d8d6cf0e83bd0033ceff
7
+ data.tar.gz: 849b32f48312ae202757ffb1b17197a9936fd0d4671b5196ad507b0fe8a3e891108f3efe94e872f919cd54c43748985eb23ff036fad2d5ecb70aa3bfb36d179a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- newman_scenario (0.1.0)
4
+ newman_scenario (0.1.1)
5
5
  dotenv (= 2.7.5)
6
6
  httparty (= 0.16.2)
7
7
  thor (= 1.0.1)
data/README.md CHANGED
@@ -37,6 +37,15 @@ Or install it yourself as:
37
37
 
38
38
  ## Configuration
39
39
 
40
+ ### Using configure`
41
+
42
+ configure will guide you to set Postman related collection id and environments ids, and
43
+ stores them in `.env`
44
+
45
+ $ newman_scenario configure
46
+
47
+ ### Setting `.env` manually
48
+
40
49
  Add this to your `ENV` or `.env`
41
50
 
42
51
  ```
@@ -53,12 +62,13 @@ NEWMAN_SCENARIO_COLLECTION_ID: 7361507-9627fa69-1fe0-0000-AAAA-XXXXXX
53
62
  # config/initializers/newman_scenario.rb
54
63
  require 'newman_scenario'
55
64
 
56
- # NewmanScenario configuration
57
- NewmanScenario::Scenario.default_collection_id = 'ABCDEF-XXXXX-XXXX-0000-AAAA-XXXXXX' # ENV['NEWMAN_SCENARIO_COLLECTION_ID']
58
- NewmanScenario::Scenario.default_environment_ids = { staging: 'YXZ-XXXXX-XXXX-0000-AAAA-XXXXXX', production: ''ABC-XXXXX-XXXX-0000-AAAA-XXXXXX''} # ENV['NEWMAN_SCENARIO_ENVIRONMENTS'] (json format)
59
- NewmanScenario::Scenario.default_collection_id = 'PMAK-XXXX-XXXX' # ENV['POSTMAN_API_KEY']
60
- NewmanScenario::Scenario.default_custom_collection_file_path = 'newman-scenarios.json' # ENV['NEWMAN_SCENARIO_CUSTOM_COLLECTION_FILE_PATH'], default: `newman_scenarios.json`
61
- NewmanScenario::Scenario.default_last_scenario_file_path = 'newman-scenarios.json' # ENV['NEWMAN_SCENARIO_LAST_SCENARIO_FILE_PATH'], default: `last_newman_scenario.json`
65
+ NewmanScenario::Scenario.configure(
66
+ default_api_key: 'PMAK-XXXX-XXXX', # ENV['POSTMAN_API_KEY'], no default value
67
+ default_collection_id: 'ABCDEF-XXXXX-XXXX-0000-AAAA-XXXXXX', # ENV['NEWMAN_SCENARIO_COLLECTION_ID'], no default value
68
+ default_environment_ids: { staging: 'YXZ-XXXXX-XXXX-0000-AAAA-XXXXXX', production: 'ABC-XXXXX-XXXX-0000-AAAA-XXXXXX'}, # ENV['NEWMAN_SCENARIO_ENVIRONMENTS'] (json format), no default value
69
+ default_custom_scenarios_file_path: 'newman-scenarios.json', # ENV['NEWMAN_SCENARIO_CUSTOM_COLLECTION_FILE_PATH'], default: `newman_scenarios.json`
70
+ default_last_scenario_file_path: '/tmp/last_newman_scenario.json' # ENV['NEWMAN_SCENARIO_LAST_SCENARIO_FILE_PATH'], default: `last_newman_scenario.json`
71
+ )
62
72
  ```
63
73
 
64
74
  ## Usage
@@ -98,6 +108,16 @@ NewmanScenario::Scenario.new.run
98
108
  NewmanScenario::Scenario.new.run(scenario_name: 'Signup', environment_name: 'staging3', no_prompt: true)
99
109
  ```
100
110
 
111
+ ## Roadmap
112
+
113
+ - [x] `NewmanScenario::Scenario.run`
114
+ - [ ] Specs :(
115
+ - [x] `newman_scenario` cli
116
+ - [x] Configure using `NewmanScenario::Scenario.configure`
117
+ - [ ] Support for custom scenario variable
118
+ - [ ] Support for local environment (no synchronised with Postman)
119
+ - [ ] Fetch available collections and environments from Postman
120
+
101
121
  ## Development
102
122
 
103
123
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -14,5 +14,15 @@ module NewmanScenario
14
14
  def run_scenario( environment = nil, scenario = nil )
15
15
  Scenario.new.run(scenario_name: scenario, environment_name: environment, bail: options[:bail])
16
16
  end
17
+
18
+ desc "configure", "configure Postman vs newman_scenario"
19
+ long_desc <<~EOF
20
+
21
+ `newman_scenario` needs some information about Postman environments and collections
22
+ Configure will prompt you for each and optionally save them to `.env`
23
+ EOF
24
+ def configure( )
25
+ Scenario.configure
26
+ end
17
27
  end
18
28
  end
@@ -5,20 +5,57 @@ require 'dotenv/load'
5
5
 
6
6
  module NewmanScenario
7
7
  class Error < StandardError; end
8
+ class ConfigurationError < StandardError; end
8
9
 
9
10
  class Scenario
11
+ DEFAULT_CUSTOM_SCENARIOS_FILE_PATH = 'newman_scenarios.json'.freeze
12
+ DEFAULT_LAST_SCENARIO_FILE_PATH = '/tmp/last_newman_scenario.json'.freeze
13
+
10
14
  @default_collection_id = ENV['NEWMAN_SCENARIO_COLLECTION_ID']
11
15
  @default_environment_ids = nil
12
16
  @default_api_key = ENV['POSTMAN_API_KEY']
13
- @default_custom_collection_file_path = ENV['NEWMAN_SCENARIO_CUSTOM_COLLECTION_FILE_PATH'] || 'newman_scenarios.json'.freeze
14
- @default_last_scenario_file_path = ENV['NEWMAN_SCENARIO_LAST_SCENARIO_FILE_PATH'] || '/tmp/last_newman_scenario.json'.freeze
17
+ @default_custom_scenarios_file_path = ENV['NEWMAN_SCENARIO_CUSTOM_COLLECTION_FILE_PATH'] || DEFAULT_CUSTOM_SCENARIOS_FILE_PATH
18
+ @default_last_scenario_file_path = ENV['NEWMAN_SCENARIO_LAST_SCENARIO_FILE_PATH'] || DEFAULT_LAST_SCENARIO_FILE_PATH
15
19
 
16
20
  class << self
21
+ attr_accessor :default_api_key
17
22
  attr_accessor :default_collection_id
18
23
  attr_accessor :default_environment_ids
19
- attr_accessor :default_api_key
20
- attr_accessor :default_custom_collection_file_path
24
+ attr_accessor :default_custom_scenarios_file_path
21
25
  attr_accessor :default_last_scenario_file_path
26
+
27
+ def configure(default_api_key: nil, default_collection_id: nil, default_environment_ids: nil, default_custom_scenarios_file_path: nil, default_last_scenario_file_path: nil)
28
+ self.default_api_key = default_api_key || prompt.ask('Postman API Key:')
29
+ self.default_collection_id = default_collection_id || prompt.ask('Postman Collection Id:')
30
+ self.default_environment_ids = default_environment_ids
31
+ unless self.default_environment_ids
32
+ self.default_environment_ids = {}
33
+ loop do
34
+ break unless prompt.yes?('Add environment?')
35
+
36
+ name = prompt.ask('Environment Name:')
37
+ id = prompt.ask('Environment Id:')
38
+ self.default_environment_ids[name] = id
39
+ end
40
+ end
41
+ self.default_custom_scenarios_file_path = default_custom_scenarios_file_path || prompt.ask('Custom scenarios file path:', value: DEFAULT_CUSTOM_SCENARIOS_FILE_PATH)
42
+ self.default_last_scenario_file_path = default_last_scenario_file_path || prompt.ask('Last scenario file path:', value: DEFAULT_LAST_SCENARIO_FILE_PATH)
43
+ if (env_path = prompt.ask('Save to: [enter to not save]', value: '.env'))
44
+ File.open(env_path, 'a') do |file|
45
+ file.puts "POSTMAN_API_KEY: #{self.default_api_key}"
46
+ file.puts "NEWMAN_SCENARIO_COLLECTION_ID: #{self.default_collection_id}"
47
+ file.puts "NEWMAN_SCENARIO_ENVIRONMENTS: #{self.default_environment_ids.to_json}"
48
+ file.puts "NEWMAN_SCENARIO_CUSTOM_COLLECTION_FILE_PATH: #{self.default_custom_scenarios_file_path}"
49
+ file.puts "NEWMAN_SCENARIO_LAST_SCENARIO_FILE_PATH: #{self.default_last_scenario_file_path}"
50
+ end
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def prompt
57
+ @prompt ||= TTY::Prompt.new
58
+ end
22
59
  end
23
60
 
24
61
  attr_accessor :collection_id
@@ -29,25 +66,31 @@ module NewmanScenario
29
66
 
30
67
  def initialize(collection_id: nil, environment_ids: nil, api_key: nil, custom_collection_file_path: nil, last_scenario_file_path: nil)
31
68
  self.collection_id ||= self.class.default_collection_id
32
- raise Error, 'Missing Collection Id' unless self.collection_id
69
+ raise ConfigurationError, 'Missing Collection Id' unless self.collection_id
33
70
 
34
71
  self.environment_ids ||= self.class.default_environment_ids
35
72
  self.environment_ids ||= JSON.parse(ENV['NEWMAN_SCENARIO_ENVIRONMENTS'], symbolize_names: true) if ENV['NEWMAN_SCENARIO_ENVIRONMENTS']
36
- raise Error, 'Missing Environment Ids' unless self.environment_ids
73
+ raise ConfigurationError, 'Missing Environment Ids' unless self.environment_ids
37
74
 
38
75
  self.api_key ||= self.class.default_api_key
39
- raise Error, 'Missing Postman API Key' unless self.api_key
76
+ raise ConfigurationError, 'Missing Postman API Key' unless self.api_key
40
77
 
41
- self.custom_collection_file_path ||= self.class.default_custom_collection_file_path
42
- raise Error, 'Missing Custom collection file path' unless self.custom_collection_file_path
78
+ self.custom_collection_file_path ||= self.class.default_custom_scenarios_file_path
79
+ raise ConfigurationError, 'Missing Custom collection file path' unless self.custom_collection_file_path
43
80
 
44
81
  self.last_scenario_file_path ||= self.class.default_last_scenario_file_path
45
- raise Error, 'Missing Last scenario file path' unless self.last_scenario_file_path
46
-
82
+ raise ConfigurationError, 'Missing Last scenario file path' unless self.last_scenario_file_path
83
+ rescue ConfigurationError => e
84
+ prompt.warn e
85
+ if prompt.yes?('Configure?')
86
+ self.class.configure
87
+ retry
88
+ end
47
89
  end
48
90
 
49
91
  def run(environment_name: nil, scenario_name: nil, bail: true, no_prompt: false)
50
92
  return if `which newman`.empty? && !prompt_to_install_newman
93
+
51
94
  prompt_to_set_api_key unless api_key
52
95
  environment = environment_ids[environment_name.to_sym] if environment_name
53
96
  environment ||= prompt.select("Environment", environment_ids, default: 1)
@@ -69,6 +112,7 @@ module NewmanScenario
69
112
  scenario_requests.delete('duplicate')
70
113
  scenario_requests += prompt.multi_select("Requests (type to filter prefix, choose duplicate to perform action multiple times)", ['duplicate'] + all_request_names, cycle: true, filter: true)
71
114
  break unless scenario_requests.include?('duplicate')
115
+
72
116
  end
73
117
  if prompt.yes?('Save this custom scenario?')
74
118
  name = prompt.ask('Name?')
@@ -127,6 +171,7 @@ module NewmanScenario
127
171
  def prompt_to_install_newman
128
172
  prompt.warn 'missing newman command line'
129
173
  return false unless prompt.yes?('Install newman?')
174
+
130
175
  prompt.ok 'installing newman: brew install newman'
131
176
  cmd('brew install newman')
132
177
  end
@@ -160,7 +205,6 @@ module NewmanScenario
160
205
  end
161
206
 
162
207
  def fetch_postman_to_file(url_path, file_path)
163
- puts "https://api.getpostman.com/#{url_path}"
164
208
  response = HTTParty.get("https://api.getpostman.com/#{url_path}", headers: { 'X-Api-Key' => api_key})
165
209
  raise Error, "Invalid response code: #{response.code}" unless response.code == 200
166
210
 
@@ -1,3 +1,3 @@
1
1
  module NewmanScenario
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newman_scenario
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hugues Bernet-Rollande