-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintelligent_foods_spec.rb
More file actions
149 lines (117 loc) · 3.96 KB
/
Copy pathintelligent_foods_spec.rb
File metadata and controls
149 lines (117 loc) · 3.96 KB
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
# frozen_string_literal: true
RSpec.describe IntelligentFoods do
it "has a version number" do
expect(IntelligentFoods::VERSION).not_to be_nil
end
describe "#configure" do
it "returns a new client with new attributes" do
configure_client(id: "abc123", secret: "xyz890")
IntelligentFoods.configure do |config|
config.client_id = "id123"
config.client_secret = "secret123"
end
expect(IntelligentFoods.client_id).to eq("id123")
end
it "sets the client ID" do
IntelligentFoods.configure do |config|
config.client_id = "abc"
end
expect(IntelligentFoods.client_id).to eq("abc")
end
it "sets the client secret" do
IntelligentFoods.configure do |config|
config.client_secret = "abc"
end
expect(IntelligentFoods.client_secret).to eq("abc")
end
it "sets the environment" do
IntelligentFoods.configure do |config|
config.environment = "preview"
end
expect(IntelligentFoods.environment).to eq("preview")
end
end
describe "#base_url" do
context "environment is staging" do
it "returns the correct url" do
IntelligentFoods.configure do |config|
config.environment = "staging"
end
staging_url = "https://api.sunbasket.dev/partner/v1"
expect(IntelligentFoods.base_url).to eq(staging_url)
end
context "the api version is v1" do
it "returns the correct url" do
IntelligentFoods.configure do |config|
config.environment = "staging"
end
staging_url = "https://api.sunbasket.dev/partner/v1"
result = IntelligentFoods.base_url(api_version: "v1")
expect(result).to eq(staging_url)
end
end
context "the api version is v2" do
it "returns the correct url" do
IntelligentFoods.configure do |config|
config.environment = "staging"
end
staging_url = "https://api.intelligentfoods.dev"
result = IntelligentFoods.base_url(api_version: "v2")
expect(result).to eq(staging_url)
end
end
end
context "environment is production" do
it "returns the correct url" do
IntelligentFoods.configure do |config|
config.environment = "production"
end
production_url = "https://api.sunbasket.com/partner/v1"
expect(IntelligentFoods.base_url).to eq(production_url)
end
context "the api version is v1" do
it "returns the correct url" do
IntelligentFoods.configure do |config|
config.environment = "production"
end
production_url = "https://api.sunbasket.com/partner/v1"
result = IntelligentFoods.base_url(api_version: "v1")
expect(result).to eq(production_url)
end
end
context "the api version is v2" do
it "returns the correct url" do
IntelligentFoods.configure do |config|
config.environment = "production"
end
production_url = "https://api.intelligentfoods.com"
result = IntelligentFoods.base_url(api_version: "v2")
expect(result).to eq(production_url)
end
end
end
context "environment is not any of the above" do
it "defaults to the dev url" do
IntelligentFoods.configure do |config|
config.environment = "asdf"
end
preview_url = "https://api.sunbasket.dev/partner/v1"
expect(IntelligentFoods.base_url).to eq(preview_url)
end
end
end
describe "#client" do
it "returns an instance of the api client" do
result = configure_client(id: "abc123", secret: "xyz890")
expect(result.id).to eq("abc123")
expect(result.secret).to eq("xyz890")
end
end
def configure_client(id:, secret:)
IntelligentFoods.configure do |config|
config.client_id = id
config.client_secret = secret
end
IntelligentFoods.client
end
end