dawarich/spec/jobs/owntracks/point_creating_job_spec.rb

41 lines
1 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
require 'rails_helper'
2024-04-06 13:09:38 -04:00
RSpec.describe Owntracks::PointCreatingJob, type: :job do
describe '#perform' do
2024-05-25 07:26:56 -04:00
subject(:perform) { described_class.new.perform(point_params, user.id) }
let(:point_params) do
{ lat: 1.0, lon: 1.0, tid: 'test', tst: Time.now.to_i, topic: 'iPhone 12 pro' }
end
2024-05-25 07:26:56 -04:00
let(:user) { create(:user) }
it 'creates a point' do
expect { perform }.to change { Point.count }.by(1)
end
2024-05-25 07:26:56 -04:00
it 'creates a point with the correct user_id' do
perform
expect(Point.last.user_id).to eq(user.id)
end
context 'when point already exists' do
it 'does not create a point' do
perform
expect { perform }.not_to(change { Point.count })
end
end
2025-07-20 11:43:55 -04:00
context 'when point is invalid' do
let(:point_params) { { lat: 1.0, lon: 1.0, tid: 'test', tst: nil, topic: 'iPhone 12 pro' } }
it 'does not create a point' do
expect { perform }.not_to(change { Point.count })
end
end
end
end