pactas_itero 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +60 -40
- data/README.md +3 -1
- data/Rakefile +4 -4
- data/bin/setup +7 -0
- data/lib/pactas_itero/api/contracts.rb +5 -0
- data/lib/pactas_itero/api/invoices.rb +1 -2
- data/lib/pactas_itero/api/oauth.rb +2 -3
- data/lib/pactas_itero/api/rated_items.rb +1 -1
- data/lib/pactas_itero/api.rb +7 -7
- data/lib/pactas_itero/client.rb +26 -22
- data/lib/pactas_itero/configurable.rb +5 -6
- data/lib/pactas_itero/default.rb +11 -14
- data/lib/pactas_itero/error.rb +12 -15
- data/lib/pactas_itero/ext/hash/camelize_keys.rb +7 -8
- data/lib/pactas_itero/response/raise_error.rb +2 -4
- data/lib/pactas_itero/version.rb +1 -1
- data/lib/pactas_itero.rb +2 -2
- data/pactas_itero.gemspec +18 -18
- data/spec/fixtures/contract_changes.json +22 -0
- data/spec/pactas_itero/api/contracts_spec.rb +85 -57
- data/spec/pactas_itero/api/customers_spec.rb +101 -99
- data/spec/pactas_itero/api/invoices_spec.rb +55 -55
- data/spec/pactas_itero/api/orders_spec.rb +42 -42
- data/spec/pactas_itero/api/rated_items_spec.rb +42 -42
- data/spec/pactas_itero/client_spec.rb +46 -50
- data/spec/pactas_itero_spec.rb +1 -3
- data/spec/spec_helper.rb +12 -12
- data/yarn-error.log +43 -0
- metadata +17 -12
@@ -1,27 +1,27 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe PactasItero::Api::Invoices do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
client = PactasItero::Client.new(bearer_token:
|
7
|
-
request = stub_get(
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
describe ".invoices" do
|
5
|
+
it "requests the correct resource" do
|
6
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
7
|
+
request = stub_get("/api/v1/invoices").
|
8
|
+
to_return(
|
9
|
+
body: fixture("invoices.json"),
|
10
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
11
|
+
)
|
12
12
|
|
13
13
|
client.invoices
|
14
14
|
|
15
15
|
expect(request).to have_been_made
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
client = PactasItero::Client.new(bearer_token:
|
20
|
-
request = stub_get(
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
it "returns an array of contracts" do
|
19
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
20
|
+
request = stub_get("/api/v1/invoices").
|
21
|
+
to_return(
|
22
|
+
body: fixture("invoices.json"),
|
23
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
24
|
+
)
|
25
25
|
|
26
26
|
invoices = client.invoices
|
27
27
|
|
@@ -29,72 +29,72 @@ describe PactasItero::Api::Invoices do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
33
|
-
it
|
34
|
-
client = PactasItero::Client.new(bearer_token:
|
35
|
-
request = stub_get(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
describe ".invoices_from" do
|
33
|
+
it "requests the correct resource" do
|
34
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
35
|
+
request = stub_get("/api/v1/invoices?from=54b67d9e995ec90bc8f37718").
|
36
|
+
to_return(
|
37
|
+
body: fixture("invoices.json"),
|
38
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
39
|
+
)
|
40
40
|
|
41
|
-
client.invoices_from(
|
41
|
+
client.invoices_from("54b67d9e995ec90bc8f37718")
|
42
42
|
|
43
43
|
expect(request).to have_been_made
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
47
|
-
client = PactasItero::Client.new(bearer_token:
|
48
|
-
request = stub_get(
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
it "requests the correct resource, if from parameter is nil" do
|
47
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
48
|
+
request = stub_get("/api/v1/invoices").
|
49
|
+
to_return(
|
50
|
+
body: fixture("invoices.json"),
|
51
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
52
|
+
)
|
53
53
|
|
54
54
|
client.invoices_from(nil)
|
55
55
|
|
56
56
|
expect(request).to have_been_made
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
60
|
-
client = PactasItero::Client.new(bearer_token:
|
61
|
-
request = stub_get(
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
it "returns an array of contracts" do
|
60
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
61
|
+
request = stub_get("/api/v1/invoices?from=54b67d9e995ec90bc8f37718").
|
62
|
+
to_return(
|
63
|
+
body: fixture("invoices.json"),
|
64
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
65
|
+
)
|
66
66
|
|
67
|
-
invoices = client.invoices_from(
|
67
|
+
invoices = client.invoices_from("54b67d9e995ec90bc8f37718")
|
68
68
|
|
69
69
|
expect(invoices).to be_a Array
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
describe
|
74
|
-
it
|
75
|
-
client = PactasItero::Client.new(bearer_token:
|
76
|
-
request = stub_get(
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
73
|
+
describe ".invoice" do
|
74
|
+
it "requests the correct resource" do
|
75
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
76
|
+
request = stub_get("/api/v1/invoices/54b67d9e995ec90bc8f37718").
|
77
|
+
to_return(
|
78
|
+
body: fixture("invoice.json"),
|
79
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
80
|
+
)
|
81
81
|
|
82
|
-
client.invoice(
|
82
|
+
client.invoice("54b67d9e995ec90bc8f37718")
|
83
83
|
|
84
84
|
expect(request).to have_been_made
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
describe
|
88
|
+
describe ".invoice_download" do
|
89
89
|
it "returns the pdf as a string after requesting the correct resource" do
|
90
|
-
client = PactasItero::Client.new(bearer_token:
|
91
|
-
request = stub_get(
|
90
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
91
|
+
request = stub_get("/api/v1/invoices/54b67d9e995ec90bc8f37718/download").
|
92
92
|
to_return(
|
93
|
-
body: fixture(
|
94
|
-
headers: { content_type:
|
93
|
+
body: fixture("invoice_download.pdf"),
|
94
|
+
headers: { content_type: "application/pdf" },
|
95
95
|
)
|
96
96
|
|
97
|
-
response = client.invoice_download(
|
97
|
+
response = client.invoice_download("54b67d9e995ec90bc8f37718")
|
98
98
|
|
99
99
|
expect(request).to have_been_made
|
100
100
|
expect(response.class).to be String
|
@@ -1,69 +1,69 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe PactasItero::Api::Orders do
|
4
4
|
describe ".create_order" do
|
5
5
|
it "requests the correct resource" do
|
6
|
-
client = PactasItero::Client.new(bearer_token:
|
6
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
7
7
|
post_data = {
|
8
8
|
ContractId: "5370e5ab9e40071fd01e01e0",
|
9
9
|
Cart: {
|
10
|
-
PlanVariantId: "525bf9089e40073a58590fd5"
|
11
|
-
}
|
10
|
+
PlanVariantId: "525bf9089e40073a58590fd5",
|
11
|
+
},
|
12
12
|
}.to_json
|
13
|
-
request = stub_post(
|
13
|
+
request = stub_post("/api/v1/orders").
|
14
14
|
with(body: post_data).
|
15
15
|
to_return(
|
16
|
-
body: fixture(
|
17
|
-
headers: { content_type:
|
16
|
+
body: fixture("create_order_response.json"),
|
17
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
18
18
|
)
|
19
19
|
|
20
20
|
client.create_order(
|
21
21
|
contract_id: "5370e5ab9e40071fd01e01e0",
|
22
22
|
cart: {
|
23
|
-
plan_variant_id: "525bf9089e40073a58590fd5"
|
24
|
-
}
|
23
|
+
plan_variant_id: "525bf9089e40073a58590fd5",
|
24
|
+
},
|
25
25
|
)
|
26
26
|
|
27
27
|
expect(request).to have_been_made
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
31
|
-
client = PactasItero::Client.new(bearer_token:
|
30
|
+
it "returns the created order" do
|
31
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
32
32
|
post_data = {
|
33
33
|
ContractId: "5370e5ab9e40071fd01e01e0",
|
34
34
|
Cart: {
|
35
|
-
PlanVariantId: "525bf9089e40073a58590fd5"
|
36
|
-
}
|
35
|
+
PlanVariantId: "525bf9089e40073a58590fd5",
|
36
|
+
},
|
37
37
|
}.to_json
|
38
|
-
request = stub_post(
|
38
|
+
request = stub_post("/api/v1/orders").
|
39
39
|
with(body: post_data).
|
40
40
|
to_return(
|
41
|
-
body: fixture(
|
42
|
-
headers: { content_type:
|
41
|
+
body: fixture("create_order_response.json"),
|
42
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
43
43
|
)
|
44
44
|
|
45
45
|
order = client.create_order(
|
46
46
|
contract_id: "5370e5ab9e40071fd01e01e0",
|
47
47
|
cart: {
|
48
|
-
plan_variant_id: "525bf9089e40073a58590fd5"
|
49
|
-
}
|
48
|
+
plan_variant_id: "525bf9089e40073a58590fd5",
|
49
|
+
},
|
50
50
|
)
|
51
51
|
|
52
|
-
expect(order.id).to eq
|
53
|
-
expect(order.contract_id).to eq
|
52
|
+
expect(order.id).to eq "537dfcab9e400760b4cd6347"
|
53
|
+
expect(order.contract_id).to eq "5370e5ab9e40071fd01e01e0"
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
describe
|
58
|
-
it
|
59
|
-
client = PactasItero::Client.new(bearer_token:
|
60
|
-
request = stub_get(
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
57
|
+
describe ".order" do
|
58
|
+
it "requests the correct resource" do
|
59
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
60
|
+
request = stub_get("/api/v1/orders/5357bc4f1d8dd00fa0db6c31").
|
61
|
+
to_return(
|
62
|
+
body: fixture("order.json"),
|
63
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
64
|
+
)
|
65
65
|
|
66
|
-
client.order(
|
66
|
+
client.order("5357bc4f1d8dd00fa0db6c31")
|
67
67
|
|
68
68
|
expect(request).to have_been_made
|
69
69
|
end
|
@@ -71,32 +71,32 @@ describe PactasItero::Api::Orders do
|
|
71
71
|
|
72
72
|
describe ".commit_order" do
|
73
73
|
it "requests the correct resource" do
|
74
|
-
client = PactasItero::Client.new(bearer_token:
|
75
|
-
request = stub_post(
|
74
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
75
|
+
request = stub_post("/api/v1/orders/537dfcab9e400760b4cd6347/commit").
|
76
76
|
with(body: {}.to_json).
|
77
77
|
to_return(
|
78
|
-
body: fixture(
|
79
|
-
headers: { content_type:
|
78
|
+
body: fixture("commit_order_response.json"),
|
79
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
80
80
|
)
|
81
81
|
|
82
|
-
client.commit_order(
|
82
|
+
client.commit_order("537dfcab9e400760b4cd6347")
|
83
83
|
|
84
84
|
expect(request).to have_been_made
|
85
85
|
end
|
86
86
|
|
87
|
-
it
|
88
|
-
client = PactasItero::Client.new(bearer_token:
|
89
|
-
request = stub_post(
|
87
|
+
it "returns the updated contract" do
|
88
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
89
|
+
request = stub_post("/api/v1/orders/537dfcab9e400760b4cd6347/commit").
|
90
90
|
with(body: {}.to_json).
|
91
91
|
to_return(
|
92
|
-
body: fixture(
|
93
|
-
headers: { content_type:
|
92
|
+
body: fixture("commit_order_response.json"),
|
93
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
94
94
|
)
|
95
95
|
|
96
|
-
contract = client.commit_order(
|
96
|
+
contract = client.commit_order("537dfcab9e400760b4cd6347")
|
97
97
|
|
98
|
-
expect(contract.id).to eq
|
99
|
-
expect(contract.current_phase.plan_variant_id).to eq
|
98
|
+
expect(contract.id).to eq "5370e5ab9e40071fd01e01e0"
|
99
|
+
expect(contract.current_phase.plan_variant_id).to eq "525bf9089e40073a58590fd5"
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -1,84 +1,84 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe PactasItero::Api::RatedItems do
|
4
4
|
describe ".create_rated_item" do
|
5
5
|
it "requests the correct resource" do
|
6
|
-
client = PactasItero::Client.new(bearer_token:
|
6
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
7
7
|
post_data = {
|
8
|
-
PeriodStart:
|
9
|
-
PeriodEnd:
|
8
|
+
PeriodStart: "2014-09-19T08:18:51.907Z",
|
9
|
+
PeriodEnd: "2014-09-19T08:19:51.907Z",
|
10
10
|
Quantity: 2,
|
11
|
-
Description:
|
11
|
+
Description: "the description",
|
12
12
|
PricePerUnit: 123.45,
|
13
|
-
TaxPolicyId:
|
13
|
+
TaxPolicyId: "tax-policy-id",
|
14
14
|
}.to_json
|
15
|
-
request = stub_post(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
request = stub_post("/api/v1/contracts/contract-id/ratedItems").
|
16
|
+
with(body: post_data).
|
17
|
+
to_return(
|
18
|
+
body: fixture("create_rated_item.json"),
|
19
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
20
|
+
)
|
21
21
|
|
22
22
|
client.create_rated_item(
|
23
|
-
|
23
|
+
"contract-id",
|
24
24
|
2,
|
25
|
-
|
25
|
+
"the description",
|
26
26
|
123.45,
|
27
|
-
|
27
|
+
"tax-policy-id",
|
28
28
|
{
|
29
29
|
period_start: "2014-09-19T08:18:51.907Z",
|
30
|
-
period_end: "2014-09-19T08:19:51.907Z"
|
31
|
-
}
|
30
|
+
period_end: "2014-09-19T08:19:51.907Z",
|
31
|
+
},
|
32
32
|
)
|
33
33
|
|
34
34
|
expect(request).to have_been_made
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
38
|
-
client = PactasItero::Client.new(bearer_token:
|
37
|
+
it "returns the created rated item" do
|
38
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
39
39
|
post_data = {
|
40
|
-
PeriodStart:
|
41
|
-
PeriodEnd:
|
40
|
+
PeriodStart: "2014-09-19T08:18:51.907Z",
|
41
|
+
PeriodEnd: "2014-09-19T08:19:51.907Z",
|
42
42
|
Quantity: 2,
|
43
|
-
Description:
|
43
|
+
Description: "the description",
|
44
44
|
PricePerUnit: 123.45,
|
45
|
-
TaxPolicyId:
|
45
|
+
TaxPolicyId: "tax-policy-id",
|
46
46
|
}.to_json
|
47
|
-
request = stub_post(
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
request = stub_post("/api/v1/contracts/contract-id/ratedItems").
|
48
|
+
with(body: post_data).
|
49
|
+
to_return(
|
50
|
+
body: fixture("create_rated_item.json"),
|
51
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
52
|
+
)
|
53
53
|
|
54
54
|
rated_item = client.create_rated_item(
|
55
|
-
|
55
|
+
"contract-id",
|
56
56
|
2,
|
57
|
-
|
57
|
+
"the description",
|
58
58
|
123.45,
|
59
|
-
|
59
|
+
"tax-policy-id",
|
60
60
|
{
|
61
61
|
period_start: "2014-09-19T08:18:51.907Z",
|
62
|
-
period_end: "2014-09-19T08:19:51.907Z"
|
63
|
-
}
|
62
|
+
period_end: "2014-09-19T08:19:51.907Z",
|
63
|
+
},
|
64
64
|
)
|
65
65
|
|
66
|
-
expect(rated_item.description).to eq
|
67
|
-
expect(rated_item.period_end).to eq
|
68
|
-
expect(rated_item.period_start).to eq
|
66
|
+
expect(rated_item.description).to eq "the description"
|
67
|
+
expect(rated_item.period_end).to eq "2014-09-19T08:18:51.907Z"
|
68
|
+
expect(rated_item.period_start).to eq "2014-09-19T08:18:51.907Z"
|
69
69
|
expect(rated_item.price_per_unit).to eq 123.45
|
70
70
|
expect(rated_item.quantity).to eq 2
|
71
|
-
expect(rated_item.tax_policy_id).to eq
|
71
|
+
expect(rated_item.tax_policy_id).to eq "tax-policy-id"
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
describe ".rated_items" do
|
76
76
|
it "returns rated items" do
|
77
|
-
client = PactasItero::Client.new(bearer_token:
|
77
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
78
78
|
stub_get("/api/v1/contracts/contract-id/ratedItems").
|
79
79
|
to_return(
|
80
80
|
body: fixture("rated_items.json"),
|
81
|
-
headers: { content_type: "application/json; charset=utf-8"}
|
81
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
82
82
|
)
|
83
83
|
|
84
84
|
rated_items = client.rated_items("contract-id")
|
@@ -98,11 +98,11 @@ describe PactasItero::Api::RatedItems do
|
|
98
98
|
|
99
99
|
describe ".delete_rated_item" do
|
100
100
|
it "deletes a rated item" do
|
101
|
-
client = PactasItero::Client.new(bearer_token:
|
101
|
+
client = PactasItero::Client.new(bearer_token: "bt")
|
102
102
|
stub_delete("/api/v1/ratedItems/rated-item-id").
|
103
103
|
to_return(
|
104
104
|
body: "",
|
105
|
-
headers: { content_type: "application/json; charset=utf-8"}
|
105
|
+
headers: { content_type: "application/json; charset=utf-8" },
|
106
106
|
)
|
107
107
|
|
108
108
|
response = client.delete_rated_item("rated-item-id")
|