ey_services_api 0.3.15 → 0.3.16

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.
@@ -6,6 +6,7 @@ gemspec
6
6
  group :test, :development do
7
7
  gemspec :path => "fake"
8
8
  gem 'rake'
9
+ gem 'timecop'
9
10
 
10
11
  #private Gem deps of fake_awsm
11
12
  gem 'ey_sso', :git => "git@github.com:engineyard/ey_sso.git", :ref => "v0.13.1"
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gemspec
5
5
 
6
6
  group :test, :development do
7
7
  gemspec :path => "fake"
8
+ gem 'timecop'
8
9
 
9
10
  gem 'rake'
10
11
  gem 'guard-rspec'
@@ -63,6 +63,22 @@ module EY
63
63
  post(invoices_url, :invoice => invoice.to_hash)
64
64
  end
65
65
 
66
+ def list_invoices(invoices_url)
67
+ get(invoices_url) do |json_body, response_location|
68
+ json_body.map do |json_item|
69
+ invoice = Invoice.new(json_item["invoice"])
70
+ invoice.connection = self
71
+ invoice.url = json_item["invoice"]["url"]
72
+ invoice.status = json_item["invoice"]["status"]
73
+ invoice
74
+ end
75
+ end
76
+ end
77
+
78
+ def destroy_invoice(url)
79
+ delete(url)
80
+ end
81
+
66
82
  end
67
83
  end
68
84
  end
@@ -1,6 +1,14 @@
1
1
  module EY
2
2
  module ServicesAPI
3
- class Invoice < APIStruct.new(:total_amount_cents, :line_item_description)
3
+ class Invoice < APIStruct.new(:total_amount_cents, :line_item_description, :unique_id)
4
+ attr_accessor :connection
5
+ attr_accessor :url
6
+ attr_accessor :status
7
+
8
+ def destroy
9
+ connection.destroy_invoice(self.url)
10
+ end
11
+
4
12
  end
5
13
  end
6
14
  end
@@ -1,5 +1,5 @@
1
1
  module EY
2
2
  module ServicesAPI
3
- VERSION = "0.3.15"
3
+ VERSION = "0.3.16"
4
4
  end
5
5
  end
@@ -1,11 +1,16 @@
1
1
  #because there may be multiple 'spec_helper' in load path when running from external test helper
2
2
  require File.expand_path('../spec_helper.rb', __FILE__)
3
+ require 'timecop'
3
4
 
4
5
  describe EY::ServicesAPI::Invoice do
5
6
  before do
6
7
  @service_account = @tresfiestas.service_account
7
8
  @invoices_url = @service_account[:invoices_url]
8
9
  @connection = EY::ServicesAPI.connection
10
+ Timecop.return
11
+ end
12
+ after do
13
+ Timecop.return
9
14
  end
10
15
 
11
16
  it "can send an invoice" do
@@ -17,6 +22,104 @@ describe EY::ServicesAPI::Invoice do
17
22
  latest_invoice[:service_account_id].should eq @service_account[:id]
18
23
  end
19
24
 
