1
0

bulk_import_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe BulkImport do
  4. describe 'Associations' do
  5. it { is_expected.to belong_to(:account).required }
  6. it { is_expected.to have_many(:rows).class_name('BulkImportRow').inverse_of(:bulk_import).dependent(:delete_all) }
  7. end
  8. describe 'Validations' do
  9. subject { Fabricate.build :bulk_import }
  10. it { is_expected.to validate_presence_of(:type) }
  11. end
  12. describe 'Scopes' do
  13. describe '.archival_completed' do
  14. let!(:old_import) { Fabricate :bulk_import, created_at: 1.month.ago }
  15. let!(:new_import) { Fabricate :bulk_import, created_at: 1.day.ago }
  16. it 'returns imports which have passed the archive window period' do
  17. expect(described_class.archival_completed)
  18. .to include(old_import)
  19. .and not_include(new_import)
  20. end
  21. end
  22. describe '.confirmation_missed' do
  23. let!(:old_unconfirmed_import) { Fabricate :bulk_import, created_at: 1.week.ago, state: :unconfirmed }
  24. let!(:old_scheduled_import) { Fabricate :bulk_import, created_at: 1.week.ago, state: :scheduled }
  25. let!(:new_unconfirmed_import) { Fabricate :bulk_import, created_at: 1.minute.ago, state: :unconfirmed }
  26. it 'returns imports which have passed the confirmation window without confirming' do
  27. expect(described_class.confirmation_missed)
  28. .to include(old_unconfirmed_import)
  29. .and not_include(old_scheduled_import)
  30. .and not_include(new_unconfirmed_import)
  31. end
  32. end
  33. end
  34. end