Skip to content

Commit 208da8d

Browse files
Add tests for user reactivation feature
1 parent cec4722 commit 208da8d

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

test/controllers/join_codes_controller_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ class JoinCodesControllerTest < ActionDispatch::IntegrationTest
5555
assert_redirected_to landing_url(script_name: @account.slug)
5656
end
5757

58+
test "create for existing identity with deactivated user" do
59+
identity = identities(:kevin)
60+
user = users(:kevin)
61+
62+
sign_in_as :kevin
63+
64+
assert user.setup?, "Kevin should be setup for this test"
65+
user.deactivate
66+
67+
assert_not user.reload.active?, "user should be inactive after deactivation"
68+
assert_equal identity.id, user.identity_id, "identity link should be preserved after deactivation"
69+
70+
assert_no_difference -> { User.count } do
71+
post join_path(code: @join_code.code, script_name: @account.slug), params: { email_address: identity.email_address }
72+
end
73+
74+
user.reload
75+
assert user.active?, "user should be reactivated after joining"
76+
assert_redirected_to landing_url(script_name: @account.slug)
77+
end
78+
5879
test "create for signed-in identity without a user in the account redirects to verification" do
5980
identity = identities(:mike)
6081
sign_in_as :mike

test/models/identity/joinable_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,26 @@ class Identity::JoinableTest < ActiveSupport::TestCase
3434
assert_not result, "join should return false when user already exists"
3535
end
3636
end
37+
38+
test "join reactivates a deactivated user" do
39+
identity = identities(:kevin)
40+
account = accounts("37s")
41+
user = users(:kevin)
42+
43+
user.stubs(:close_remote_connections)
44+
user.deactivate
45+
46+
assert_not user.reload.active?, "user should be inactive after deactivation"
47+
assert_empty user.accesses, "user should have no accesses after deactivation"
48+
assert_equal identity.id, user.identity_id, "identity link should be preserved after deactivation"
49+
50+
assert_no_difference -> { User.count } do
51+
result = identity.join(account)
52+
assert_not result, "join should return false for reactivation"
53+
end
54+
55+
user.reload
56+
assert user.active?, "user should be active after reactivation"
57+
assert user.accesses.any?, "user should have accesses restored after reactivation"
58+
end
3759
end

0 commit comments

Comments
 (0)