25
+ it "duplicate blank uniq identifiers don't cause conflicts" do
26
+ invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => 500, :line_item_description => "good stuff", :unique_id => "")
27
+ @connection.send_invoice(@invoices_url, invoice)
28
+ invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => 5000, :line_item_description => "duplicate stuff ok", :unique_id => "")
29
+ @connection.send_invoice(@invoices_url, invoice)
30
+ end
31
+
32
+ internal_only_tests do
33
+
34
+ it "can send an invoice with uniq identifier, returns error for duplicates" do
35
+ invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => 500, :line_item_description => "good stuff", :unique_id => "ABCDEFG123")
36
+ @connection.send_invoice(@invoices_url, invoice)
37
+ lambda{
38
+ invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => 5000, :line_item_description => "duplicate stuff BAD", :unique_id => "ABCDEFG123")
39
+ @connection.send_invoice(@invoices_url, invoice)
40
+ }.should raise_error(EY::ServicesAPI::Connection::ValidationError, /Unique ID already exists on another invoice on this account/)
41
+ end
42
+
43
+ end
44
+
45
+ it "can list invoices, can delete pending invoices" do
46
+ invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => 500, :line_item_description => "good stuff", :unique_id => 123)
47
+ @connection.send_invoice(@invoices_url, invoice)
48
+ invoices = @connection.list_invoices(@invoices_url)
49
+ invoices.size.should eq 1
50
+ invoice = invoices.first
51
+ invoice.total_amount_cents.should eq 500
52
+ invoice.line_item_description.should eq "good stuff"
53
+ invoice.unique_id.should eq "123"
54
+ invoice.status.should eq "pending"
55
+ invoice.destroy
56
+ @connection.list_invoices(@invoices_url).size.should eq 0
57
+ end
58
+
59
+ internal_only_tests do
60
+
61
+ it "can list invoices, can delete pending invoices on the first of the month" do
62
+ Timecop.travel(Time.now.beginning_of_month + 12.hours)
63
+ invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => 500, :line_item_description => "good stuff", :unique_id => 123)
64
+ @connection.send_invoice(@invoices_url, invoice)
65
+ invoices = @connection.list_invoices(@invoices_url)
66
+ invoices.size.should eq 1
67
+ invoice = invoices.first
68
+ invoice.total_amount_cents.should eq 500
69
+ invoice.line_item_description.should eq "good stuff"
70
+ invoice.unique_id.should eq "123"
71
+ invoice.status.should eq "pending"
72
+ invoice.destroy
73
+ @connection.list_invoices(@invoices_url).size.should eq 0
74
+ end
75
+
76
+ it "invoices become locked 24 hours after the account is canceled, can't be deleted" do
77
+ @tresfiestas.destroy_service_account
78
+ invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => 500, :line_item_description => "good stuff", :unique_id => 123)
79
+ @connection.send_invoice(@invoices_url, invoice)
80
+ Timecop.travel(Time.now + 1.day + 1.minute)
81
+ invoices = @connection.list_invoices(@invoices_url)
82
+ invoices.size.should eq 1
83
+ invoice = invoices.first
84
+ invoice.total_amount_cents.should eq 500
85
+ invoice.line_item_description.should eq "good stuff"
86
+ invoice.unique_id.should eq "123"
87
+ invoice.status.should eq "locked"
88
+ lambda{
89
+ invoice.destroy
90
+ }.should raise_error(EY::ServicesAPI::Connection::ValidationError, /cannot delete locked invoices/)
91
+ end
92
+
93
+ it "invoices become locked 24 after end of month, and 24 hours after the account is canceled, can't be deleted" do
94
+ invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => 500, :line_item_description => "good stuff", :unique_id => 123)
95
+ @connection.send_invoice(@invoices_url, invoice)
96
+ Timecop.travel(Time.now.end_of_month + 1.day + 1.minute)
97
+ invoices = @connection.list_invoices(@invoices_url)
98
+ invoices.size.should eq 1
99
+ invoice = invoices.first
100
+ invoice.total_amount_cents.should eq 500
101
+ invoice.line_item_description.should eq "good stuff"
102
+ invoice.unique_id.should eq "123"
103
+ invoice.status.should eq "locked"
104
+ lambda{
105
+ invoice.destroy
106
+ }.should raise_error(EY::ServicesAPI::Connection::ValidationError, /cannot delete locked invoices/)
107
+ end
108
+
109
+ it "returns an error when posting invoices to canceled service accounts" do
110
+ @tresfiestas.destroy_service_account
111
+ invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => 500, :line_item_description => "good stuff")
112
+ @connection.send_invoice(@invoices_url, invoice)
113
+
114
+ Timecop.travel(Time.now + 1.day + 1.minute)
115
+ lambda{
116
+ invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => 500, :line_item_description => "good stuff")
117
+ @connection.send_invoice(@invoices_url, invoice)
118
+ }.should raise_error(EY::ServicesAPI::Connection::ValidationError, /Account is no longer active, and cannot accept any invoices/)
119
+ end
120
+
121
+ end
122
+
20
123
  it "returns an error for fractional ammounts for total_amount_cents" do
21
124
  lambda{
22
125
  invoice = EY::ServicesAPI::Invoice.new(:total_amount_cents => 4.50, :line_item_description => "fractional stuff")
@@ -16,3 +16,9 @@ RSpec.configure do |config|
16
16
  @tresfiestas = EY::ServicesAPI.mock_backend
17
17
  end
18
18
  end
19
+
20
+ def internal_only_tests
21
+ if ENV["BUNDLE_GEMFILE"] == "EYIntegratedGemfile"
22
+ yield
23
+ end
24
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ey_services_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 15
10
- version: 0.3.15
9
+ - 16
10
+ version: 0.3.16
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jacob & Thorben & David & mkb & Josh & Others
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-07 00:00:00 Z
18
+ date: 2012-11-01 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  requirements: []
148
148
 
149
149
  rubyforge_project: ey_services_api
150
- rubygems_version: 1.8.10
150
+ rubygems_version: 1.8.24
151
151
  signing_key:
152
152
  specification_version: 3
153
153
  summary: API for Partner Services (talks to services.engineyard.com)