-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpasswords_controller_test.rb
More file actions
65 lines (53 loc) · 1.67 KB
/
passwords_controller_test.rb
File metadata and controls
65 lines (53 loc) · 1.67 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
require "test_helper"
class ShopkeeperAuth::PasswordsControllerTest < ActionDispatch::IntegrationTest
def setup
@shopkeeper = shopkeepers(:one)
@email = @shopkeeper.email
end
test "should send reset password instructions" do
post shopkeeper_password_url,
params: {
email: @email,
redirect_url: "http://localhost:3000/reset"
},
as: :json
assert_response :success
end
test "should return error when email is missing" do
post shopkeeper_password_url,
params: {redirect_url: "http://localhost:3000/reset"},
as: :json
assert_response :unauthorized
assert_equal 401, JSON.parse(response.body)["code"]
end
test "should return error when redirect_url is missing" do
post shopkeeper_password_url,
params: {email: @email},
as: :json
assert_response :unauthorized
assert_equal 401, JSON.parse(response.body)["code"]
end
test "should redirect with error when password update fails validation" do
token = @shopkeeper.send(:set_reset_password_token)
patch shopkeeper_password_url,
params: {
reset_password_token: token,
password: "short",
password_confirmation: "mismatch"
}
assert_response :redirect
assert_match "edit", response.location
follow_redirect!
assert_select ".bg-yellow-50"
end
test "should return generic success for non-existent email to prevent enumeration" do
post shopkeeper_password_url,
params: {
email: "nonexistent@example.com",
redirect_url: "http://localhost:3000/reset"
},
as: :json
assert_response :ok
assert JSON.parse(response.body)["success"]
end
end