fakturoid 0.3.0 → 0.4.0
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/.github/workflows/rubocop.yml +20 -0
- data/.github/workflows/tests.yml +27 -0
- data/.rubocop.yml +54 -12
- data/.ruby-version +1 -1
- data/CHANGELOG.md +33 -0
- data/Gemfile +3 -1
- data/README.md +39 -31
- data/lib/fakturoid/api/arguments.rb +3 -1
- data/lib/fakturoid/api/http_methods.rb +2 -0
- data/lib/fakturoid/api.rb +4 -2
- data/lib/fakturoid/client/account.rb +3 -1
- data/lib/fakturoid/client/bank_account.rb +3 -1
- data/lib/fakturoid/client/event.rb +4 -2
- data/lib/fakturoid/client/expense.rb +11 -5
- data/lib/fakturoid/client/generator.rb +6 -4
- data/lib/fakturoid/client/invoice.rb +18 -10
- data/lib/fakturoid/client/number_format.rb +11 -0
- data/lib/fakturoid/client/subject.rb +10 -4
- data/lib/fakturoid/client/todo.rb +3 -1
- data/lib/fakturoid/client/user.rb +4 -2
- data/lib/fakturoid/client.rb +12 -9
- data/lib/fakturoid/config.rb +14 -2
- data/lib/fakturoid/connection.rb +11 -3
- data/lib/fakturoid/railtie.rb +2 -0
- data/lib/fakturoid/request.rb +5 -2
- data/lib/fakturoid/response.rb +21 -19
- data/lib/fakturoid/version.rb +3 -1
- data/lib/fakturoid.rb +14 -12
- data/test/api_test.rb +12 -10
- data/test/config_test.rb +23 -21
- data/test/request_test.rb +8 -6
- data/test/response_test.rb +68 -66
- data/test/test_helper.rb +8 -6
- metadata +9 -7
- data/.circleci/config.yml +0 -15
data/test/response_test.rb
CHANGED
@@ -1,187 +1,189 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
2
4
|
|
3
5
|
class Fakturoid::ResponseTest < Fakturoid::TestCase
|
4
|
-
should
|
5
|
-
json = load_fixture(
|
6
|
+
should "should return json invoice" do
|
7
|
+
json = load_fixture("invoice.json")
|
6
8
|
test_connection = Faraday.new do |builder|
|
7
9
|
builder.adapter :test do |stub|
|
8
|
-
stub.get(
|
10
|
+
stub.get("invoices/5.json") { |_env| [200, { content_type: "application/json" }, json] }
|
9
11
|
end
|
10
|
-
builder.headers = { content_type:
|
12
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
11
13
|
end
|
12
14
|
|
13
|
-
response = Fakturoid::Response.new(test_connection.get(
|
15
|
+
response = Fakturoid::Response.new(test_connection.get("invoices/5.json"), Fakturoid::Client::Invoice, :get)
|
14
16
|
assert response.json?
|
15
17
|
assert_equal 200, response.status_code
|
16
18
|
assert_equal 5, response.id
|
17
|
-
assert_equal 5, response.body[
|
19
|
+
assert_equal 5, response.body["id"]
|
18
20
|
assert response.respond_to?(:body)
|
19
21
|
assert response.respond_to?(:id)
|
20
22
|
assert_raises(NoMethodError) { response.name }
|
21
23
|
end
|
22
24
|
|
23
|
-
context
|
24
|
-
should
|
25
|
+
context "Exceptions" do
|
26
|
+
should "raise user agent error" do
|
25
27
|
test_connection = Faraday.new do |builder|
|
26
28
|
builder.adapter :test do |stub|
|
27
|
-
stub.get(
|
29
|
+
stub.get("invoices/5.json") { |_env| [400, { content_type: "application/json" }, " "] }
|
28
30
|
end
|
29
|
-
builder.headers = { content_type:
|
31
|
+
builder.headers = { content_type: "application/json", user_agent: "" }
|
30
32
|
end
|
31
33
|
|
32
|
-
assert_raises(Fakturoid::UserAgentError) { Fakturoid::Response.new(test_connection.get(
|
34
|
+
assert_raises(Fakturoid::UserAgentError) { Fakturoid::Response.new(test_connection.get("invoices/5.json"), Fakturoid::Client::Invoice, :get) }
|
33
35
|
end
|
34
36
|
|
35
|
-
should
|
37
|
+
should "raise pagination error" do
|
36
38
|
test_connection = Faraday.new do |builder|
|
37
39
|
builder.adapter :test do |stub|
|
38
|
-
stub.get(
|
40
|
+
stub.get("invoices.json?page=4") { |_env| [400, { content_type: "application/json" }, " "] }
|
39
41
|
end
|
40
|
-
builder.headers = { content_type:
|
42
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
41
43
|
end
|
42
44
|
|
43
|
-
assert_raises(Fakturoid::PaginationError) { Fakturoid::Response.new(test_connection.get(
|
45
|
+
assert_raises(Fakturoid::PaginationError) { Fakturoid::Response.new(test_connection.get("invoices.json?page=4"), Fakturoid::Client::Invoice, :get) }
|
44
46
|
end
|
45
47
|
|
46
|
-
should
|
48
|
+
should "raise authentication error" do
|
47
49
|
test_connection = Faraday.new do |builder|
|
48
50
|
builder.adapter :test do |stub|
|
49
|
-
stub.get(
|
51
|
+
stub.get("invoices.json?page=4") { |_env| [401, { content_type: "application/json" }, " "] }
|
50
52
|
end
|
51
|
-
builder.headers = { content_type:
|
53
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
52
54
|
end
|
53
55
|
|
54
|
-
assert_raises(Fakturoid::AuthenticationError) { Fakturoid::Response.new(test_connection.get(
|
56
|
+
assert_raises(Fakturoid::AuthenticationError) { Fakturoid::Response.new(test_connection.get("invoices.json?page=4"), Fakturoid::Client::Invoice, :get) }
|
55
57
|
end
|
56
58
|
|
57
|
-
should
|
58
|
-
json = load_fixture(
|
59
|
+
should "raise blocked account error" do
|
60
|
+
json = load_fixture("blocked_account.json")
|
59
61
|
test_connection = Faraday.new do |builder|
|
60
62
|
builder.adapter :test do |stub|
|
61
|
-
stub.get(
|
63
|
+
stub.get("account.json") { |_env| [402, { content_type: "application/json" }, json] }
|
62
64
|
end
|
63
|
-
builder.headers = { content_type:
|
65
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
64
66
|
end
|
65
67
|
|
66
68
|
begin
|
67
|
-
Fakturoid::Response.new(test_connection.get(
|
69
|
+
Fakturoid::Response.new(test_connection.get("account.json"), Fakturoid::Client::Account, :get)
|
68
70
|
rescue Fakturoid::BlockedAccountError => e
|
69
71
|
assert_equal 402, e.response_code
|
70
|
-
assert e.response_body.key?(
|
72
|
+
assert e.response_body.key?("status")
|
71
73
|
rescue => e
|
72
74
|
assert false, "Raised exception was not expected: #{e.class}"
|
73
75
|
else
|
74
|
-
assert false,
|
76
|
+
assert false, "Exception was expected"
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
78
|
-
should
|
80
|
+
should "raise destroy subject error" do
|
79
81
|
test_connection = Faraday.new do |builder|
|
80
82
|
builder.adapter :test do |stub|
|
81
|
-
stub.delete(
|
83
|
+
stub.delete("subjects/5.json") { |_env| [403, { content_type: "application/json" }, " "] }
|
82
84
|
end
|
83
|
-
builder.headers = { content_type:
|
85
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
84
86
|
end
|
85
87
|
|
86
|
-
assert_raises(Fakturoid::DestroySubjectError) { Fakturoid::Response.new(test_connection.delete(
|
88
|
+
assert_raises(Fakturoid::DestroySubjectError) { Fakturoid::Response.new(test_connection.delete("subjects/5.json"), Fakturoid::Client::Subject, :delete) }
|
87
89
|
end
|
88
90
|
|
89
|
-
should
|
91
|
+
should "raise subject limit error" do
|
90
92
|
test_connection = Faraday.new do |builder|
|
91
93
|
builder.adapter :test do |stub|
|
92
|
-
stub.post(
|
94
|
+
stub.post("subjects.json") { |_env| [403, { content_type: "application/json" }, " "] }
|
93
95
|
end
|
94
|
-
builder.headers = { content_type:
|
96
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
95
97
|
end
|
96
98
|
|
97
|
-
assert_raises(Fakturoid::SubjectLimitError) { Fakturoid::Response.new(test_connection.post(
|
99
|
+
assert_raises(Fakturoid::SubjectLimitError) { Fakturoid::Response.new(test_connection.post("subjects.json", name: "Customer s.r.o."), Fakturoid::Client::Subject, :post) }
|
98
100
|
end
|
99
101
|
|
100
|
-
should
|
102
|
+
should "raise generator limit error" do
|
101
103
|
test_connection = Faraday.new do |builder|
|
102
104
|
builder.adapter :test do |stub|
|
103
|
-
stub.post(
|
105
|
+
stub.post("generators.json") { |_env| [403, { content_type: "application/json" }, " "] }
|
104
106
|
end
|
105
|
-
builder.headers = { content_type:
|
107
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
106
108
|
end
|
107
109
|
|
108
|
-
assert_raises(Fakturoid::GeneratorLimitError) { Fakturoid::Response.new(test_connection.post(
|
110
|
+
assert_raises(Fakturoid::GeneratorLimitError) { Fakturoid::Response.new(test_connection.post("generators.json", name: "Customer s.r.o.", recurring: true), Fakturoid::Client::Generator, :post) }
|
109
111
|
end
|
110
112
|
|
111
|
-
should
|
113
|
+
should "raise unsupported feature error" do
|
112
114
|
test_connection = Faraday.new do |builder|
|
113
115
|
builder.adapter :test do |stub|
|
114
|
-
stub.post(
|
116
|
+
stub.post("invoices/5/message.json") { |_env| [403, { content_type: "application/json" }, " "] }
|
115
117
|
end
|
116
|
-
builder.headers = { content_type:
|
118
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
117
119
|
end
|
118
120
|
|
119
|
-
assert_raises(Fakturoid::UnsupportedFeatureError) { Fakturoid::Response.new(test_connection.post(
|
121
|
+
assert_raises(Fakturoid::UnsupportedFeatureError) { Fakturoid::Response.new(test_connection.post("invoices/5/message.json", email: "customer@email.cz"), Fakturoid::Client::Invoice, :post) }
|
120
122
|
end
|
121
123
|
|
122
|
-
should
|
124
|
+
should "raise record not found error" do
|
123
125
|
test_connection = Faraday.new do |builder|
|
124
126
|
builder.adapter :test do |stub|
|
125
|
-
stub.get(
|
127
|
+
stub.get("invoices/10.json") { |_env| [404, { content_type: "application/json" }, " "] }
|
126
128
|
end
|
127
|
-
builder.headers = { content_type:
|
129
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
128
130
|
end
|
129
131
|
|
130
|
-
assert_raises(Fakturoid::RecordNotFoundError) { Fakturoid::Response.new(test_connection.get(
|
132
|
+
assert_raises(Fakturoid::RecordNotFoundError) { Fakturoid::Response.new(test_connection.get("invoices/10.json"), Fakturoid::Client::Invoice, :get) }
|
131
133
|
end
|
132
134
|
|
133
|
-
should
|
135
|
+
should "raise content type error" do
|
134
136
|
test_connection = Faraday.new do |builder|
|
135
137
|
builder.adapter :test do |stub|
|
136
|
-
stub.get(
|
138
|
+
stub.get("invoices/5.xml") { |_env| [415, { content_type: "application/xml" }, " "] }
|
137
139
|
end
|
138
|
-
builder.headers = { content_type:
|
140
|
+
builder.headers = { content_type: "application/xml", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
139
141
|
end
|
140
142
|
|
141
|
-
assert_raises(Fakturoid::ContentTypeError) { Fakturoid::Response.new(test_connection.get(
|
143
|
+
assert_raises(Fakturoid::ContentTypeError) { Fakturoid::Response.new(test_connection.get("invoices/5.xml"), Fakturoid::Client::Invoice, :get) }
|
142
144
|
end
|
143
145
|
|
144
|
-
should
|
145
|
-
json = load_fixture(
|
146
|
+
should "raise invalid record error" do
|
147
|
+
json = load_fixture("invoice_error.json")
|
146
148
|
test_connection = Faraday.new do |builder|
|
147
149
|
builder.adapter :test do |stub|
|
148
|
-
stub.patch(
|
150
|
+
stub.patch("invoice/5.json") { |_env| [422, { content_type: "application/json" }, json] }
|
149
151
|
end
|
150
|
-
builder.headers = { content_type:
|
152
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
151
153
|
end
|
152
154
|
|
153
155
|
begin
|
154
|
-
Fakturoid::Response.new(test_connection.patch(
|
156
|
+
Fakturoid::Response.new(test_connection.patch("invoice/5.json"), Fakturoid::Client::Invoice, :patch)
|
155
157
|
rescue Fakturoid::InvalidRecordError => e
|
156
158
|
assert_equal 422, e.response_code
|
157
|
-
assert e.response_body.key?(
|
159
|
+
assert e.response_body.key?("errors")
|
158
160
|
rescue => e
|
159
161
|
assert false, "Raised exception was not expected: #{e.class}"
|
160
162
|
else
|
161
|
-
assert false,
|
163
|
+
assert false, "Exception was expected"
|
162
164
|
end
|
163
165
|
end
|
164
166
|
|
165
|
-
should
|
167
|
+
should "raise rate limit error" do
|
166
168
|
test_connection = Faraday.new do |builder|
|
167
169
|
builder.adapter :test do |stub|
|
168
|
-
stub.get(
|
170
|
+
stub.get("invoices/5.json") { |_env| [429, { content_type: "application/json" }, " "] }
|
169
171
|
end
|
170
|
-
builder.headers = { content_type:
|
172
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
171
173
|
end
|
172
174
|
|
173
|
-
assert_raises(Fakturoid::RateLimitError) { Fakturoid::Response.new(test_connection.get(
|
175
|
+
assert_raises(Fakturoid::RateLimitError) { Fakturoid::Response.new(test_connection.get("invoices/5.json"), Fakturoid::Client::Invoice, :get) }
|
174
176
|
end
|
175
177
|
|
176
|
-
should
|
178
|
+
should "raise read only site error" do
|
177
179
|
test_connection = Faraday.new do |builder|
|
178
180
|
builder.adapter :test do |stub|
|
179
|
-
stub.delete(
|
181
|
+
stub.delete("invoices/5.json") { |_env| [503, { content_type: "application/json" }, " "] }
|
180
182
|
end
|
181
|
-
builder.headers = { content_type:
|
183
|
+
builder.headers = { content_type: "application/json", user_agent: "Fakturoid gem (email@testmail.cz)" }
|
182
184
|
end
|
183
185
|
|
184
|
-
assert_raises(Fakturoid::ReadOnlySiteError) { Fakturoid::Response.new(test_connection.delete(
|
186
|
+
assert_raises(Fakturoid::ReadOnlySiteError) { Fakturoid::Response.new(test_connection.delete("invoices/5.json"), Fakturoid::Client::Invoice, :delete) }
|
185
187
|
end
|
186
188
|
end
|
187
189
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "minitest/autorun"
|
4
|
+
require "mocha/minitest"
|
5
|
+
require "shoulda-context"
|
6
|
+
require "pathname"
|
7
|
+
require "fakturoid"
|
6
8
|
|
7
9
|
module Fakturoid
|
8
10
|
class TestCase < Minitest::Test
|
@@ -11,7 +13,7 @@ module Fakturoid
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def load_fixture(file_name)
|
14
|
-
File.read(test_path.join(
|
16
|
+
File.read(test_path.join("fixtures", file_name))
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakturoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eda Riedl
|
8
8
|
- Lukáš Konarovský
|
9
9
|
- Oldřich Vetešník
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-03-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -131,7 +131,8 @@ executables: []
|
|
131
131
|
extensions: []
|
132
132
|
extra_rdoc_files: []
|
133
133
|
files:
|
134
|
-
- ".
|
134
|
+
- ".github/workflows/rubocop.yml"
|
135
|
+
- ".github/workflows/tests.yml"
|
135
136
|
- ".gitignore"
|
136
137
|
- ".rubocop.yml"
|
137
138
|
- ".ruby-version"
|
@@ -152,6 +153,7 @@ files:
|
|
152
153
|
- lib/fakturoid/client/expense.rb
|
153
154
|
- lib/fakturoid/client/generator.rb
|
154
155
|
- lib/fakturoid/client/invoice.rb
|
156
|
+
- lib/fakturoid/client/number_format.rb
|
155
157
|
- lib/fakturoid/client/subject.rb
|
156
158
|
- lib/fakturoid/client/todo.rb
|
157
159
|
- lib/fakturoid/client/user.rb
|
@@ -175,7 +177,7 @@ homepage: https://github.com/fakturoid/fakturoid-ruby
|
|
175
177
|
licenses:
|
176
178
|
- MIT
|
177
179
|
metadata: {}
|
178
|
-
post_install_message:
|
180
|
+
post_install_message:
|
179
181
|
rdoc_options: []
|
180
182
|
require_paths:
|
181
183
|
- lib
|
@@ -190,8 +192,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
192
|
- !ruby/object:Gem::Version
|
191
193
|
version: '0'
|
192
194
|
requirements: []
|
193
|
-
rubygems_version: 3.
|
194
|
-
signing_key:
|
195
|
+
rubygems_version: 3.2.32
|
196
|
+
signing_key:
|
195
197
|
specification_version: 4
|
196
198
|
summary: Ruby client for web based invoicing service www.fakturoid.cz
|
197
199
|
test_files:
|
data/.circleci/config.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
version: 2
|
2
|
-
jobs:
|
3
|
-
build:
|
4
|
-
docker:
|
5
|
-
- image: circleci/ruby:2.6.3
|
6
|
-
environment:
|
7
|
-
TZ: /usr/share/zoneinfo/Europe/Prague
|
8
|
-
steps:
|
9
|
-
- checkout
|
10
|
-
- run:
|
11
|
-
name: Install gems
|
12
|
-
command: bundle install --path=vendor/bundle --jobs=4 --retry=3
|
13
|
-
- run:
|
14
|
-
name: Run tests
|
15
|
-
command: bundle exec rake test
|