2024-11-07 13:00:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-11-04 07:06:04 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe ImportsChannel, type: :channel do
|
2024-11-07 13:00:11 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
let(:import) { create(:import) }
|
|
|
|
|
|
|
|
|
|
before { stub_connection current_user: user }
|
|
|
|
|
|
|
|
|
|
describe '#subscribe' do
|
|
|
|
|
it 'confirms the subscription and subscribes to a stream' do
|
|
|
|
|
subscribe(import_id: import.id)
|
|
|
|
|
|
|
|
|
|
expect(subscription).to be_confirmed
|
|
|
|
|
expect(subscription).to have_stream_for(import)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'rejects the subscription without import_id' do
|
|
|
|
|
subscribe
|
|
|
|
|
|
|
|
|
|
expect(subscription).to be_rejected
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#broadcast' do
|
|
|
|
|
it 'broadcasts a message to the stream' do
|
|
|
|
|
subscribe(import_id: import.id)
|
|
|
|
|
|
|
|
|
|
expect do
|
|
|
|
|
ImportsChannel.broadcast_to(import, message: 'Test message')
|
|
|
|
|
end.to have_broadcasted_to(import).with(message: 'Test message')
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-11-04 07:06:04 -05:00
|
|
|
end
|