Skip to content

Commit

Permalink
Allow content-id based subscriber lists to match on reverse links
Browse files Browse the repository at this point in the history
  • Loading branch information
hannako committed Dec 16, 2022
1 parent 3dbe505 commit 2645bb9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/queries/subscriber_list_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def lists
lists_matched_on_links +
lists_matched_on_tags +
lists_matched_on_document_type_only +
lists_matched_on_content_id_only
lists_matched_on_content_id_only +
lists_with_content_id_matched_on_links
).uniq(&:id)
end

Expand All @@ -27,6 +28,11 @@ def lists_matched_on_links
MatchedForNotification.new(query_field: :links, scope: document_type_scope).call(@links)
end

def lists_with_content_id_matched_on_links
lists_with_content_id = SubscriberList.where.not(content_id: nil)
MatchedForNotification.new(query_field: :links, scope: lists_with_content_id).call(@links)
end

def lists_matched_on_document_type_only
FindWithoutLinksAndTags.new(scope: document_type_scope).call
end
Expand Down
35 changes: 35 additions & 0 deletions spec/queries/subscriber_list_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,41 @@
end
end

context "when list has reverse links" do
let(:document_collection_id) { "4d74904a-e45e-47e4-921d-c9dc13c8c9de" }
let(:just_another_content_id) { "d876e220-6806-4148-9060-e393d1ff8f3e" }
let(:list_params) do
{ content_id: document_collection_id,
links: { document_collections: { any: [document_collection_id] } } }
end

it "includes list where the content id matches, but links do not" do
subscriber_list = create_subscriber_list(list_params)
query_params = { content_id: document_collection_id, links: {} }
query = described_class.new(**content_change_attributes.merge(query_params))
expect(query.lists).to include(subscriber_list)
end

it "includes list where links match, but content id does not" do
subscriber_list = create_subscriber_list(default_list_attributes.merge(list_params))
query_params = {
content_id: just_another_content_id,
links: { document_collections: [document_collection_id] },
}
query = described_class.new(**content_change_attributes.merge(query_params))

expect(query.lists).to include(subscriber_list)
end

it "excludes lists where the content id does not match and links do not match" do
subscriber_list = create_subscriber_list(default_list_attributes.merge(list_params))
query_params = { content_id: just_another_content_id, links: {} }
query = described_class.new(**content_change_attributes.merge(query_params))

expect(query.lists).not_to include(subscriber_list)
end
end

def create_subscriber_list(options)
create(:subscriber_list, options)
end
Expand Down

0 comments on commit 2645bb9

Please sign in to comment.