automation-test 1.22 → 1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -5
- data/lib/apimatic_calculator/configuration.rb +3 -3
- data/lib/apimatic_calculator/controllers/simple_calculator_controller.rb +4 -12
- data/lib/apimatic_calculator/models/operation_type_enum.rb +4 -4
- data/test/controllers/controller_test_base.rb +21 -0
- data/test/controllers/test_simple_calculator_controller.rb +34 -0
- data/test/http_response_catcher.rb +19 -0
- data/test/test_helper.rb +94 -0
- metadata +41 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bbadee38c26e33d07680d66d9c3178bd21a397ef63e0faf86c34d5843a3dafa
|
4
|
+
data.tar.gz: 672fe6cfd2fb6eb91cbdf43f7ac2a7aae08ce313affe47f1a7a4d83df574654d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 516ad91a9ee37dd7f62598b46b1eebdd9820ebfda1dedabc6a12869c942b46e526dd6e48ff9c2b856ed189c25172c35b43599595930f0e4d8b869c7079cc41e0
|
7
|
+
data.tar.gz: 384ce20df710cb5421fe1b1d3caf6cee82b42fbf2646dbce657f84cc81ce980e702157a7265919877d9b50625eaedc531a50176f48c76bee342ea598dc70a29b
|
data/README.md
CHANGED
@@ -3,23 +3,31 @@
|
|
3
3
|
|
4
4
|
## Introduction
|
5
5
|
|
6
|
-
Simple calculator API hosted on APIMATIC
|
6
|
+
Simple calculator API hosted on APIMATIC
|
7
7
|
|
8
8
|
## Install the Package
|
9
9
|
|
10
10
|
Install the gem from the command line:
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
gem install automation-test -v 1.
|
13
|
+
gem install automation-test -v 1.23
|
14
14
|
```
|
15
15
|
|
16
16
|
Or add the gem to your Gemfile and run `bundle`:
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
gem 'automation-test', '1.
|
19
|
+
gem 'automation-test', '1.23'
|
20
20
|
```
|
21
21
|
|
22
|
-
For additional gem details, see the [RubyGems page for the automation-test gem](https://rubygems.org/gems/automation-test/versions/1.
|
22
|
+
For additional gem details, see the [RubyGems page for the automation-test gem](https://rubygems.org/gems/automation-test/versions/1.23).
|
23
|
+
|
24
|
+
## Test the SDK
|
25
|
+
|
26
|
+
To run the tests, navigate to the root directory of the SDK in your terminal and execute the following command:
|
27
|
+
|
28
|
+
```
|
29
|
+
rake
|
30
|
+
```
|
23
31
|
|
24
32
|
## Initialize the API Client
|
25
33
|
|
@@ -29,6 +37,7 @@ The following parameters are configurable for the API Client:
|
|
29
37
|
|
30
38
|
| Parameter | Type | Description |
|
31
39
|
| --- | --- | --- |
|
40
|
+
| `environment` | Environment | The API environment. <br> **Default: `Environment.PRODUCTION`** |
|
32
41
|
| `timeout` | `Float` | The value to use for connection timeout. <br> **Default: 60** |
|
33
42
|
| `max_retries` | `Integer` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
|
34
43
|
| `retry_interval` | `Float` | Pause in seconds between retries. <br> **Default: 1** |
|
@@ -39,7 +48,8 @@ The following parameters are configurable for the API Client:
|
|
39
48
|
The API client can be initialized as follows:
|
40
49
|
|
41
50
|
```ruby
|
42
|
-
client = ApimaticCalculator::Client.new(
|
51
|
+
client = ApimaticCalculator::Client.new(
|
52
|
+
environment: Environment::PRODUCTION,
|
43
53
|
)
|
44
54
|
```
|
45
55
|
|
@@ -15,7 +15,7 @@ module ApimaticCalculator
|
|
15
15
|
# An enum for API servers.
|
16
16
|
class Server
|
17
17
|
SERVER = [
|
18
|
-
|
18
|
+
CALCULATOR = 'Calculator'.freeze
|
19
19
|
].freeze
|
20
20
|
end
|
21
21
|
|
@@ -96,7 +96,7 @@ module ApimaticCalculator
|
|
96
96
|
# All the environments the SDK can run in.
|
97
97
|
ENVIRONMENTS = {
|
98
98
|
Environment::PRODUCTION => {
|
99
|
-
Server::
|
99
|
+
Server::CALCULATOR => 'https://examples.apimatic.io/apps/calculator'
|
100
100
|
}
|
101
101
|
}.freeze
|
102
102
|
|
@@ -104,7 +104,7 @@ module ApimaticCalculator
|
|
104
104
|
# @param [Configuration::Server] The server enum for which the base URI is
|
105
105
|
# required.
|
106
106
|
# @return [String] The base URI.
|
107
|
-
def get_base_uri(server = Server::
|
107
|
+
def get_base_uri(server = Server::CALCULATOR)
|
108
108
|
ENVIRONMENTS[environment][server].clone
|
109
109
|
end
|
110
110
|
end
|
@@ -11,31 +11,23 @@ module ApimaticCalculator
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# Calculates the expression using the specified operation.
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# | Table Column 1 | Table Column 2 | Table Column 3 |
|
17
|
-
# | -------------- | -------------- | -------------- |
|
18
|
-
# | Row 1x1 | Row 1x2 | Row 1x3 |
|
19
|
-
# | Row 2x1 | Row 2x2 | Row 2x3 |
|
20
14
|
# @param [OperationTypeEnum] operation Required parameter: The operator to
|
21
15
|
# apply on the variables
|
22
16
|
# @param [Float] x Required parameter: The LHS value
|
23
17
|
# @param [Float] y Required parameter: The RHS value
|
24
18
|
# @return [Float] response from the API call
|
25
|
-
def
|
26
|
-
x,
|
27
|
-
y)
|
19
|
+
def get_calculate(options = {})
|
28
20
|
# Prepare query url.
|
29
21
|
_query_builder = config.get_base_uri
|
30
22
|
_query_builder << '/{operation}'
|
31
23
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
32
24
|
_query_builder,
|
33
|
-
'operation' => { 'value' => operation, 'encode' => true }
|
25
|
+
'operation' => { 'value' => options['operation'], 'encode' => true }
|
34
26
|
)
|
35
27
|
_query_builder = APIHelper.append_url_with_query_parameters(
|
36
28
|
_query_builder,
|
37
|
-
'x' => x,
|
38
|
-
'y' => y
|
29
|
+
'x' => options['x'],
|
30
|
+
'y' => options['y']
|
39
31
|
)
|
40
32
|
_query_url = APIHelper.clean_url _query_builder
|
41
33
|
|
@@ -7,16 +7,16 @@ module ApimaticCalculator
|
|
7
7
|
# Possible operators are sum, subtract, multiply, divide
|
8
8
|
class OperationTypeEnum
|
9
9
|
OPERATION_TYPE_ENUM = [
|
10
|
-
#
|
10
|
+
# Represents the sum operator
|
11
11
|
SUM = 'SUM'.freeze,
|
12
12
|
|
13
|
-
#
|
13
|
+
# Represents the subtract operator
|
14
14
|
SUBTRACT = 'SUBTRACT'.freeze,
|
15
15
|
|
16
|
-
#
|
16
|
+
# Represents the multiply operator
|
17
17
|
MULTIPLY = 'MULTIPLY'.freeze,
|
18
18
|
|
19
|
-
#
|
19
|
+
# Represents the divide operator
|
20
20
|
DIVIDE = 'DIVIDE'.freeze
|
21
21
|
].freeze
|
22
22
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'json'
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'minitest/hell'
|
9
|
+
require 'minitest/pride'
|
10
|
+
require 'minitest/proveit'
|
11
|
+
require 'apimatic_calculator'
|
12
|
+
require_relative '../test_helper'
|
13
|
+
require_relative '../http_response_catcher'
|
14
|
+
|
15
|
+
class ControllerTestBase < Minitest::Test
|
16
|
+
parallelize_me!
|
17
|
+
include ApimaticCalculator
|
18
|
+
|
19
|
+
# Create configuration and set any test parameters
|
20
|
+
CONFIG = Configuration.new
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require_relative 'controller_test_base'
|
7
|
+
|
8
|
+
class SimpleCalculatorControllerTests < ControllerTestBase
|
9
|
+
# Called only once for the class before any test has executed
|
10
|
+
def setup
|
11
|
+
@response_catcher = HttpResponseCatcher.new
|
12
|
+
@controller = SimpleCalculatorController.new CONFIG, http_call_back: @response_catcher
|
13
|
+
end
|
14
|
+
|
15
|
+
# Check if multiplication works
|
16
|
+
def test_multiply()
|
17
|
+
# Parameters for the API call
|
18
|
+
options = {}
|
19
|
+
options['operation'] = 'MULTIPLY'
|
20
|
+
options['x'] = 4
|
21
|
+
options['y'] = 5
|
22
|
+
|
23
|
+
# Perform the API call through the SDK function
|
24
|
+
result = @controller.get_calculate(options)
|
25
|
+
|
26
|
+
# Test response code
|
27
|
+
assert_equal(200, @response_catcher.response.status_code)
|
28
|
+
|
29
|
+
# Test whether the captured response is as we expected
|
30
|
+
refute_nil(result)
|
31
|
+
assert_equal('20', @response_catcher.response.raw_body)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
class HttpResponseCatcher < ApimaticCalculator::HttpCallBack
|
7
|
+
attr_accessor :response
|
8
|
+
|
9
|
+
def on_before_request(request)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Catching the response
|
13
|
+
def on_after_response(response)
|
14
|
+
@response = response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'tempfile'
|
7
|
+
require 'open-uri'
|
8
|
+
|
9
|
+
class TestHelper
|
10
|
+
|
11
|
+
@cache = Hash.new
|
12
|
+
|
13
|
+
# Class method to compare the received headers with the expected headers.
|
14
|
+
# @param [Hash] A hash of expected headers (keys in lower case).
|
15
|
+
# @param [Hash] A hash of received headers.
|
16
|
+
# @param [Boolean, optional] A flag which determines if we allow extra headers.
|
17
|
+
def self.match_headers(expected_headers,
|
18
|
+
received_headers,
|
19
|
+
allow_extra: true)
|
20
|
+
return false if ((received_headers.length < expected_headers.length) ||
|
21
|
+
((allow_extra == false) && (received_headers.length > expected_headers.length)))
|
22
|
+
|
23
|
+
received_headers = Hash[received_headers.map{|k, v| [k.to_s.downcase, v]}]
|
24
|
+
expected_headers.each do |e_key, e_value|
|
25
|
+
return false unless received_headers.key?(e_key)
|
26
|
+
return false if ((e_value != nil) &&
|
27
|
+
(e_value != received_headers[e_key]))
|
28
|
+
end
|
29
|
+
|
30
|
+
return true
|
31
|
+
end
|
32
|
+
|
33
|
+
# Class method to compare the received body with the expected body.
|
34
|
+
# @param [Dynamic] The expected body.
|
35
|
+
# @param [Dynamic] The received body.
|
36
|
+
# @param [Boolean, optional] A flag which determines if we check values in dictionaries.
|
37
|
+
# @param [Boolean, optional] A flag which determines if we check the order of array elements.
|
38
|
+
# @param [Boolean, optional] A flag which determines if we check the count of array elements.
|
39
|
+
def self.match_body(expected_body,
|
40
|
+
received_body,
|
41
|
+
check_values: false,
|
42
|
+
check_order: false,
|
43
|
+
check_count: false)
|
44
|
+
if expected_body.instance_of? Hash
|
45
|
+
return false unless received_body.instance_of? Hash
|
46
|
+
for key in expected_body.keys
|
47
|
+
return false unless received_body.keys.include? key
|
48
|
+
if check_values or expected_body[key].instance_of? Hash
|
49
|
+
return false unless TestHelper.match_body(expected_body[key],
|
50
|
+
received_body[key],
|
51
|
+
check_values: check_values,
|
52
|
+
check_order: check_order,
|
53
|
+
check_count: check_count)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
elsif expected_body.instance_of? Array
|
57
|
+
return False unless received_body.instance_of? Array
|
58
|
+
if check_count == true && (expected_body.length != received_body.length)
|
59
|
+
return false
|
60
|
+
else
|
61
|
+
previous_matches = Array.new
|
62
|
+
expected_body.each.with_index do |expected_element, i|
|
63
|
+
matches = (received_body.map.with_index do |received_element, j|
|
64
|
+
j if TestHelper.match_body(expected_element,
|
65
|
+
received_element,
|
66
|
+
check_values: check_values,
|
67
|
+
check_order: check_order,
|
68
|
+
check_count: check_count)
|
69
|
+
end).compact
|
70
|
+
return false if matches.length == 0
|
71
|
+
if check_order == true
|
72
|
+
return false if (i != 0 && matches.map{|x| previous_matches.map{|y| y > x}.all?}.all?)
|
73
|
+
previous_matches = matches
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
elsif expected_body != received_body
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
return true
|
81
|
+
end
|
82
|
+
|
83
|
+
# Class method which takes a URL, downloads the file (if not already downloaded
|
84
|
+
# for this test session) and returns the path of the file.
|
85
|
+
# @param [String] The URL of the required file.
|
86
|
+
def self.get_file(url)
|
87
|
+
unless @cache.keys.include? url
|
88
|
+
@cache[url] = Tempfile.new('APIMatic')
|
89
|
+
@cache[url].binmode
|
90
|
+
@cache[url].write(open(url, {ssl_ca_cert: Certifi.where}).read)
|
91
|
+
end
|
92
|
+
return @cache[url].path
|
93
|
+
end
|
94
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: automation-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.23'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- APIMatic SDK Generator
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|
@@ -92,7 +92,41 @@ dependencies:
|
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '2.2'
|
95
|
-
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: minitest
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '5.14'
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 5.14.1
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '5.14'
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 5.14.1
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: minitest-proveit
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "~>"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '1.0'
|
122
|
+
type: :development
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - "~>"
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '1.0'
|
129
|
+
description: Simple calculator API hosted on APIMATIC
|
96
130
|
email: support@apimatic.io
|
97
131
|
executables: []
|
98
132
|
extensions: []
|
@@ -117,6 +151,10 @@ files:
|
|
117
151
|
- lib/apimatic_calculator/models/operation_type_enum.rb
|
118
152
|
- lib/apimatic_calculator/utilities/date_time_helper.rb
|
119
153
|
- lib/apimatic_calculator/utilities/file_wrapper.rb
|
154
|
+
- test/controllers/controller_test_base.rb
|
155
|
+
- test/controllers/test_simple_calculator_controller.rb
|
156
|
+
- test/http_response_catcher.rb
|
157
|
+
- test/test_helper.rb
|
120
158
|
homepage: https://apimatic.io
|
121
159
|
licenses:
|
122
160
|
- MIT
|