|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'rails_helper' |
| 4 | + |
| 5 | +module Spree |
| 6 | + RSpec.describe MergeableOrdersFinder do |
| 7 | + let(:user) { create(:user) } |
| 8 | + let(:store) { create(:store) } |
| 9 | + let(:current_order) { create(:order, user: user, store: store) } |
| 10 | + let(:context) { double('context', spree_current_user: user, current_store: store, current_order: current_order) } |
| 11 | + let(:subject) { Spree::MergeableOrdersFinder.new(context: context) } |
| 12 | + |
| 13 | + describe '#call' do |
| 14 | + let!(:incomplete_order1) { create(:order, user: user, store: store, state: 'cart') } |
| 15 | + let!(:incomplete_order2) { create(:order, user: user, store: store, state: 'address') } |
| 16 | + let!(:complete_order) { create(:order, user: user, store: store, state: 'complete').touch(:completed_at) } |
| 17 | + let!(:other_store_order) { create(:order, user: user, state: 'cart') } |
| 18 | + |
| 19 | + it 'returns incomplete orders from the same store' do |
| 20 | + orders = subject.call |
| 21 | + expect(orders).to include(incomplete_order1, incomplete_order2) |
| 22 | + expect(orders).not_to include(current_order, complete_order, other_store_order) |
| 23 | + end |
| 24 | + |
| 25 | + context 'when user is nil' do |
| 26 | + let(:context) { double('context', spree_current_user: nil, current_store: store, current_order: current_order) } |
| 27 | + |
| 28 | + it 'returns empty relation' do |
| 29 | + orders = subject.call |
| 30 | + expect(orders).to be_empty |
| 31 | + expect(orders).to eq(Spree::Order.none) |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + context 'when current_order is nil' do |
| 36 | + let(:context) { double('context', spree_current_user: user, current_store: store, current_order: nil) } |
| 37 | + |
| 38 | + it 'returns empty relation' do |
| 39 | + orders = subject.call |
| 40 | + expect(orders).to be_empty |
| 41 | + expect(orders).to eq(Spree::Order.none) |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + context 'when both user and current_order are nil' do |
| 46 | + let(:context) { double('context', spree_current_user: nil, current_store: store, current_order: nil) } |
| 47 | + |
| 48 | + it 'returns empty relation' do |
| 49 | + orders = subject.call |
| 50 | + expect(orders).to be_empty |
| 51 | + expect(orders).to eq(Spree::Order.none) |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + end |
| 56 | +end |
0 commit comments