slidepay 0.0.2

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.
@@ -0,0 +1,38 @@
1
+ require "slidepay"
2
+ require "spec_helper"
3
+
4
+ describe SlidePay::BankAccount do
5
+ it "should have an id_attribute" do
6
+ b = SlidePay::BankAccount.new()
7
+ expect(b.id_attribute).to eq("bank_account_id")
8
+ end
9
+
10
+ it "should have a root url" do
11
+ b = SlidePay::BankAccount.new()
12
+ expect(b.url_root).to eq("bank_account")
13
+ end
14
+
15
+ describe "url" do
16
+ it "should not append the object id if no id is set" do
17
+ b = SlidePay::BankAccount.new()
18
+ expect(b.url()).to eq("bank_account")
19
+ end
20
+
21
+ it "should append the object id if set" do
22
+ b = SlidePay::BankAccount.new("bank_account_id" => 2)
23
+ expect(b.url()).to eq("bank_account/2")
24
+ end
25
+ end
26
+
27
+ describe "id" do
28
+ it "should return nil if the id is not set" do
29
+ b = SlidePay::BankAccount.new()
30
+ expect(b.id()).to eq(nil)
31
+ end
32
+
33
+ it "should return the id if it is present" do
34
+ b = SlidePay::BankAccount.new("bank_account_id" => 2)
35
+ expect(b.id()).to eq(2)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,141 @@
1
+ require "slidepay"
2
+ require "spec_helper"
3
+
4
+ describe SlidePay::Client do
5
+ before(:all) do
6
+ SlidePay.configure(development: true)
7
+ end
8
+
9
+ it "should allow instantiation with no parameters" do
10
+ c = SlidePay::Client.new
11
+ expect(c).to be_a(SlidePay::Client)
12
+ end
13
+
14
+ it "should set api_key, token, and endpoint when they are present" do
15
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT")
16
+
17
+ expect(c.api_key).to eq("TEST_API_KEY")
18
+ expect(c.token).to eq("TEST_TOKEN")
19
+ expect(c.endpoint).to eq("TEST_ENDPOINT")
20
+ end
21
+
22
+ describe "basic request methods" do
23
+ describe "get" do
24
+ it "should accept a string" do
25
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", endpoint: "TEST_ENDPOINT")
26
+
27
+ SlidePay.should_receive(:get).with(path: 'test/path', api_key: "TEST_API_KEY", token: nil, endpoint: "TEST_ENDPOINT")
28
+ expect(c.get("test/path")).not_to raise_error
29
+ end
30
+
31
+ it "should accept a hash" do
32
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", endpoint: "TEST_ENDPOINT")
33
+
34
+ SlidePay.should_receive(:get).with(path: 'test/path', api_key: "TEST_API_KEY", token: nil, endpoint: "TEST_ENDPOINT")
35
+ expect(c.get(path: "test/path")).not_to raise_error
36
+ end
37
+ end
38
+
39
+ describe "post" do
40
+ it "should send the parameters hash with api_key and token to SlidePay" do
41
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", endpoint: "TEST_ENDPOINT")
42
+
43
+ SlidePay.should_receive(:post).with(path: 'test/path', data: "TEST_DATA", api_key: "TEST_API_KEY", token: nil, endpoint: "TEST_ENDPOINT")
44
+ expect(c.post(path: "test/path", data: "TEST_DATA")).not_to raise_error
45
+ end
46
+ end
47
+
48
+ describe "put" do
49
+ it "should send the parameters hash with api_key and token to SlidePay" do
50
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", endpoint: "TEST_ENDPOINT")
51
+
52
+ SlidePay.should_receive(:put).with(path: 'test/path', data: "TEST_DATA", api_key: "TEST_API_KEY", token: nil, endpoint: "TEST_ENDPOINT")
53
+ expect(c.put(path: "test/path", data: "TEST_DATA")).not_to raise_error
54
+ end
55
+ end
56
+
57
+ describe "delete" do
58
+ it "should accept a string" do
59
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", endpoint: "TEST_ENDPOINT")
60
+
61
+ SlidePay.should_receive(:delete).with(path: 'test/path', api_key: "TEST_API_KEY", token: nil, endpoint: "TEST_ENDPOINT")
62
+ expect(c.delete("test/path")).not_to raise_error
63
+ end
64
+
65
+ it "should accept a hash" do
66
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", endpoint: "TEST_ENDPOINT")
67
+
68
+ SlidePay.should_receive(:delete).with(path: 'test/path', api_key: "TEST_API_KEY", token: nil, endpoint: "TEST_ENDPOINT")
69
+ expect(c.delete(path: "test/path")).not_to raise_error
70
+ end
71
+ end
72
+ end
73
+
74
+ describe "resource request methods" do
75
+ describe "list" do
76
+ it "should use the resource's url_root with the SlidePay.get method" do
77
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT")
78
+ b = SlidePay::BankAccount.new()
79
+ SlidePay.should_receive(:get).with(path: b.url_root, api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT").and_return(a_response_object(bank_account_array_response))
80
+ c.list(b)
81
+ end
82
+
83
+ it "should return an array" do
84
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT")
85
+ b = SlidePay::BankAccount.new()
86
+ SlidePay.stub(:request) { a_response_object(bank_account_array_response) }
87
+
88
+ bank_accounts = c.list(b)
89
+ expect(bank_accounts).to be_a(Array)
90
+ end
91
+
92
+ it "should return an array of the proper length" do
93
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT")
94
+ b = SlidePay::BankAccount.new()
95
+ SlidePay.stub(:request) { a_response_object(bank_account_array_response) }
96
+
97
+ bank_accounts = c.list(b)
98
+ expect(bank_accounts).to be_a(Array)
99
+ end
100
+
101
+ it "should return an array of resources of the proper type" do
102
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT")
103
+ b = SlidePay::BankAccount.new()
104
+ SlidePay.stub(:request) { a_response_object(bank_account_array_response) }
105
+
106
+ bank_accounts = c.list(b)
107
+ expect(bank_accounts).to be_a(Array)
108
+ expect(bank_accounts.length).to eq(2)
109
+ expect(bank_accounts[0]).to be_a(SlidePay::BankAccount)
110
+ expect(bank_accounts[1]).to be_a(SlidePay::BankAccount)
111
+ end
112
+ end
113
+
114
+ describe "retrieve" do
115
+ it "should use the resource's method for fulfillment" do
116
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT")
117
+ b = SlidePay::BankAccount.new()
118
+ b.should_receive(:retrieve).with(api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT")
119
+ c.retrieve(b)
120
+ end
121
+ end
122
+
123
+ describe "save" do
124
+ it "should use the resource's method for fulfillment" do
125
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT")
126
+ b = SlidePay::BankAccount.new()
127
+ b.should_receive(:save).with(api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT")
128
+ c.save(b)
129
+ end
130
+ end
131
+
132
+ describe "destroy" do
133
+ it "should use the resource's method for fulfillment" do
134
+ c = SlidePay::Client.new(api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT")
135
+ b = SlidePay::BankAccount.new("bank_account_id" => 1)
136
+ b.should_receive(:destroy).with(api_key: "TEST_API_KEY", token: "TEST_TOKEN", endpoint: "TEST_ENDPOINT")
137
+ c.destroy(b)
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,90 @@
1
+ require "slidepay"
2
+ require "spec_helper"
3
+
4
+ describe SlidePay::Payment do
5
+ it "should have an id_attribute" do
6
+ p = SlidePay::Payment.new()
7
+ expect(p.id_attribute).to eq("payment_id")
8
+ end
9
+
10
+ it "should have a root url" do
11
+ p = SlidePay::Payment.new()
12
+ expect(p.url_root).to eq("payment")
13
+ end
14
+
15
+ describe "url" do
16
+ it "should not append the object id if no id is set" do
17
+ p = SlidePay::Payment.new()
18
+ expect(p.url()).to eq("payment")
19
+ end
20
+
21
+ it "should append the object id if set" do
22
+ p = SlidePay::Payment.new("payment_id" => 2)
23
+ expect(p.url()).to eq("payment/2")
24
+ end
25
+ end
26
+
27
+ describe "id" do
28
+ it "should return nil if the id is not set" do
29
+ p = SlidePay::Payment.new()
30
+ expect(p.id()).to eq(nil)
31
+ end
32
+
33
+ it "should return the id if it is present" do
34
+ p = SlidePay::Payment.new("payment_id" => 2)
35
+ expect(p.id()).to eq(2)
36
+ end
37
+ end
38
+
39
+ describe "save" do
40
+ it "should call the process method" do
41
+ p = SlidePay::Payment.new()
42
+ p.should_receive(:process)
43
+ p.save()
44
+ end
45
+ end
46
+
47
+ describe "destroy" do
48
+ it "should call the refund method" do
49
+ p = SlidePay::Payment.new()
50
+ p.should_receive(:refund)
51
+ p.destroy()
52
+ end
53
+ end
54
+
55
+ describe "process" do
56
+ it "should set the payment_id and the order_master_id on success" do
57
+ SlidePay.stub(:post) { a_response_object(successful_payment_response) }
58
+
59
+ p = SlidePay::Payment.new()
60
+ expect(p["order_master_id"]).to eq(nil)
61
+ expect(p["payment_id"]).to eq(nil)
62
+ p.process()
63
+ expect(p["order_master_id"]).to eq("10") # Test data found in spec_helper
64
+ expect(p["payment_id"]).to eq("12")
65
+ end
66
+
67
+ it "should raise an error on failure" do
68
+ SlidePay.stub(:post) { a_response_object(failed_payment_response) }
69
+
70
+ p = SlidePay::Payment.new()
71
+ expect{ p.process() }.to raise_error("TEST_PAYMENT_FAILED_MESSAGE")
72
+ end
73
+ end
74
+
75
+ describe "refund" do
76
+ it "should return false for failure" do
77
+ SlidePay.stub(:post) { a_response_object(failed_object_response) }
78
+
79
+ p = SlidePay::Payment.new()
80
+ expect(p.refund()).to eq(false)
81
+ end
82
+
83
+ it "should return true for successful refund" do
84
+ SlidePay.stub(:post) { a_response_object(successful_object_response) }
85
+
86
+ p = SlidePay::Payment.new()
87
+ expect(p.refund()).to eq(true)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,135 @@
1
+ require 'slidepay'
2
+ require 'spec_helper'
3
+
4
+ describe SlidePay::Response do
5
+ def public_methods
6
+ [:success, :custom, :operation, :endpoint, :timezone, :method, :obj,
7
+ :id, :milliseconds, :data, :data_md5]
8
+ end
9
+
10
+ it "should be a String" do
11
+ expect(SlidePay::Response.superclass).to eq(String)
12
+ end
13
+
14
+ it "should have a bunch of public instance methods" do
15
+ actual_public_methods = SlidePay::Response.public_instance_methods
16
+ public_methods.each do |method|
17
+ expect(actual_public_methods).to include(method)
18
+ end
19
+ end
20
+
21
+ describe "constructor" do
22
+ it "should create a blank instance if no string is provided" do
23
+ r = SlidePay::Response.new
24
+ expect(r).to eq("")
25
+ end
26
+
27
+ # it "should raise an error if created with invalid JSON" do
28
+ # expect(SlidePay::Response.new("THIS IS NOT JSON")).to raise_error
29
+ # end
30
+
31
+ it "should set the response to any string passed in" do
32
+ json = "{ \"custom\": \"CUSTOM_VALUE\" }"
33
+
34
+ r = SlidePay::Response.new(json)
35
+
36
+ expect(r).to eq(json)
37
+ end
38
+
39
+ it "should try to parse any JSON string passed in on creation" do
40
+ json = "{ \"custom\": \"CUSTOM_VALUE\" }"
41
+
42
+ r = SlidePay::Response.new(json)
43
+ expect(r.custom).to eq("CUSTOM_VALUE")
44
+ end
45
+ end
46
+
47
+ describe "parse_object_from_json" do
48
+ it "should populate the object when given a valid SlidePay response JSON" do
49
+ r = SlidePay::Response.new(successful_endpoint_response)
50
+
51
+ expect(r).to eq(successful_endpoint_response)
52
+
53
+ expect(r.success).to eq(true)
54
+ expect(r.custom).to eq(nil)
55
+ expect(r.operation).to eq("GET endpoint")
56
+ expect(r.endpoint).to eq("https://api.getcube.com:65532#{SlidePay::ENDPOINT_SUFFIX}")
57
+ expect(r.timezone).to eq(nil)
58
+ expect(r.method).to eq("GET")
59
+ expect(r.obj).to eq(nil)
60
+ expect(r.id).to eq(0)
61
+ expect(r.milliseconds).to eq("31.25")
62
+ expect(r.data).to eq("https://api.getcube.com:65532/rest.svc/API/")
63
+ expect(r.data_md5).to eq("15D13569C731E9D77ABDCB3348A2EBDD")
64
+ end
65
+
66
+ it "should populate the data property of the response with an object when appropriate" do
67
+ r = SlidePay::Response.new(successful_token_detail_response)
68
+
69
+ response_object = object_from_response(successful_token_detail_response)
70
+
71
+ expect(r.data).to be_a(Hash)
72
+ expect(r.data).to eq(response_object["data"])
73
+ end
74
+
75
+ it "should populate the data property of the response with an array when appropriate" do
76
+ r = SlidePay::Response.new(successful_array_response)
77
+
78
+ response_object = object_from_response(successful_array_response)
79
+
80
+ expect(r.data).to be_a(Array)
81
+ expect(r.data).to eq(response_object["data"])
82
+ end
83
+ end
84
+
85
+ describe "was_successful?" do
86
+ it "should always return a boolean" do
87
+ r = SlidePay::Response.new("{\"success\" : true}")
88
+ expect(r.was_successful?).to be_a(TrueClass)
89
+
90
+ r = SlidePay::Response.new("{\"success\" : false}")
91
+ expect(r.was_successful?).to be_a(FalseClass)
92
+ end
93
+
94
+ it "should return true for a successful response" do
95
+ r = SlidePay::Response.new(successful_endpoint_response)
96
+ expect(r.was_successful?).to eq(true)
97
+ end
98
+
99
+ it "should return false for an unsuccessful response" do
100
+ r = SlidePay::Response.new(failed_endpoint_response)
101
+ expect(r.was_successful?).to eq(false)
102
+ end
103
+ end
104
+
105
+ describe "endpoint" do
106
+ it "should always include the SlidePay endpoint suffix" do
107
+ r = SlidePay::Response.new
108
+ expect(r.endpoint).to include(SlidePay::ENDPOINT_SUFFIX)
109
+ end
110
+
111
+ it "should add the endpoint suffix to the endpoint value retrieved" do
112
+ r = SlidePay::Response.new(successful_token_detail_response)
113
+ response_object = object_from_response(successful_token_detail_response)
114
+ expect(r.endpoint).to eq("#{response_object["endpoint"]}#{SlidePay::ENDPOINT_SUFFIX}")
115
+ end
116
+ end
117
+
118
+ describe "error" do
119
+ it "should return nil for a successful response" do
120
+ r = SlidePay::Response.new(successful_token_detail_response)
121
+ expect(r.error).to eq(nil)
122
+ end
123
+
124
+ it "should return a Hash object for an unsuccessful response" do
125
+ r = SlidePay::Response.new(failed_token_detail_response)
126
+ expect(r.error).to be_a(Hash)
127
+ end
128
+
129
+ it "should return an object containing an error_code and error_text" do
130
+ r = SlidePay::Response.new(failed_token_detail_response)
131
+ expect(r.error).to include("error_text")
132
+ expect(r.error).to include("error_code")
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,301 @@
1
+ require "slidepay"
2
+ require "spec_helper"
3
+
4
+ describe SlidePay do
5
+ def public_methods
6
+ [:get_auth_option, :request, :get, :post, :put, :delete]
7
+ end
8
+
9
+ it "should have a version" do
10
+ expect(SlidePay::VERSION).not_to be_nil
11
+ end
12
+
13
+ it "should have a global token variable that is nil" do
14
+ expect(SlidePay.token).to be_nil
15
+ end
16
+
17
+ it "should have a global api_key variable that is nil" do
18
+ expect(SlidePay.api_key).to be_nil
19
+ end
20
+
21
+ it "should have a default endpoint" do
22
+ expect(SlidePay.endpoint).not_to be_nil
23
+ end
24
+
25
+ describe "configure" do
26
+ before(:each) do
27
+ clear_slidepay()
28
+ end
29
+
30
+ it "should only configure an endpoint by default" do
31
+ SlidePay.configure
32
+
33
+ expect(SlidePay.token).to be_nil
34
+ expect(SlidePay.api_key).to be_nil
35
+ expect(SlidePay.endpoint).to eq(SlidePay::SUPERVISOR_URL)
36
+ end
37
+
38
+ it "should allow configuration of token, api_key, and endpoint" do
39
+ SlidePay.configure(endpoint: "TEST_ENDPOINT", token: "TEST_TOKEN", api_key: "TEST_API_KEY")
40
+
41
+ expect(SlidePay.token).to eq("TEST_TOKEN")
42
+ expect(SlidePay.api_key).to eq("TEST_API_KEY")
43
+ expect(SlidePay.endpoint).to eq("TEST_ENDPOINT")
44
+ end
45
+
46
+ it "should allow a user to choose the development enpdoint" do
47
+ SlidePay.configure(development: true)
48
+
49
+ expect(SlidePay.endpoint).to eq(SlidePay::DEV_API_URL)
50
+ end
51
+ end
52
+
53
+ it "should have a bunch of public methods" do
54
+ actual_slidepay_methods = SlidePay.public_methods
55
+ public_methods.each do |method|
56
+ expect(actual_slidepay_methods).to include(method)
57
+ end
58
+ end
59
+
60
+ it "should have a bunch of configuration options" do
61
+ ENDPOINT_SUFFIX = '/rest.svc/API/'
62
+ SUPERVISOR_URL = 'https://supervisor.getcube.com:65532/rest.svc/API/'
63
+ PROD_API_URL = 'https://api.getcube.com:65532/rest.svc/API/'
64
+ DEV_API_URL = 'https://dev.getcube.com:65532/rest.svc/API/'
65
+ DEBUG = false
66
+
67
+ expect(SlidePay::ENDPOINT_SUFFIX).to eq(ENDPOINT_SUFFIX)
68
+ expect(SlidePay::SUPERVISOR_URL).to eq(SUPERVISOR_URL)
69
+ expect(SlidePay::PROD_API_URL).to eq(PROD_API_URL)
70
+ expect(SlidePay::DEV_API_URL).to eq(DEV_API_URL)
71
+ expect(SlidePay::DEBUG).to eq(DEBUG)
72
+ end
73
+
74
+ describe "get_endpoint_option" do
75
+ after(:each) do
76
+ clear_endpoint()
77
+ end
78
+
79
+ it "should use the default endpoint if none is provided" do
80
+ set_global_endpoint()
81
+
82
+ endpoint = SlidePay.get_endpoint_option({})
83
+ expect(SlidePay.endpoint).to eq("TEST_ENDPOINT")
84
+ expect(endpoint).to eq("TEST_ENDPOINT")
85
+ end
86
+
87
+ it "should use the endpoint passed in if there is no default" do
88
+ endpoint = SlidePay.get_endpoint_option(endpoint: "NEW_ENDPOINT")
89
+ expect(SlidePay.endpoint).to eq(nil)
90
+ expect(endpoint).to eq("NEW_ENDPOINT")
91
+ end
92
+
93
+ it "should use the endpoint passed in over the default" do
94
+ set_global_endpoint()
95
+
96
+ endpoint = SlidePay.get_endpoint_option(endpoint: "NEW_ENDPOINT")
97
+ expect(SlidePay.endpoint).to eq("TEST_ENDPOINT")
98
+ expect(endpoint).to eq("NEW_ENDPOINT")
99
+ end
100
+ end
101
+
102
+
103
+ describe "get_auth_option" do
104
+ after(:each) do
105
+ clear_auth_data()
106
+ end
107
+
108
+ it "should use the default token over the default api_key if both are present" do
109
+ set_global_token()
110
+ set_global_api_key()
111
+
112
+ auth = SlidePay.get_auth_option({})
113
+ expect(SlidePay.token).to eq("TEST_TOKEN")
114
+ expect(SlidePay.api_key).to eq("TEST_API_KEY")
115
+ expect(auth).to eq({ "x-cube-token" => "TEST_TOKEN" })
116
+ end
117
+
118
+ it "should use the default api_key when nothing else is given" do
119
+ set_global_api_key()
120
+
121
+ auth = SlidePay.get_auth_option({})
122
+ expect(SlidePay.token).to eq(nil)
123
+ expect(SlidePay.api_key).to eq("TEST_API_KEY")
124
+ expect(auth).to eq({ "x-cube-api-key" => "TEST_API_KEY" })
125
+ end
126
+
127
+ it "should use the default token when nothing else is given" do
128
+ set_global_token()
129
+
130
+ auth = SlidePay.get_auth_option({})
131
+ expect(SlidePay.token).to eq("TEST_TOKEN")
132
+ expect(SlidePay.api_key).to eq(nil)
133
+ expect(auth).to eq({ "x-cube-token" => "TEST_TOKEN" })
134
+ end
135
+
136
+ it "should use the provided api_key even when a default is present" do
137
+ set_global_api_key()
138
+
139
+ auth = SlidePay.get_auth_option(api_key: "PASSED_IN_API_KEY")
140
+ expect(SlidePay.token).to eq(nil)
141
+ expect(SlidePay.api_key).to eq("TEST_API_KEY")
142
+ expect(auth).to eq({ "x-cube-api-key" => "PASSED_IN_API_KEY" })
143
+ end
144
+
145
+ it "should use the provided token even when a default is present" do
146
+ set_global_token()
147
+
148
+ auth = SlidePay.get_auth_option(token: "PASSED_IN_TOKEN")
149
+ expect(SlidePay.token).to eq("TEST_TOKEN")
150
+ expect(SlidePay.api_key).to eq(nil)
151
+ expect(auth).to eq({ "x-cube-token" => "PASSED_IN_TOKEN" })
152
+ end
153
+ end
154
+
155
+ describe "request" do
156
+ before(:each) do
157
+ SlidePay.configure(development: true)
158
+ end
159
+
160
+ it "should return a SlidePay::Response object on a get" do
161
+ RestClient.should_receive(:get).and_return(failed_token_response)
162
+ r_get = SlidePay.request("GET", { :path => 'login'})
163
+ expect(r_get).to be_a(SlidePay::Response)
164
+ end
165
+
166
+ it "should return a SlidePay::Response object on a put" do
167
+ RestClient.should_receive(:put).and_return(failed_token_response)
168
+ r_put = SlidePay.request("PUT", { :path => 'login'})
169
+ expect(r_put).to be_a(SlidePay::Response)
170
+ end
171
+
172
+ it "should return a SlidePay::Response object on a post" do
173
+ RestClient.should_receive(:post).and_return(failed_token_response)
174
+ r_post = SlidePay.request("POST", { :path => 'login'})
175
+ expect(r_post).to be_a(SlidePay::Response)
176
+ end
177
+
178
+ it "should return a SlidePay::Response object on a delete" do
179
+ RestClient.should_receive(:delete).and_return(failed_token_response)
180
+ r_delete = SlidePay.request("DELETE", { :path => 'login'})
181
+ expect(r_delete).to be_a(SlidePay::Response)
182
+ end
183
+
184
+ it "should raise an error for invalid request types" do
185
+ expect { SlidePay.request("INVALID_TYPE", {}) }.to raise_error
186
+ end
187
+ end
188
+
189
+ describe "get" do
190
+ before(:all) do
191
+ SlidePay.configure(development: true)
192
+ set_global_api_key_from_env
193
+ end
194
+
195
+ it "should accept a string" do
196
+ SlidePay.should_receive(:request).with("GET", path: 'token/detail').and_return(a_response_object(successful_token_detail_response))
197
+ expect(SlidePay.get('token/detail')).to be_a(SlidePay::Response)
198
+ end
199
+
200
+ it "should accept a hash" do
201
+ SlidePay.should_receive(:request).with("GET", path: 'token/detail').and_return(a_response_object(successful_token_detail_response))
202
+ expect(SlidePay.get(path: 'token/detail')).to be_a(SlidePay::Response)
203
+ end
204
+ end
205
+
206
+ describe "delete" do
207
+ before(:all) do
208
+ SlidePay.configure(development: true)
209
+ set_global_api_key_from_env
210
+ end
211
+
212
+ it "should accept a string" do
213
+ SlidePay.should_receive(:request).with("DELETE", path: 'fictional_object/2').and_return(a_response_object(successful_deletion_response))
214
+ expect(SlidePay.delete('fictional_object/2')).to be_a(SlidePay::Response)
215
+ end
216
+
217
+ it "should accept a hash" do
218
+ SlidePay.should_receive(:request).with("DELETE", path: 'fictional_object/2').and_return(a_response_object(successful_deletion_response))
219
+ expect(SlidePay.delete(path: 'fictional_object/2')).to be_a(SlidePay::Response)
220
+ end
221
+ end
222
+
223
+ describe "retrieve_token" do
224
+ before(:all) do
225
+ clear_slidepay
226
+ SlidePay.configure(development: true)
227
+ end
228
+
229
+ it "should always return a SlidePay::Response" do
230
+ SlidePay.should_receive(:get).with(path: 'login', email: '', password: '').and_return(a_response_object(successful_token_response))
231
+
232
+ r = SlidePay.retrieve_token('','')
233
+ expect(r).to be_a(SlidePay::Response)
234
+ end
235
+
236
+ it "should return a token value on success" do
237
+ SlidePay.should_receive(:get).with(path: 'login', email: SlidePay::TEST_EMAIL, password: SlidePay::TEST_PASSWORD).and_return(a_response_object(successful_token_response))
238
+ r = SlidePay.retrieve_token(SlidePay::TEST_EMAIL,SlidePay::TEST_PASSWORD)
239
+
240
+ expect(r.data).to be_a(String)
241
+ expect(r.data).to eq("TOKEN_FROM_THE_BEYOND")
242
+ end
243
+
244
+ it "should return an error object on failure" do
245
+ SlidePay.should_receive(:get).with(path: 'login', email: '', password: '').and_return(a_response_object(failed_token_response))
246
+ r = SlidePay.retrieve_token('','')
247
+
248
+ expect(r.data).to be_a(Hash)
249
+ expect(r.error).to be_a(Hash)
250
+ end
251
+ end
252
+
253
+ describe "retrieve_endpoint" do
254
+ before(:all) do
255
+ clear_slidepay
256
+ SlidePay.configure()
257
+ end
258
+
259
+ it "should always return a string" do
260
+ SlidePay.should_receive(:get).with(path: 'endpoint', email: '').and_return(a_response_object(failed_endpoint_response))
261
+ r = SlidePay.retrieve_endpoint('')
262
+ expect(r).to be_a(SlidePay::Response)
263
+ end
264
+
265
+ it "should return an endpoint value on success" do
266
+ SlidePay.should_receive(:get).with(path: 'endpoint', email: 'matt+test@getcube.com').and_return(a_response_object(successful_token_response))
267
+ r = SlidePay.retrieve_endpoint('matt+test@getcube.com')
268
+
269
+ expect(r.data).to be_a(String)
270
+ expect(r.data).to eq("TOKEN_FROM_THE_BEYOND")
271
+ end
272
+
273
+ it "should return an error object on failure" do
274
+ SlidePay.should_receive(:get).with(path: 'endpoint', email: '').and_return(a_response_object(failed_token_response))
275
+ r = SlidePay.retrieve_endpoint('')
276
+
277
+ expect(r.data).to be_a(Hash)
278
+ expect(r.error).to be_a(Hash)
279
+ end
280
+ end
281
+
282
+ describe "authenticate" do
283
+ before(:each) do
284
+ clear_slidepay
285
+ SlidePay.configure(development: true)
286
+ end
287
+
288
+ it "should have a token after a successful authentication" do
289
+ SlidePay.should_receive(:get).with(path: 'login', email: SlidePay::TEST_EMAIL, password: SlidePay::TEST_PASSWORD).and_return(a_response_object(successful_token_response))
290
+ expect(SlidePay.authenticate(SlidePay::TEST_EMAIL, SlidePay::TEST_PASSWORD)).to eq(true)
291
+ expect(SlidePay.token).not_to eq(nil)
292
+ end
293
+
294
+ it "should not have a token after a successful authentication" do
295
+ SlidePay.should_receive(:get).with(path: 'login', email: '', password: '').and_return(a_response_object(failed_token_response))
296
+ expect(SlidePay.authenticate('','')).to eq(false)
297
+ expect(SlidePay.token).to eq(nil)
298
+ end
299
+ end
300
+
301
+ end