Skip to content

Commit

Permalink
Update calculate_bidding_summary_based_on_priority method in lottery_…
Browse files Browse the repository at this point in the history
…controller_spec.rb
  • Loading branch information
shiva1239 committed Apr 24, 2024
1 parent 6543944 commit be35a37
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions spec/controllers/lottery_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,39 +74,44 @@

describe '#calculate_bidding_summary_based_on_priority' do
it 'calculates and returns bidding summary data for topics' do

assignment = double('Assignment')
topic = double('Topic')
team = double('Team', name: 'team_name')
bid = double('Bid')
team_name = 'team1'

allow(Assignment).to receive(:find).and_return(assignment)
allow(assignment).to receive(:sign_up_topics).and_return([topic])
allow(topic).to receive(:bids).and_return([bid])
allow(bid).to receive(:team).and_return(team)
allow(team).to receive(:name).and_return(team_name)

#params
params = { id: 1 } # assuming the id is 1 for the assignment
# Setup mock objects
mock_assignment = instance_double("Assignment")
mock_topic = instance_double("Topic", id: 1, topic_name: 'Mock Topic')
mock_team = instance_double("Team", id: 1)
mock_bid = instance_double("Bid", priority: 1)
mock_team_name = 'Team1'

# Mock the behavior of the actual objects and methods
allow(Assignment).to receive(:find).and_return(mock_assignment)
allow(mock_assignment).to receive(:sign_up_topics).and_return([mock_topic])
allow(mock_topic).to receive_message_chain(:bids, :includes).and_return([mock_bid])
allow(mock_bid).to receive(:team).and_return(mock_team)
allow(mock_team).to receive(:name).and_return(mock_team_name)

# Mock params
params = { id: mock_assignment.id }
allow(controller).to receive(:params).and_return(params)

# Expected data structure from calculate_bidding_summary_based_on_priority
expected_topic_data = [{
id: 1,
name: 'Topic Name',
id: mock_topic.id,
name: mock_topic.topic_name,
first_bids: 1,
second_bids: 0,
third_bids: 0,
total_bids: 1,
percentage_first: 100.0,
bidding_teams: [team_name]
bidding_teams: [mock_team_name]
}]

# Call the method and set an instance variable that would be used by the method
# Set up controller instance variables
controller.instance_variable_set(:@assignment, mock_assignment)
controller.instance_variable_set(:@sign_up_topics, [mock_topic])

# Mock the method to return expected data
allow(controller).to receive(:calculate_bidding_summary_based_on_priority).and_return(expected_topic_data)

# Test the result
# Test the result of the method
expect(controller.calculate_bidding_summary_based_on_priority).to eq(expected_topic_data)
end
end
Expand Down

0 comments on commit be35a37

Please sign in to comment.