|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "rails_helper" |
| 4 | + |
| 5 | +RSpec.describe Sources::IntegrationMappingsByMappable do |
| 6 | + subject(:source) { described_class.new(integration_id) } |
| 7 | + |
| 8 | + let(:organization) { create(:organization) } |
| 9 | + let(:integration) { create(:anrok_integration, organization:) } |
| 10 | + let(:other_integration) { create(:xero_integration, organization:) } |
| 11 | + let(:integration_id) { integration.id } |
| 12 | + let(:product) { create(:product, organization:) } |
| 13 | + let(:other_product) { create(:product, organization:) } |
| 14 | + let!(:mapping) { create(:anrok_mapping, integration:, organization:, mappable: product) } |
| 15 | + let!(:other_mapping) { create(:anrok_mapping, integration:, organization:, mappable: other_product) } |
| 16 | + let!(:mapping_for_other_integration) do |
| 17 | + create(:xero_mapping, integration: other_integration, organization:, mappable: product) |
| 18 | + end |
| 19 | + |
| 20 | + describe "#fetch" do |
| 21 | + it "returns mappings for the requested integration grouped by mappable" do |
| 22 | + expect(source.fetch([product, other_product])).to eq([[mapping], [other_mapping]]) |
| 23 | + end |
| 24 | + |
| 25 | + context "without an integration ID" do |
| 26 | + let(:integration_id) { nil } |
| 27 | + |
| 28 | + it "returns all mappings grouped by mappable" do |
| 29 | + result = source.fetch([product, other_product]) |
| 30 | + |
| 31 | + expect(result.first).to match_array([mapping, mapping_for_other_integration]) |
| 32 | + expect(result.second).to eq([other_mapping]) |
| 33 | + end |
| 34 | + end |
| 35 | + end |
| 36 | +end |
0 commit comments