aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorTeddy Wing2018-02-07 12:50:46 +0100
committerTeddy Wing2018-02-08 11:29:31 +0100
commit6134ed98a3fe29276a17a0d79a70a8ce3e3f548b (patch)
treef52fb6a48008171ce49546be300861155617f8fe /spec
parentee1781d525bc04aff3f7f743be8297ee003ee9e0 (diff)
downloadchouette-core-6134ed98a3fe29276a17a0d79a70a8ce3e3f548b.tar.bz2
Add `ParentNotifier` service
This is a takeoff on `ParentImportNotifier`. I just copied over the class and spec and generalised the service to work with `Import`-style interfaces. We can now use the same notifier service class for both imports and compliance check sets. Refs #4758
Diffstat (limited to 'spec')
-rw-r--r--spec/services/parent_notifier_spec.rb90
1 files changed, 90 insertions, 0 deletions
diff --git a/spec/services/parent_notifier_spec.rb b/spec/services/parent_notifier_spec.rb
new file mode 100644
index 000000000..ecf508fcd
--- /dev/null
+++ b/spec/services/parent_notifier_spec.rb
@@ -0,0 +1,90 @@
+RSpec.describe ParentNotifier 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
+
+ ParentNotifier.new(Import).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)
+
+ ParentNotifier.new(Import).notify_when_finished
+ end
+ end
+
+ describe ".objects_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(
+ ParentNotifier.new(Import).objects_pending_notification
+ ).to eq([netex_import])
+ end
+
+ it "doesn't include imports without a parent" do
+ create(:import, parent: nil)
+
+ expect(
+ ParentNotifier.new(Import).objects_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(
+ ParentNotifier.new(Import).objects_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(
+ ParentNotifier.new(Import).objects_pending_notification
+ ).to be_empty
+ end
+ end
+end