2022-03-30 00:09:03 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Projects::RecordTargetPlatformsService, '#execute' do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
2022-05-05 21:09:10 +00:00
|
|
|
let(:detector_service) { Projects::AppleTargetPlatformDetectorService }
|
2022-03-30 00:09:03 +00:00
|
|
|
|
2022-05-05 21:09:10 +00:00
|
|
|
subject(:execute) { described_class.new(project, detector_service).execute }
|
|
|
|
|
|
|
|
context 'when detector returns target platform values' do
|
|
|
|
let(:detector_result) { [:ios, :osx] }
|
|
|
|
let(:service_result) { detector_result.map(&:to_s) }
|
2022-04-22 18:09:22 +00:00
|
|
|
|
2022-03-30 00:09:03 +00:00
|
|
|
before do
|
2022-05-05 21:09:10 +00:00
|
|
|
double = instance_double(detector_service, execute: detector_result)
|
|
|
|
allow(detector_service).to receive(:new) { double }
|
2022-03-30 00:09:03 +00:00
|
|
|
end
|
|
|
|
|
2022-05-05 21:09:10 +00:00
|
|
|
shared_examples 'saves and returns detected target platforms' do
|
|
|
|
it 'creates a new setting record for the project', :aggregate_failures do
|
|
|
|
expect { execute }.to change { ProjectSetting.count }.from(0).to(1)
|
|
|
|
expect(ProjectSetting.last.target_platforms).to match_array(service_result)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the array of stored target platforms' do
|
|
|
|
expect(execute).to match_array service_result
|
|
|
|
end
|
2022-03-30 00:09:03 +00:00
|
|
|
end
|
|
|
|
|
2022-05-05 21:09:10 +00:00
|
|
|
it_behaves_like 'saves and returns detected target platforms'
|
|
|
|
|
|
|
|
context 'when detector returns a non-array value' do
|
|
|
|
let(:detector_service) { Projects::AndroidTargetPlatformDetectorService }
|
|
|
|
let(:detector_result) { :android }
|
|
|
|
let(:service_result) { [detector_result.to_s] }
|
|
|
|
|
|
|
|
it_behaves_like 'saves and returns detected target platforms'
|
2022-03-30 00:09:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a project has an existing setting record' do
|
|
|
|
before do
|
|
|
|
create(:project_setting, project: project, target_platforms: saved_target_platforms)
|
|
|
|
end
|
|
|
|
|
2022-05-05 21:09:10 +00:00
|
|
|
def project_setting
|
|
|
|
ProjectSetting.find_by_project_id(project.id)
|
|
|
|
end
|
|
|
|
|
2022-03-30 00:09:03 +00:00
|
|
|
context 'when target platforms changed' do
|
|
|
|
let(:saved_target_platforms) { %w(tvos) }
|
|
|
|
|
|
|
|
it 'updates' do
|
|
|
|
expect { execute }.to change { project_setting.target_platforms }.from(%w(tvos)).to(%w(ios osx))
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match_array %w(ios osx) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when target platforms are the same' do
|
|
|
|
let(:saved_target_platforms) { %w(osx ios) }
|
|
|
|
|
|
|
|
it 'does not update' do
|
|
|
|
expect { execute }.not_to change { project_setting.updated_at }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-04-22 18:09:22 +00:00
|
|
|
|
|
|
|
describe 'Build iOS guide email experiment' do
|
|
|
|
shared_examples 'tracks experiment assignment event' do
|
|
|
|
it 'tracks the assignment event', :experiment do
|
|
|
|
expect(experiment(:build_ios_app_guide_email))
|
|
|
|
.to track(:assignment)
|
|
|
|
.with_context(project: project)
|
|
|
|
.on_next_instance
|
|
|
|
|
|
|
|
execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'experiment candidate' do
|
|
|
|
before do
|
|
|
|
stub_experiments(build_ios_app_guide_email: :candidate)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'executes a Projects::InProductMarketingCampaignEmailsService' do
|
|
|
|
service_double = instance_double(Projects::InProductMarketingCampaignEmailsService, execute: true)
|
|
|
|
|
|
|
|
expect(Projects::InProductMarketingCampaignEmailsService)
|
|
|
|
.to receive(:new).with(project, Users::InProductMarketingEmail::BUILD_IOS_APP_GUIDE)
|
|
|
|
.and_return service_double
|
|
|
|
expect(service_double).to receive(:execute)
|
|
|
|
|
|
|
|
execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'tracks experiment assignment event'
|
|
|
|
end
|
|
|
|
|
2022-05-05 21:09:10 +00:00
|
|
|
shared_examples 'does not send email' do
|
|
|
|
it 'does not execute a Projects::InProductMarketingCampaignEmailsService' do
|
|
|
|
expect(Projects::InProductMarketingCampaignEmailsService).not_to receive(:new)
|
|
|
|
|
|
|
|
execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-22 18:09:22 +00:00
|
|
|
context 'experiment control' do
|
|
|
|
before do
|
|
|
|
stub_experiments(build_ios_app_guide_email: :control)
|
|
|
|
end
|
|
|
|
|
2022-05-05 21:09:10 +00:00
|
|
|
it_behaves_like 'does not send email'
|
|
|
|
it_behaves_like 'tracks experiment assignment event'
|
|
|
|
end
|
2022-04-22 18:09:22 +00:00
|
|
|
|
2022-05-05 21:09:10 +00:00
|
|
|
context 'when project is not an iOS project' do
|
|
|
|
let(:detector_service) { Projects::AppleTargetPlatformDetectorService }
|
|
|
|
let(:detector_result) { :android }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_experiments(build_ios_app_guide_email: :candidate)
|
2022-04-22 18:09:22 +00:00
|
|
|
end
|
|
|
|
|
2022-05-05 21:09:10 +00:00
|
|
|
it_behaves_like 'does not send email'
|
|
|
|
|
|
|
|
it 'does not track experiment assignment event', :experiment do
|
|
|
|
expect(experiment(:build_ios_app_guide_email))
|
|
|
|
.not_to track(:assignment)
|
|
|
|
|
|
|
|
execute
|
|
|
|
end
|
2022-04-22 18:09:22 +00:00
|
|
|
end
|
|
|
|
end
|
2022-03-30 00:09:03 +00:00
|
|
|
end
|
|
|
|
|
2022-05-05 21:09:10 +00:00
|
|
|
context 'when detector does not return any target platform values' do
|
2022-03-30 00:09:03 +00:00
|
|
|
before do
|
|
|
|
double = instance_double(Projects::AppleTargetPlatformDetectorService, execute: [])
|
|
|
|
allow(Projects::AppleTargetPlatformDetectorService).to receive(:new).with(project) { double }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does nothing' do
|
|
|
|
expect { execute }.not_to change { ProjectSetting.count }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|