Skip to content

Commit

Permalink
missing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mensfeld committed Aug 22, 2024
1 parent a66679f commit b02795d
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,64 @@
expect(message.payload[:task][:id]).to eq('*')
end
end

describe '#enable' do
before { post 'recurring_tasks/task1/enable' }

it do
expect(response.status).to eq(302)
# Taken from referer and referer is nil in specs
expect(response.location).to eq(nil)
end

it 'expect to create new command' do
# Dispatch of commands is async, so we have to wait
sleep(1)
message = Karafka::Admin.read_topic(schedules_topic, 0, 1, -1).first
expect(message.key).to eq('command:enable:task1')
expect(message.payload[:type]).to eq('command')
expect(message.payload[:command][:name]).to eq('enable')
expect(message.payload[:task][:id]).to eq('task1')
end
end

describe '#disable' do
before { post 'recurring_tasks/task1/disable' }

it do
expect(response.status).to eq(302)
# Taken from referer and referer is nil in specs
expect(response.location).to eq(nil)
end

it 'expect to create new command' do
# Dispatch of commands is async, so we have to wait
sleep(1)
message = Karafka::Admin.read_topic(schedules_topic, 0, 1, -1).first
expect(message.key).to eq('command:disable:task1')
expect(message.payload[:type]).to eq('command')
expect(message.payload[:command][:name]).to eq('disable')
expect(message.payload[:task][:id]).to eq('task1')
end
end

describe '#trigger' do
before { post 'recurring_tasks/task1/trigger' }

it do
expect(response.status).to eq(302)
# Taken from referer and referer is nil in specs
expect(response.location).to eq(nil)
end

it 'expect to create new command' do
# Dispatch of commands is async, so we have to wait
sleep(1)
message = Karafka::Admin.read_topic(schedules_topic, 0, 1, -1).first
expect(message.key).to eq('command:trigger:task1')
expect(message.payload[:type]).to eq('command')
expect(message.payload[:command][:name]).to eq('trigger')
expect(message.payload[:task][:id]).to eq('task1')
end
end
end
7 changes: 7 additions & 0 deletions spec/lib/karafka/web/ui/models/recurring_tasks/log_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

RSpec.describe_current do
subject(:log) { described_class }

it { expect(log).to be < Karafka::Web::Ui::Lib::HashProxy }
end
30 changes: 30 additions & 0 deletions spec/lib/karafka/web/ui/models/recurring_tasks/schedule_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

RSpec.describe_current do
subject(:schedule) { described_class.new(attrs) }

let(:attrs) { { tasks: {} } }

describe '#tasks' do
context 'when no tasks' do
it { expect(schedule.tasks).to eq([]) }
end

context 'when tasks are present' do
let(:attrs) do
{
tasks: {
task1: {
id: 'task1',
cron: '* * * * *'
}
}
}
end

it { expect(schedule.tasks.first).to be_a(Karafka::Web::Ui::Models::RecurringTasks::Task) }
it { expect(schedule.tasks).to be_a(Array) }
it { expect(schedule.tasks.first.id).to eq('task1') }
end
end
end
21 changes: 21 additions & 0 deletions spec/lib/karafka/web/ui/models/recurring_tasks/task_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

RSpec.describe_current do
subject(:task) { described_class.new(attrs) }

let(:attrs) { { enabled: true } }

it { expect(task.class).to be < Karafka::Web::Ui::Lib::HashProxy }

describe '#enabled?' do
context 'when enabled' do
it { expect(task.enabled?).to eq(true) }
end

context 'when disabled' do
let(:attrs) { { enabled: false } }

it { expect(task.enabled?).to eq(false) }
end
end
end

0 comments on commit b02795d

Please sign in to comment.