Skip to content

Instantly share code, notes, and snippets.

@panSarin
Created February 16, 2022 12:45
Show Gist options
  • Save panSarin/43940da15846cc83e1dace5e5acf0cf4 to your computer and use it in GitHub Desktop.
Save panSarin/43940da15846cc83e1dace5e5acf0cf4 to your computer and use it in GitHub Desktop.
services/visits/create.rb
# frozen_string_literal: true
require 'rails_helper'
describe Visits::Create do
subject { described_class.new(params).call }
let_it_be(:doctor) { create :user }
let_it_be(:patient) { create :user }
let_it_be(:slot) { create :slot, user: doctor, date: Time.current }
let_it_be(:category_cannabis) { create :category, name: 'CANNABIS' }
context 'when params are valid' do
let_it_be(:params) do
{
patient: patient,
visit_params: {
slot_id: slot.id,
category: 'CANNABIS'
}
}
end
it 'create visit' do
subject
expect(Visit.count).to eq(1)
expect(Visit.last.slot_id).to eq(slot.id)
expect(Visit.last.category_id).to eq(category_cannabis.id)
end
it 'create order' do
subject
expect(Order.count).to eq(1)
end
it 'run check_paid_worker' do
expect(CheckPaidVisitWorker).to receive(:perform_in)
subject
end
end
end
# frozen_string_literal: true
require 'rails_helper'
describe Visits::Create do
subject { described_class.new(params).call }
let_it_be(:doctor) { create :user }
let_it_be(:patient) { create :user }
let_it_be(:slot) { create :slot, user: doctor, date: Time.current }
let_it_be(:category_cannabis) { create :category, name: 'CANNABIS' }
context 'when params are valid' do
let_it_be(:params) do
{
patient: patient,
visit_params: {
slot_id: slot.id,
category: 'CANNABIS'
}
}
end
it 'create visit' do
subject
expect(Visit.count).to eq(1)
expect(Visit.last.slot_id).to eq(slot.id)
expect(Visit.last.category_id).to eq(category_cannabis.id)
end
it 'create order' do
subject
expect(Order.count).to eq(1)
end
it 'run check_paid_worker' do
expect(CheckPaidVisitWorker).to receive(:perform_in)
subject
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment