Skip to content

Commit

Permalink
4434 – Update seeds script: create imported fact checks (#1914)
Browse files Browse the repository at this point in the history
Added the creation of imported fact checks to the seeds script.

Ticket: 4434
PR: 1914
  • Loading branch information
vasconsaurus authored Jun 7, 2024
1 parent 9192faa commit 98c7f77
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def open_file(file)
end
}

BLANK_PARAMS = Array.new(8, { type: 'Blank' })

class Setup

private
Expand Down Expand Up @@ -211,14 +213,22 @@ class PopulatedWorkspaces

private

attr_reader :teams, :users, :invited_teams
attr_reader :teams, :users, :invited_teams, :bot

public

def initialize(setup)
@teams = setup.teams
@users = setup.users
@invited_teams = teams.size > 1
@bot = BotUser.fetch_user
end

def fetch_bot_installation
teams.each_value do |team|
installation = TeamBotInstallation.where(team: team, user: bot).last
bot.install_to!(team) if installation.nil?
end
end

def populate_projects
Expand All @@ -232,11 +242,12 @@ def populate_projects
media_attributes: media_params,
user: users[:main_user_a],
team: teams[:main_team_a],
channel: channel(media_params[:type]),
claim_description_attributes: {
description: claim_title(media_params),
context: Faker::Lorem.sentence,
user: users[:main_user_a],
fact_check_attributes: fact_check_params_for_half_the_claims(index, users[:main_user_a]),
user: media_params[:type] == "Blank" ? bot : users[:main_user_a],
fact_check_attributes: imported_fact_check_params(media_params[:type]) || fact_check_params_for_half_the_claims(index, users[:main_user_a]),
}
}
}
Expand All @@ -256,11 +267,12 @@ def populate_projects
media_attributes: media_params,
user: users[:invited_user_b],
team: teams[:invited_team_b1],
channel: channel(media_params[:type]),
claim_description_attributes: {
description: claim_title(media_params),
context: Faker::Lorem.sentence,
user: users[:invited_user_b],
fact_check_attributes: fact_check_params_for_half_the_claims(index, users[:invited_user_b]),
user: media_params[:type] == "Blank" ? bot : users[:invited_user_b],
fact_check_attributes: imported_fact_check_params(media_params[:type]) || fact_check_params_for_half_the_claims(index, users[:invited_user_b]),
}
}
}
Expand All @@ -274,11 +286,12 @@ def populate_projects
media_attributes: media_params,
user: users[:invited_user_b],
team: teams[:invited_team_b2],
channel: channel(media_params[:type]),
claim_description_attributes: {
description: claim_title(media_params),
context: Faker::Lorem.sentence,
user: users[:invited_user_b],
fact_check_attributes: fact_check_params_for_half_the_claims(index, users[:invited_user_b]),
user: media_params[:type] == "Blank" ? bot : users[:invited_user_b],
fact_check_attributes: imported_fact_check_params(media_params[:type]) || fact_check_params_for_half_the_claims(index, users[:invited_user_b]),
}
}
}
Expand All @@ -292,11 +305,12 @@ def populate_projects
media_attributes: media_params,
user: users[:invited_user_c],
team: teams[:invited_team_c],
channel: channel(media_params[:type]),
claim_description_attributes: {
description: claim_title(media_params),
context: Faker::Lorem.sentence,
user: users[:invited_user_c],
fact_check_attributes: fact_check_params_for_half_the_claims(index, users[:invited_user_c]),
user: media_params[:type] == "Blank" ? bot : users[:invited_user_c],
fact_check_attributes: imported_fact_check_params(media_params[:type]) || fact_check_params_for_half_the_claims(index, users[:invited_user_c]),
}
}
}
Expand Down Expand Up @@ -413,6 +427,7 @@ def medias_params
*UPLOADED_AUDIO_PARAMS,
*UPLOADED_IMAGE_PARAMS,
*UPLOADED_VIDEO_PARAMS,
*BLANK_PARAMS,
*LINK_PARAMS.call
].shuffle!
end
Expand Down Expand Up @@ -670,6 +685,24 @@ def cluster(project_media, feed, team_id)
}
Cluster.create!(cluster_params)
end

def imported_fact_check_params(media_type)
if media_type == 'Blank'
{
summary: Faker::Company.catch_phrase,
title: Faker::Company.name,
user: bot,
language: 'en',
url: get_url_for_some_fact_checks(4)
}
else
false
end
end

def channel(media_type)
media_type == "Blank" ? { main: CheckChannels::ChannelCodes::FETCH } : { main: CheckChannels::ChannelCodes::MANUAL }
end
end

puts "If you want to create a new user: press enter"
Expand All @@ -690,6 +723,7 @@ def cluster(project_media, feed, team_id)
setup = Setup.new(answer.presence) # .presence : returns nil or the string
puts 'Creating projects for all users...'
populated_workspaces = PopulatedWorkspaces.new(setup)
populated_workspaces.fetch_bot_installation
populated_workspaces.populate_projects
puts 'Creating saved searches for all teams...'
populated_workspaces.saved_searches
Expand Down

0 comments on commit 98c7f77

Please sign in to comment.