|
| 1 | +# (C) 2019-2020 GoodData Corporation |
| 2 | +require 'gooddata' |
| 3 | + |
| 4 | +describe 'Should upgrade custom v2 for project', :vcr, :constraint => 'slow' do |
| 5 | + before(:all) do |
| 6 | + @client = ConnectionHelper.create_default_connection |
| 7 | + @blueprint = GoodData::Model::ProjectBlueprint.from_json('./spec/data/blueprints/old_date_dimension.json') |
| 8 | + end |
| 9 | + |
| 10 | + after(:all) do |
| 11 | + @client&.disconnect |
| 12 | + end |
| 13 | + |
| 14 | + it 'upgrade all date dimension to custom v2' do |
| 15 | + to_project = @client&.create_project_from_blueprint(@blueprint, auth_token: ConnectionHelper::SECRETS[:gd_project_token], environment: ProjectHelper::ENVIRONMENT) |
| 16 | + blueprint = to_project.blueprint(include_ca: true) |
| 17 | + date_old = GoodData::Model::ProjectBlueprint.date_dimensions(blueprint) |
| 18 | + |
| 19 | + expect(date_old).not_to be_nil |
| 20 | + date_old.each do |date| |
| 21 | + expect(%w[datecustom dategooddata].any? { |e| date[:id] == e }).to be_truthy |
| 22 | + expect(GoodData::LCM2::MigrateGdcDateDimension::DATE_DIMENSION_OLD.any? { |e| date[:urn]&.include?(e) }).to be_truthy |
| 23 | + end |
| 24 | + |
| 25 | + message = get_upgrade_message(true, nil) |
| 26 | + to_project&.upgrade_custom_v2(message) |
| 27 | + |
| 28 | + blueprint = to_project.blueprint(include_ca: true) |
| 29 | + date_new = GoodData::Model::ProjectBlueprint.date_dimensions(blueprint) |
| 30 | + expect(date_new).not_to be_nil |
| 31 | + date_new.each do |date| |
| 32 | + expect(%w[datecustom dategooddata].any? { |e| date[:id] == e }).to be_truthy |
| 33 | + expect(date[:urn]&.include?(GoodData::LCM2::MigrateGdcDateDimension::DATE_DIMENSION_CUSTOM_V2)).to be_truthy |
| 34 | + end |
| 35 | + |
| 36 | + to_project&.delete |
| 37 | + end |
| 38 | + |
| 39 | + it 'upgrade a date dimension to custom v2' do |
| 40 | + to_project = @client&.create_project_from_blueprint(@blueprint, auth_token: ConnectionHelper::SECRETS[:gd_project_token], environment: ProjectHelper::ENVIRONMENT) |
| 41 | + blueprint = to_project.blueprint(include_ca: true) |
| 42 | + date_old = GoodData::Model::ProjectBlueprint.date_dimensions(blueprint) |
| 43 | + |
| 44 | + expect(date_old).not_to be_nil |
| 45 | + date_old.each do |date| |
| 46 | + expect(%w[datecustom dategooddata].any? { |e| date[:id] == e }).to be_truthy |
| 47 | + expect(GoodData::LCM2::MigrateGdcDateDimension::DATE_DIMENSION_OLD.any? { |e| date[:urn]&.include?(e) }).to be_truthy |
| 48 | + end |
| 49 | + |
| 50 | + message = get_upgrade_message(false, ['datecustom.dataset.dt']) |
| 51 | + to_project&.upgrade_custom_v2(message) |
| 52 | + |
| 53 | + blueprint = to_project.blueprint(include_ca: true) |
| 54 | + date_new = GoodData::Model::ProjectBlueprint.date_dimensions(blueprint) |
| 55 | + expect(date_new).not_to be_nil |
| 56 | + date_new.each do |date| |
| 57 | + expect(%w[datecustom dategooddata].any? { |e| date[:id] == e }).to be_truthy |
| 58 | + if date[:id] == 'datecustom' |
| 59 | + expect(date[:urn]&.include?(GoodData::LCM2::MigrateGdcDateDimension::DATE_DIMENSION_CUSTOM_V2)).to be_truthy |
| 60 | + else |
| 61 | + expect(date[:urn]&.include?('gooddata')).to be_truthy |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + to_project&.delete |
| 66 | + end |
| 67 | + |
| 68 | + it 'upgrade multiple date dimension to custom v2' do |
| 69 | + to_project = @client&.create_project_from_blueprint(@blueprint, auth_token: ConnectionHelper::SECRETS[:gd_project_token], environment: ProjectHelper::ENVIRONMENT) |
| 70 | + blueprint = to_project.blueprint(include_ca: true) |
| 71 | + date_old = GoodData::Model::ProjectBlueprint.date_dimensions(blueprint) |
| 72 | + |
| 73 | + expect(date_old).not_to be_nil |
| 74 | + date_old.each do |date| |
| 75 | + expect(%w[datecustom dategooddata].any? { |e| date[:id] == e }).to be_truthy |
| 76 | + expect(GoodData::LCM2::MigrateGdcDateDimension::DATE_DIMENSION_OLD.any? { |e| date[:urn]&.include?(e) }).to be_truthy |
| 77 | + end |
| 78 | + |
| 79 | + message = get_upgrade_message(false, ['datecustom.dataset.dt','dategooddata.dataset.dt']) |
| 80 | + to_project&.upgrade_custom_v2(message) |
| 81 | + |
| 82 | + blueprint = to_project.blueprint(include_ca: true) |
| 83 | + date_new = GoodData::Model::ProjectBlueprint.date_dimensions(blueprint) |
| 84 | + expect(date_new).not_to be_nil |
| 85 | + date_new.each do |date| |
| 86 | + expect(%w[datecustom dategooddata].any? { |e| date[:id] == e }).to be_truthy |
| 87 | + expect(date[:urn]&.include?(GoodData::LCM2::MigrateGdcDateDimension::DATE_DIMENSION_CUSTOM_V2)).to be_truthy |
| 88 | + end |
| 89 | + |
| 90 | + to_project&.delete |
| 91 | + end |
| 92 | + |
| 93 | + def get_upgrade_message(is_all, upgrade_datasets) |
| 94 | + if is_all |
| 95 | + { |
| 96 | + upgrade: { |
| 97 | + dateDatasets: { |
| 98 | + upgrade: "all" |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + else |
| 103 | + { |
| 104 | + upgrade: { |
| 105 | + dateDatasets: { |
| 106 | + upgrade: "exact", |
| 107 | + datasets: upgrade_datasets |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + end |
| 112 | + end |
| 113 | +end |
0 commit comments