Skip to content

Commit

Permalink
Temporary commit to add document collection matching
Browse files Browse the repository at this point in the history
I'll put this in its own PR. Just commiting here to see if it performs
better than #1803
  • Loading branch information
hannako committed Nov 21, 2022
1 parent c534797 commit 55d2043
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/queries/subscriber_list_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class SubscriberListQuery
def initialize(content_id:, tags:, links:, document_type:, email_document_supertype:, government_document_supertype:)
@content_id = content_id
@tags = tags.symbolize_keys
@links = links.symbolize_keys
@links = links.deep_symbolize_keys
@document_type = document_type
@email_document_supertype = email_document_supertype
@government_document_supertype = government_document_supertype
Expand All @@ -13,7 +13,8 @@ def lists
lists_matched_on_document_types_and_links +
lists_matched_on_document_types_and_tags +
lists_matched_on_document_types_only +
lists_matched_on_content_id_only
lists_matched_on_content_id_only +
lists_matched_on_document_collection_id
).uniq(&:id)
end

Expand All @@ -35,6 +36,18 @@ def lists_matched_on_content_id_only
FindWithoutLinksAndTags.new(scope: content_id_scope).call
end

def lists_matched_on_document_collection_id
return [] unless document_collection_ids

document_collection_ids.flat_map do |id|
FindWithoutLinksAndTags.new(scope: content_id_scope(id)).call
end
end

def document_collection_ids
@links[:document_collections].presence
end

def document_type_scope
SubscriberList
.where(content_id: nil)
Expand All @@ -43,8 +56,8 @@ def document_type_scope
.where(government_document_supertype: ["", @government_document_supertype])
end

def content_id_scope
def content_id_scope(content_id = @content_id)
SubscriberList
.where(content_id: @content_id)
.where(content_id:)
end
end
16 changes: 16 additions & 0 deletions spec/queries/subscriber_list_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@
subscriber_list = create_subscriber_list(default_list_attributes.merge(content_id: no_match_content_id))
expect(subject.lists).not_to include(subscriber_list)
end

context "when matching on document collection id" do
let(:document_collection_id) { "4d74904a-e45e-47e4-921d-c9dc13c8c9de" }
let(:document_collection_attributes) { { links: { document_collections: [document_collection_id] } } }
let(:query) { described_class.new(**content_change_attributes.merge(document_collection_attributes)) }

it "includes lists where the content id matches the document_collection_id" do
subscriber_list = create_subscriber_list(default_list_attributes.merge(content_id: document_collection_id))
expect(query.lists).to include(subscriber_list)
end

it "excludes lists where the content id does not match the document_collection_id" do
subscriber_list = create_subscriber_list(default_list_attributes.merge(content_id: no_match_content_id))
expect(query.lists).not_to include(subscriber_list)
end
end
end

def create_subscriber_list(options)
Expand Down

0 comments on commit 55d2043

Please sign in to comment.