From 55fdd201b2f862cdbde5bed8ea679ce28f587609 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Sat, 2 Feb 2019 17:42:28 +0100 Subject: [PATCH] Add additional checks --- .../model_importers/team_importer_spec.rb | 71 +++++++++++++------ 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/spec/services/model_importers/team_importer_spec.rb b/spec/services/model_importers/team_importer_spec.rb index 3f7427750..28b2517d9 100644 --- a/spec/services/model_importers/team_importer_spec.rb +++ b/spec/services/model_importers/team_importer_spec.rb @@ -3,8 +3,15 @@ require 'rails_helper' describe TeamImporter do + + def check_module(json_module, db_module) + it { expect(my_module.dig('my_module', 'name')).to be_a(String) } + end describe '#import_template_experiment_from_dir' do context 'successful import of all different elements with given json' do + + TEMPLATE_DIR = "#{Rails.root}/spec/services/model_importers/" \ + "test_experiment_data" before :all do time = Time.new(2015, 8, 1, 14, 35, 0) create :user, email: Faker::Internet.email @@ -16,35 +23,57 @@ describe TeamImporter do @project = create :project, name: 'Project', visibility: 1, team: @team, archived: false, created_at: time - @team_importer = TeamImporter.new + @json = @team_importer = TeamImporter.new @exp = @team_importer - .import_template_experiment_from_dir( - 'spec/services/model_importers/test_experiment_data', - 2, 2 - ) + .import_template_experiment_from_dir(TEMPLATE_DIR, 2, 2) end - it { expect(@exp.id).to eq 1 } - it { expect(@exp.project.id).to eq 2 } - it { expect(@exp.name).to eq 'Experiment export' } - it { expect(@exp.description).to eq 'My description' } + describe 'Experiment variables' do + it { expect(@exp.id).to eq 1 } + it { expect(@exp.project.id).to eq 2 } + it { expect(@exp.name).to eq 'Experiment export' } + it { expect(@exp.description).to eq 'My description' } - it { expect(@exp.created_at).to eq '2019-01-21T13:27:53.342Z' } - it { expect(@exp.created_by.id).to eq 2 } - it { expect(@exp.last_modified_by.id).to eq 2 } + it { expect(@exp.created_at).to eq '2019-01-21T13:27:53.342Z' } + it { expect(@exp.created_by.id).to eq 2 } + it { expect(@exp.last_modified_by.id).to eq 2 } - it { expect(@exp.archived).to eq false } - it { expect(@exp.archived_by_id).to be_nil } - it { expect(@exp.archived_on).to be_nil } + it { expect(@exp.archived).to eq false } + it { expect(@exp.archived_by_id).to be_nil } + it { expect(@exp.archived_on).to be_nil } - it { expect(@exp.restored_by_id).to be_nil } - it { expect(@exp.restored_on).to be_nil } + it { expect(@exp.restored_by_id).to be_nil } + it { expect(@exp.restored_on).to be_nil } - it { expect(@exp.workflowimg_updated_at).to eq '2019-01-21T13:31:04.682Z' } - it { expect(@exp.workflowimg_file_size).to eq 4581 } + it { expect(@exp.workflowimg_updated_at).to eq '2019-01-21T13:31:04.682Z' } + it { expect(@exp.workflowimg_file_size).to eq 4581 } + end - # Module groups - it { expect(@exp.my_module_groups.count).to eq 2 } + describe 'Module groups' do + # Module groups + it { expect(@exp.my_module_groups.count).to eq 2 } + it { expect(@exp.my_module_groups.pluck(:created_by_id)).to all eq 2 } + it { expect(@exp.my_module_groups.pluck(:created_at)).to( + match_array(['2019-01-21T13:32:46.449Z'.to_time, + '2019-01-21T13:32:46.460Z'.to_time])) } + it { expect(@exp.my_module_groups.pluck(:updated_at)).to( + match_array(['2019-01-21T13:32:46.449Z'.to_time, + '2019-01-21T13:32:46.460Z'.to_time])) } + it { expect(@exp.modules_without_group.count).to( + eq 1) } + it { expect(@exp.my_modules.where(my_module_group: nil).count).to( + eq 2) } + it { expect(@exp.archived_modules.count).to( + eq 1) } + end + + describe 'Modules' do + @json = JSON.parse(File.read("#{TEMPLATE_DIR}" \ + "/experiment_export.json")) + @json['my_modules'].each do |my_module| + check_module(my_module, '') + end + end end end end