Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/services/decidim/chatbot/workflows/proposals_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,24 @@ def send_ending
def component
@component ||= Decidim::Component.find_by(id: config[:component_id])
end

def proposals
@proposals ||= Decidim::Proposals::Proposal.where(component:).published.except_rejected.only_amendables
base = Decidim::Proposals::Proposal
.where(decidim_component_id: component.id)
.published
.only_amendables

base.where(proposal_state: none_rejected)
.or(base.where(proposal_state: nil))
end

def none_rejected
Decidim::Proposals::ProposalState
.where(decidim_component_id: component.id)
.where.not(token: "rejected")
end


def commentable_id
@commentable_id ||= received_message.button_id.to_s.start_with?("comment-") && received_message.button_id.to_s.sub("comment-", "")
end
Expand Down
33 changes: 9 additions & 24 deletions spec/services/workflows/proposals_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,20 @@ module Workflows
end
end

context "when there are exactly per_page proposals" do
context "when there are proposals without states" do
let!(:proposals) do
create_list(:proposal, 10, :evaluating, component: proposals_component, published_at: Time.current)
create_list(:proposal, 7, :evaluating, component: proposals_component, published_at: Time.current)
end

before do
allow(received_message).to receive(:user_text?).and_return(true)
allow(received_message).to receive(:actionable?).and_return(false)
end

# With 10 proposals and per_page=10: remaining = 10 - (10*1) = 0, not negative
# So it enters the main flow: mark_as_responding, send_cards, send_ending
it "sends carousel cards then ending" do
expect(adapter).to receive(:send_message!).with(hash_including(type: :interactive_carousel)).ordered
expect(adapter).to receive(:send_message!).with(hash_including(type: :interactive_buttons)).ordered
subject.start
let!(:proposals_without_states) do
create_list(:proposal, 3, component: proposals_component, published_at: Time.current)
end

it "marks as responding" do
expect(adapter).to receive(:mark_as_responding!)
subject.start
let!(:rejected_proposals) do
create_list(:proposal, 5, :rejected, component: proposals_component, published_at: Time.current)
end

it "updates page in current_workflow_options" do
subject.start
sender.reload
expect(sender.current_workflow_options["page"]).to eq(2)
it "only the none rejected proposals will be return" do
expect(subject.send(:proposals).count).to eq(10)
end
end
end

context "when there are more than per_page proposals" do
let!(:proposals) do
Expand Down