Skip to content

Commit

Permalink
[TAN-419] Scaffolded all types in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesspeake committed Oct 21, 2023
1 parent 496a8cd commit 7d631da
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def migrate(persist_changes)
# 8. Add phase_id to creation_phase_id of any native_surveys
update_native_survey_creation_phase(project, phase)

# 7. Activities - Do we need to update any of the historic logs? If so we should run this as a separate task - could be huge
# 9. Activities - Do we need to update any of the historic logs? If so we should run this as a separate task - could be huge

@stats[:success] = @stats[:success] + 1
end
end
Expand All @@ -52,7 +53,7 @@ def migrate(persist_changes)

def create_phase(project)
phase = Phase.new(
title_multiloc: { en: 'default' }, # TODO: Set this to the participation method name
title_multiloc: { en: 'default' }, # TODO: Set this to the participation method name - need the translations in the codebase for this
project: project,
created_at: project.created_at,
start_at: project.created_at,
Expand Down Expand Up @@ -113,9 +114,15 @@ def add_ideas_to_phase(project, phase)
Idea.where(project: project).update!(phase_ids: [phase.id])
end

def update_counts(project); end
def update_counts(phase)
Basket.update_counts(phase, 'Phase')
end

def update_native_survey_creation_phase(project, phase); end
def update_native_survey_creation_phase(project, phase)
if phase.participation_method == 'native_survey'
Idea.where(project: project).update!(creation_phase: phase)
end
end

def error_handler(error)
Rails.logger.error "ERROR: #{error}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,114 @@
RSpec.describe MultiTenancy::Rake::ContinuousProjectMigrationService do
subject(:service) { described_class.new }

describe '#migrate' do
# TODO: Create a continuous project for each participation method
shared_examples 'project_settings' do
it 'should list number of projects & successful migrations' do
expect(service.stats).to eq({ projects: 1, success: 1, errors: [] })
end

it 'changes the project type' do
expect(project.reload.process_type).to eq 'timeline'
end

it 'creates a single open ended phase for the project' do
expect(project.phases.count).to eq 1
expect(project.phases.first.end_at).to be_nil
end

it 'copies all project settings to the phase' do
phase = project.phases.first
expect(phase.participation_method).to eq project.participation_method
# TODO: Check the rest of the settings here
# TODO: Should it remove the settings from the project too?
end
end

shared_examples 'ideas' do
it 'adds ideas to the phase' do
phase = project.phases.first
project.ideas.each do |idea|
expect(idea.phases.count).to eq 1
expect(idea.phases.first).to eq phase
end
end
end

# Ideation
let_it_be(:ideation_project) { create(:continuous_project) }
let_it_be(:ideas) { create_list(:idea, 3, project: ideation_project) }
shared_examples 'permissions' do
it 'moves permissions from project to the phase' do
# TODO: Should it remove the permissions from the project too? Probably - but check what happens when creating timelines
expect(project).not_to be_nil
end
end

describe '#migrate' do
context 'without persistence' do
let_it_be(:project) { create(:continuous_project) }

before { service.migrate(false) }

it 'should list number of projects' do
it 'should list number of projects with no success' do
expect(service.stats).to eq({ projects: 1, success: 0, errors: [] })
end

it 'should not change the project type' do
expect(ideation_project.reload.process_type).to eq 'continuous'
expect(project.reload.process_type).to eq 'continuous'
end
end

context 'with persistence' do
# TODO: Can probably use before all here for speed
before { service.migrate(true) }

it 'changes the project type' do
expect(ideation_project.reload.process_type).to eq 'timeline'
context 'ideation projects' do
let_it_be(:project) { create(:continuous_project) }
let_it_be(:ideas) { create_list(:idea, 3, project: project) }

include_examples 'project_settings'
include_examples 'ideas'
end

it 'creates a single open ended phase for the project' do
expect(ideation_project.phases.count).to eq 1
expect(ideation_project.phases.first.end_at).to be_nil
context 'native surveys' do
let_it_be(:project) { create(:continuous_native_survey_project) }
let_it_be(:ideas) { create_list(:native_survey_response, 2, project: project) }

include_examples 'project_settings'
include_examples 'ideas'

it 'add the creation phase to each idea' do
phase = project.phases.first
project.ideas.each do |idea|
expect(idea.reload.creation_phase).to eq phase
end
end
end

it 'copies all project settings to the phase' do
expect(ideation_project.phases.first.participation_method).to eq 'ideation'
# TODO: Check the rest of the settings here
# TODO: Ensure some settings are not the default
context 'voting' do
let_it_be(:project) { create(:continuous_budgeting_project) }
include_examples 'project_settings'
end

it 'updates participation contexts' do
expect(ideation_project).not_to be_nil
context 'volunteering' do
let_it_be(:project) { create(:continuous_volunteering_project) }
include_examples 'project_settings'
end

it 'adds ideas to the phase' do
phase = ideation_project.phases.first
ideation_project.ideas.each do |idea|
expect(idea.phases.count).to eq 1
expect(idea.phases.first).to eq phase
end
context 'poll' do
let_it_be(:project) { create(:continuous_poll_project) }
include_examples 'project_settings'
end

context 'survey' do
let_it_be(:project) { create(:continuous_survey_project) }
include_examples 'project_settings'
end

context 'information' do
let_it_be(:project) { create(:continuous_project, participation_method: 'information') }
include_examples 'project_settings'
end

it 'should list number of projects & successful migrations' do
expect(service.stats).to eq({ projects: 1, success: 1, errors: [] })
context 'document_annotation' do
let_it_be(:project) { create(:continuous_document_annotation_project) }
include_examples 'project_settings'
end
end
end
Expand Down

0 comments on commit 7d631da

Please sign in to comment.