-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusers_spec.rb
More file actions
165 lines (147 loc) · 4.34 KB
/
users_spec.rb
File metadata and controls
165 lines (147 loc) · 4.34 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# frozen_string_literal: true
require_relative "../lib/embed_workflow"
require "net/http"
describe "users" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:execute_request)
.with(instance_of(Net::HTTPRequest))
.and_return("response")
end
describe "#list" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:get_request)
.with({ path: "/api/v1/users", params: {} })
.and_return("response")
end
it "sends the correct parameters to the users API" do
EmbedWorkflow::Users.list
end
context "with pagination parameters" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:get_request)
.with({ path: "/api/v1/users", params: { starting_after: "550e8400-e29b-41d4-a716-446655440000", limit: 10 } })
.and_return("response")
end
it "sends the correct pagination parameters" do
EmbedWorkflow::Users.list(starting_after: "550e8400-e29b-41d4-a716-446655440000", limit: 10)
end
end
end
describe "#fetch" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:get_request)
.with({ path: "/api/v1/users/api-user-1" })
.and_return("response")
end
it "sends the correct parameters to the users API" do
EmbedWorkflow::Users.fetch(key: "api-user-1")
end
end
describe "#delete" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:delete_request)
.with({ path: "/api/v1/users/api-user-1" })
.and_return("response")
end
it "sends the correct parameters to the users API" do
EmbedWorkflow::Users.delete(key: "api-user-1")
end
end
describe "#upsert" do
context "with minimum parameters" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:put_request)
.with({
path: "/api/v1/users/api-user-1",
body: { key: "api-user-1" }
})
.and_return("response")
end
it "sends the correct parameters to the users API" do
EmbedWorkflow::Users.upsert(key: "api-user-1")
end
end
context "with all parameters" do
before do
data = { foo: "bar" }
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:put_request)
.with({
path: "/api/v1/users/api-user-1",
body: {
key: "api-user-1",
name: "Jane Doe",
email: "jane@example.com",
time_zone: "America/New_York",
groups: ["admin", "users"],
data: data
}
})
.and_return("response")
end
it "sends the correct parameters to the users API" do
data = { foo: "bar" }
EmbedWorkflow::Users.upsert(
key: "api-user-1",
name: "Jane Doe",
email: "jane@example.com",
time_zone: "America/New_York",
groups: ["admin", "users"],
data: data
)
end
end
context "with nil values to unset fields" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:put_request)
.with({
path: "/api/v1/users/api-user-1",
body: {
key: "api-user-1",
time_zone: nil,
groups: nil
}
})
.and_return("response")
end
it "sends nil values to unset time_zone and groups" do
EmbedWorkflow::Users.upsert(
key: "api-user-1",
time_zone: nil,
groups: nil
)
end
end
context "with mixed nil and provided values" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:put_request)
.with({
path: "/api/v1/users/api-user-1",
body: {
key: "api-user-1",
name: "Jane Doe",
email: "jane@example.com",
groups: nil
}
})
.and_return("response")
end
it "sends both set and unset values correctly" do
EmbedWorkflow::Users.upsert(
key: "api-user-1",
name: "Jane Doe",
email: "jane@example.com",
groups: nil
)
end
end
end
end