FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
shipcloud-ruby/spec/shipcloud_spec.rb at master · shipcloud/shipcloud-ruby · GitHub
This repository was archived by the owner on Aug 14, 2024. It is now read-only.
shipcloud
/
shipcloud-ruby
Public archive
Notifications
You must be signed in to change notification settings
Fork
8
Star
7
Code
Issues
1
Pull requests
4
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
shipcloud-ruby
/
spec
/
shipcloud_spec.rb
Copy path
More file actions
More file actions
Latest commit
History
History
History
154 lines (127 loc) · 4.85 KB
Breadcrumbs
shipcloud-ruby
/
spec
/
shipcloud_spec.rb
Copy path
File metadata and controls
154 lines (127 loc) · 4.85 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# frozen_string_literal: true
require
"spec_helper"
describe
Shipcloud
do
describe
".request"
do
context
"given no api key exists"
do
it
"raises an authentication error"
do
expect
do
Shipcloud
.
request
(
:get
,
"clients"
,
{
}
)
end
.
to
raise_error
(
Shipcloud
::
AuthenticationError
)
end
end
context
"with an invalid api key"
do
before
(
:each
)
do
WebMock
.
stub_request
(
:any
,
/
#{
Shipcloud
.
configuration
.
api_base
}
/
)
.
to_return
(
body
:
"{}"
)
Shipcloud
.
api_key
=
"your-api-key"
end
it
"attempts to get a url with one param"
do
Shipcloud
.
request
(
:get
,
"transactions"
,
{
param_name
:
"param_value"
}
)
expect
(
WebMock
)
.
to
have_requested
(
:get
,
"
#{
api_url
}
/transactions?param_name=param_value"
)
end
it
"attempts to get a url with more than one param"
do
Shipcloud
.
request
(
:get
,
"transactions"
,
{
client
:
"client_id"
,
order
:
"created_at_desc"
}
)
expect
(
WebMock
)
.
to
have_requested
(
:get
,
"
#{
api_url
}
/transactions?client=client_id&order=created_at_desc"
)
end
it
"doesn't add a question mark if no params"
do
Shipcloud
.
request
(
:get
,
"transactions"
,
{
}
)
expect
(
WebMock
)
.
to
have_requested
(
:get
,
"
#{
api_url
}
/transactions"
)
end
end
context
"with an api key passed in as an argument"
do
it
"uses the given api key instead of the global one"
do
WebMock
.
stub_request
(
:any
,
/
#{
Shipcloud
.
configuration
.
api_base
}
/
)
.
to_return
(
body
:
"{}"
)
Shipcloud
.
api_key
=
"global-api-key"
Shipcloud
.
request
(
:get
,
"transactions"
,
{
}
,
api_key
:
"123"
)
expect
(
WebMock
)
.
to
have_requested
(
:get
,
"
#{
api_url
}
/transactions"
,
)
.
with
(
headers
:
{
"Authorization"
=>
"Basic
#{
Base64
.
strict_encode64
(
'123:'
)
.
chomp
}
"
,
}
,
)
end
end
end
describe
".configure"
do
before
:each
do
Shipcloud
.
configuration
=
nil
end
it
"defaults api_key to nil"
do
expect
(
Shipcloud
.
configuration
.
api_key
)
.
to
be_nil
end
it
"sets the api_key"
do
Shipcloud
.
configure
do
|
config
|
config
.
api_key
=
"your-api-key"
end
expect
(
Shipcloud
.
configuration
.
api_key
)
.
to
eq
"your-api-key"
end
it
"gets the api key, set as a class variable (DEPRECATED)"
do
Shipcloud
.
api_key
=
"old-school-api-key"
expect
(
Shipcloud
.
api_key
)
.
to
eq
"old-school-api-key"
expect
(
Shipcloud
.
configuration
.
api_key
)
.
to
eq
"old-school-api-key"
end
it
"defaults api_base to 'api.shipcloud.io'"
do
expect
(
Shipcloud
.
configuration
.
api_base
)
.
to
eq
"api.shipcloud.io"
end
it
"overwrites the default api base"
do
Shipcloud
.
configure
do
|
config
|
config
.
api_base
=
"api.shipcloud.dev"
end
expect
(
Shipcloud
.
configuration
.
api_base
)
.
to
eq
"api.shipcloud.dev"
end
it
"defaults use_ssl to true"
do
expect
(
Shipcloud
.
configuration
.
use_ssl
)
.
to
be
true
end
it
"overwrites the default ssl mode"
do
Shipcloud
.
configure
do
|
config
|
config
.
use_ssl
=
false
end
expect
(
Shipcloud
.
configuration
.
use_ssl
)
.
to
be
false
end
it
"defaults debug to false"
do
expect
(
Shipcloud
.
configuration
.
debug
)
.
to
be
false
end
it
"overwrites the default debug mode"
do
Shipcloud
.
configure
do
|
config
|
config
.
debug
=
true
end
expect
(
Shipcloud
.
configuration
.
debug
)
.
to
be
true
end
it
"defaults affiliate_id to nil"
do
expect
(
Shipcloud
.
configuration
.
affiliate_id
)
.
to
be_nil
end
it
"sets and gets the affiliate_id"
do
Shipcloud
.
configure
do
|
config
|
config
.
affiliate_id
=
"integration.my_rails_app.1234567"
end
expect
(
Shipcloud
.
configuration
.
affiliate_id
)
.
to
eq
"integration.my_rails_app.1234567"
end
end
describe
".api_headers"
do
it
"returns the correct api headers with default affiliate id"
do
Shipcloud
.
configuration
=
nil
# reset configuration
expect
(
Shipcloud
.
api_headers
)
.
to
eq
(
"Content-Type"
=>
"application/json"
,
"User-Agent"
=>
"shipcloud-ruby v
#{
Shipcloud
::
VERSION
}
, API
#{
Shipcloud
::
API_VERSION
}
, "
\
"
#{
RUBY_VERSION
}
,
#{
RUBY_PLATFORM
}
,
#{
RUBY_PATCHLEVEL
}
"
,
"Affiliate-ID"
=>
"integration.shipcloud-ruby-gem.v
#{
Shipcloud
::
VERSION
}
"
,
)
end
it
"returns the correct api headers with affiliate id if configured"
do
Shipcloud
.
configure
do
|
config
|
config
.
affiliate_id
=
"integration.my_rails_app.1234567"
end
expect
(
Shipcloud
.
api_headers
)
.
to
eq
(
"Content-Type"
=>
"application/json"
,
"User-Agent"
=>
"shipcloud-ruby v
#{
Shipcloud
::
VERSION
}
, API
#{
Shipcloud
::
API_VERSION
}
, "
\
"
#{
RUBY_VERSION
}
,
#{
RUBY_PLATFORM
}
,
#{
RUBY_PATCHLEVEL
}
"
,
"Affiliate-ID"
=>
"integration.my_rails_app.1234567"
,
)
end
end
def
api_url
"https://
#{
Shipcloud
.
configuration
.
api_base
}
/
#{
Shipcloud
::
API_VERSION
}
"
end
end
Back
|
FazBrowse Home
|
New Git URL