-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathflat_json_params_test.rb
More file actions
278 lines (207 loc) · 7.98 KB
/
flat_json_params_test.rb
File metadata and controls
278 lines (207 loc) · 7.98 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
require "test_helper"
class FlatJsonParamsTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
end
test "update user role with flat JSON" do
put user_role_path(users(:david)), params: { role: "admin" }, as: :json
assert_response :no_content
assert users(:david).reload.admin?
end
test "update notification settings with flat JSON" do
logout_and_sign_in_as :david
assert_changes -> { users(:david).reload.settings.bundle_email_frequency }, from: "never", to: "every_few_hours" do
put notifications_settings_path, params: { bundle_email_frequency: "every_few_hours" }, as: :json
end
assert_response :no_content
end
test "update join code with flat JSON" do
put account_join_code_path, params: { usage_limit: 5 }, as: :json
assert_response :no_content
assert_equal 5, Current.account.join_code.reload.usage_limit
end
test "update account settings with flat JSON" do
put account_settings_path, params: { name: "New Name" }, as: :json
assert_response :no_content
assert_equal "New Name", Current.account.reload.name
end
test "update board entropy with flat JSON" do
board = boards(:writebook)
put board_entropy_path(board), params: { auto_postpone_period_in_days: 90 }, as: :json
assert_response :success
assert_equal 90.days, board.entropy.reload.auto_postpone_period
end
test "update account entropy with flat JSON" do
put account_entropy_path, params: { auto_postpone_period_in_days: 7 }, as: :json
assert_response :success
assert_equal 7.days, Current.account.entropy.reload.auto_postpone_period
end
test "create push subscription with flat JSON" do
stub_dns_resolution("142.250.185.206")
post user_push_subscriptions_path(users(:kevin)),
params: { endpoint: "https://fcm.googleapis.com/fcm/send/abc123", p256dh_key: "key1", auth_key: "key2" },
as: :json
assert_response :created
end
test "create card with flat JSON" do
assert_difference -> { Card.count }, +1 do
post board_cards_path(boards(:writebook)),
params: { title: "Flat card", description: "<p>Flat description</p>" },
as: :json
end
assert_response :created
card = Card.last
assert_equal "Flat card", card.title
assert_equal "Flat description", card.description.to_plain_text
end
test "create card with flat JSON and tag_ids" do
tag = tags(:mobile)
assert_difference -> { Card.count }, +1 do
post board_cards_path(boards(:writebook)),
params: { title: "Flat tagged card", tag_ids: [ tag.id ] },
as: :json
end
assert_response :created
card = Card.last
assert_equal [ tag ], card.reload.tags
assert_equal [ tag.title ], @response.parsed_body["tags"]
end
test "update card with flat JSON" do
card = cards(:logo)
put card_path(card),
params: { title: "Flat update", description: "<p>Updated flat</p>" },
as: :json
assert_response :success
card.reload
assert_equal "Flat update", card.title
assert_equal "Updated flat", card.description.to_plain_text
end
test "update card with flat JSON and tag_ids" do
card = cards(:logo)
tag = tags(:mobile)
put card_path(card),
params: { tag_ids: [ tag.id ] },
as: :json
assert_response :success
assert_equal [ tag ], card.reload.tags
assert_equal [ tag.title ], @response.parsed_body["tags"]
end
test "create board with flat JSON" do
assert_difference -> { Board.count }, +1 do
post boards_path, params: { name: "Flat board" }, as: :json
end
assert_response :created
assert_equal "Flat board", Board.last.name
end
test "update board with flat JSON" do
board = boards(:writebook)
put board_path(board),
params: { name: "Flat board", auto_postpone_period_in_days: 7, public_description: "<p>Flat public desc</p>" },
as: :json
assert_response :no_content
board.reload
assert_equal "Flat board", board.name
assert_equal 7.days, board.entropy.auto_postpone_period
assert_equal "Flat public desc", board.public_description.to_plain_text
end
test "create column with flat JSON" do
board = boards(:writebook)
assert_difference -> { board.columns.count }, +1 do
post board_columns_path(board), params: { name: "Flat Column" }, as: :json
end
assert_response :created
assert_equal "Flat Column", Column.last.name
end
test "update column with flat JSON" do
column = columns(:writebook_in_progress)
put board_column_path(column.board, column), params: { name: "Flat Updated" }, as: :json
assert_response :no_content
assert_equal "Flat Updated", column.reload.name
end
test "create step with flat JSON" do
card = cards(:logo)
assert_difference -> { card.steps.count }, +1 do
post card_steps_path(card), params: { content: "Flat step" }, as: :json
end
assert_response :created
assert_equal "Flat step", Step.last.content
end
test "update step with flat JSON" do
card = cards(:logo)
step = card.steps.create!(content: "Original")
put card_step_path(card, step), params: { content: "Flat updated" }, as: :json
assert_response :success
assert_equal "Flat updated", step.reload.content
end
test "create card reaction with flat JSON" do
card = cards(:logo)
assert_difference -> { card.reactions.count }, +1 do
post card_reactions_path(card), params: { content: "🎉" }, as: :json
end
assert_response :created
end
test "create comment reaction with flat JSON" do
comment = comments(:logo_agreement_kevin)
assert_difference -> { comment.reactions.count }, +1 do
post card_comment_reactions_path(comment.card, comment), params: { content: "👍" }, as: :json
end
assert_response :created
end
test "create access token with flat JSON" do
assert_difference -> { identities(:kevin).access_tokens.count }, +1 do
post my_access_tokens_path, params: { description: "Flat token", permission: "read" }, as: :json
end
assert_response :created
assert_equal "Flat token", @response.parsed_body["description"]
end
test "update user with flat JSON" do
put user_path(users(:david)), params: { name: "Flat Name" }, as: :json
assert_response :no_content
assert_equal "Flat Name", users(:david).reload.name
end
test "create webhook with flat JSON" do
board = boards(:writebook)
assert_difference -> { Webhook.count }, +1 do
post board_webhooks_path(board),
params: { name: "Flat Webhook", url: "https://example.com/flat", subscribed_actions: [ "card_published" ] },
as: :json
end
assert_response :created
assert_equal "Flat Webhook", Webhook.last.name
end
test "update webhook with flat JSON" do
webhook = webhooks(:active)
patch board_webhook_path(webhook.board, webhook),
params: { name: "Flat Updated", subscribed_actions: [ "card_published" ] },
as: :json
assert_response :success
assert_equal "Flat Updated", webhook.reload.name
end
test "create signup with flat JSON" do
sign_out
email = "flatjson-#{SecureRandom.hex(6)}@example.com"
untenanted do
assert_difference -> { Identity.count }, +1 do
post signup_path, params: { email_address: email }, as: :json
end
end
assert_response :created
end
test "complete signup with flat JSON" do
signup = Signup.new(email_address: "flatjson-#{SecureRandom.hex(6)}@example.com", full_name: "Flat User")
signup.create_identity || raise("Failed to create identity")
logout_and_sign_in_as signup.identity
untenanted do
assert_difference -> { Account.count }, +1 do
post signup_completion_path, params: { full_name: "Flat JSON User" }, as: :json
end
end
assert_response :created
end
test "update user via join with flat JSON" do
logout_and_sign_in_as :david
post users_joins_path, params: { name: "Flat Join" }, as: :json
assert_response :no_content
assert_equal "Flat Join", users(:david).reload.name
end
end