Skip to content

Commit

Permalink
Tests: add channels tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ewlarson committed Sep 23, 2024
1 parent f75d778 commit 6c4e868
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ group :test do
gem 'm', '~> 1.5.0'
gem 'minitest'
gem 'minitest-ci', '~> 3.4.0'
gem "minitest-rails", "~> 7.0"
gem 'minitest-reporters'
gem 'rails-controller-testing'
gem 'simplecov', require: false
gem 'webmock', '~> 3.23'
end

gem 'net-ftp'
Expand Down
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ GEM
dry-validation (~> 1.0, >= 1.0.0)
connection_pool (2.4.1)
content_disposition (1.0.0)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
csv (3.3.0)
database_cleaner (2.0.2)
Expand Down Expand Up @@ -526,6 +529,9 @@ GEM
minitest (5.25.1)
minitest-ci (3.4.0)
minitest (>= 5.0.6)
minitest-rails (7.0.1)
minitest (~> 5.10)
railties (~> 7.0.0)
minitest-reporters (1.7.1)
ansi
builder
Expand Down Expand Up @@ -819,6 +825,10 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webmock (3.23.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webpacker (5.4.4)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
Expand Down Expand Up @@ -890,6 +900,7 @@ DEPENDENCIES
mini_magick (~> 4.9.4)
minitest
minitest-ci (~> 3.4.0)
minitest-rails (~> 7.0)
minitest-reporters
net-ftp
noticed
Expand Down Expand Up @@ -924,6 +935,7 @@ DEPENDENCIES
twitter-typeahead-rails (= 0.11.1.pre.corejavascript)
vite_rails (~> 3.0)
web-console
webmock (~> 3.23)
webpacker (~> 5.x)
whenever (~> 1.0.0)

Expand Down
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ bundle exec rake geoportal:server
## Test Locally

RAILS_ENV=test bundle exec rake geoportal:test
RAILS_ENV=test bundle exec rake test:system test
RAILS_ENV=test bundle exec rails test:system test
24 changes: 24 additions & 0 deletions test/channels/application_cable/channel_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'test_helper'

module ApplicationCable
class ChannelTest < ActiveSupport::TestCase
test "should be a subclass of ActionCable::Channel::Base" do
assert Channel < ActionCable::Channel::Base
end

test "should be defined within ApplicationCable module" do
assert_equal ApplicationCable::Channel, Channel
end

test "can be instantiated with connection and identifier" do
connection = Object.new
def connection.identifiers
[:test_identifier]
end
identifier = "test_channel"
assert_nothing_raised do
Channel.new(connection, identifier)
end
end
end
end
27 changes: 27 additions & 0 deletions test/channels/application_cable/connection_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'test_helper'

module ApplicationCable
class ConnectionTest < ActionCable::Connection::TestCase
def setup
@user = User.create(email: '[email protected]', password: 'password')
end

test "connects with authenticated user" do
# Simulate Devise authentication
warden = Minitest::Mock.new
warden.expect :user, @user

connect env: { 'warden' => warden }

assert_equal @user, connection.current_user
end

test "rejects connection without authenticated user" do
# Simulate no authenticated user
warden = Minitest::Mock.new
warden.expect :user, nil

assert_reject_connection { connect env: { 'warden' => warden } }
end
end
end
17 changes: 17 additions & 0 deletions test/channels/export_channel_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'test_helper'

class ExportChannelTest < ActionCable::Channel::TestCase
test "subscribes to export_channel" do
subscribe
assert subscription.confirmed?
assert_has_stream 'export_channel'
end

test "unsubscribes from export_channel" do
subscribe
assert subscription.confirmed?

unsubscribe
assert_no_streams
end
end
7 changes: 7 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

require "minitest/rails"
require "minitest/reporters"

require "webmock/minitest"
WebMock.enable!
WebMock.allow_net_connect!

require 'selenium/webdriver'

class ActiveSupport::TestCase
Expand Down

0 comments on commit 6c4e868

Please sign in to comment.