|
1 | 1 | require "test_helper" |
2 | 2 |
|
3 | 3 | class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase |
4 | | - # test "connects with cookies" do |
5 | | - # cookies.signed[:user_id] = 42 |
6 | | - # |
7 | | - # connect |
8 | | - # |
9 | | - # assert_equal connection.user_id, "42" |
10 | | - # end |
| 4 | + test "anonymous connection succeeds with nil shopkeeper and account" do |
| 5 | + connect |
| 6 | + |
| 7 | + assert_nil connection.current_shopkeeper |
| 8 | + assert_nil connection.current_account |
| 9 | + end |
| 10 | + |
| 11 | + test "authenticated connection identifies shopkeeper and account" do |
| 12 | + shopkeeper = shopkeepers(:one) |
| 13 | + account = shopkeeper.create_default_account |
| 14 | + warden = Minitest::Mock.new |
| 15 | + warden.expect(:user, shopkeeper, [:shopkeeper]) |
| 16 | + |
| 17 | + connect "/#{account.id}/cable", env: {"warden" => warden} |
| 18 | + |
| 19 | + assert_equal shopkeeper, connection.current_shopkeeper |
| 20 | + assert_equal account, connection.current_account |
| 21 | + warden.verify |
| 22 | + end |
| 23 | + |
| 24 | + test "connection without account UUID in path has nil account" do |
| 25 | + shopkeeper = shopkeepers(:one) |
| 26 | + warden = Minitest::Mock.new |
| 27 | + warden.expect(:user, shopkeeper, [:shopkeeper]) |
| 28 | + |
| 29 | + connect "/cable", env: {"warden" => warden} |
| 30 | + |
| 31 | + assert_equal shopkeeper, connection.current_shopkeeper |
| 32 | + assert_nil connection.current_account |
| 33 | + warden.verify |
| 34 | + end |
11 | 35 | end |
0 commit comments