diff options
| author | Robert Dober | 2017-08-03 11:19:47 +0200 |
|---|---|---|
| committer | GitHub | 2017-08-03 11:19:47 +0200 |
| commit | 494fdfab76e6557018de77dac6861513ffa0502b (patch) | |
| tree | 7488393cfe925334893e78a7a3983ded78167267 /spec/services | |
| parent | 8aba37303c2c2bd95df8c5117173579b3399c2c7 (diff) | |
| parent | 517495a48e2a05c301159fc48573a9994fbff47b (diff) | |
| download | chouette-core-494fdfab76e6557018de77dac6861513ffa0502b.tar.bz2 | |
Merge pull request #50 from af83/3511-cron-job-to-notify-parent-WorkbenchImport-of-sub-import-status--rb201708011853
3511 cron job to notify parent workbench import of sub import status rb201708011853
Diffstat (limited to 'spec/services')
| -rw-r--r-- | spec/services/parent_import_notifier_spec.rb | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/spec/services/parent_import_notifier_spec.rb b/spec/services/parent_import_notifier_spec.rb new file mode 100644 index 000000000..3ab505f88 --- /dev/null +++ b/spec/services/parent_import_notifier_spec.rb @@ -0,0 +1,90 @@ +RSpec.describe ParentImportNotifier do + let(:workbench_import) { create(:workbench_import) } + + describe ".notify_when_finished" do + it "calls #notify_parent on finished imports" do + workbench_import = build_stubbed(:workbench_import) + + finished_statuses = [:failed, :successful, :aborted, :canceled] + netex_imports = [] + + finished_statuses.each do |status| + netex_imports << build_stubbed( + :netex_import, + parent: workbench_import, + status: status + ) + end + + netex_imports.each do |netex_import| + expect(netex_import).to receive(:notify_parent) + end + + ParentImportNotifier.notify_when_finished(netex_imports) + end + + it "doesn't call #notify_parent if its `notified_parent_at` is set" do + netex_import = create( + :netex_import, + parent: workbench_import, + status: :failed, + notified_parent_at: DateTime.now + ) + + expect(netex_import).not_to receive(:notify_parent) + + ParentImportNotifier.notify_when_finished + end + end + + describe ".imports_pending_notification" do + it "includes imports with a parent and `notified_parent_at` unset" do + netex_import = create( + :netex_import, + parent: workbench_import, + status: :successful, + notified_parent_at: nil + ) + + expect( + ParentImportNotifier.imports_pending_notification + ).to eq([netex_import]) + end + + it "doesn't include imports without a parent" do + create(:import, parent: nil) + + expect( + ParentImportNotifier.imports_pending_notification + ).to be_empty + end + + it "doesn't include imports that aren't finished" do + [:new, :pending, :running].each do |status| + create( + :netex_import, + parent: workbench_import, + status: status, + notified_parent_at: nil + ) + end + + expect( + ParentImportNotifier.imports_pending_notification + ).to be_empty + end + + it "doesn't include imports that have already notified their parent" do + create( + :netex_import, + parent: workbench_import, + status: :successful, + notified_parent_at: DateTime.now + ) + + expect( + ParentImportNotifier.imports_pending_notification + ).to be_empty + end + end +end |
