Commit 0d5c00b0 authored by mo khan's avatar mo khan Committed by Ash McKenzie

Map blacklisted to denied for legacy API

parent 69d4c55d
...@@ -24,10 +24,19 @@ module SoftwareLicensePolicies ...@@ -24,10 +24,19 @@ module SoftwareLicensePolicies
policy = SoftwareLicense.create_policy_for!( policy = SoftwareLicense.create_policy_for!(
project: project, project: project,
name: params[:name], name: params[:name],
classification: params[:approval_status] classification: map_from(params[:approval_status])
) )
RefreshLicenseComplianceChecksWorker.perform_async(project.id) RefreshLicenseComplianceChecksWorker.perform_async(project.id)
policy policy
end end
def map_from(approval_status)
case approval_status
when 'blacklisted'
'denied'
else
approval_status
end
end
end end
end end
...@@ -36,23 +36,34 @@ describe SoftwareLicensePolicies::CreateService do ...@@ -36,23 +36,34 @@ describe SoftwareLicensePolicies::CreateService do
software_license_policy = project.software_license_policies.last software_license_policy = project.software_license_policies.last
expect(software_license_policy).to be_persisted expect(software_license_policy).to be_persisted
expect(software_license_policy.name).to eq(params[:name]) expect(software_license_policy.name).to eq(params[:name])
expect(software_license_policy.classification).to eq('blacklisted') expect(software_license_policy.classification).to eq('denied')
end end
context "when valid parameters are specified" do context 'when valid parameters are specified' do
let(:result) { subject.execute } where(:approval_status, :expected_classification) do
[
before do ['approved', 'approved'],
allow(RefreshLicenseComplianceChecksWorker).to receive(:perform_async) ['denied', 'denied'],
result ['blacklisted', 'denied'],
]
end end
specify { expect(result[:status]).to be(:success) } with_them do
specify { expect(result[:software_license_policy]).to be_present } let(:params) { { name: 'MIT', approval_status: approval_status } }
specify { expect(result[:software_license_policy]).to be_persisted } let(:result) { subject.execute }
specify { expect(result[:software_license_policy].name).to eql(params[:name]) }
specify { expect(result[:software_license_policy].classification).to eql('blacklisted') } before do
specify { expect(RefreshLicenseComplianceChecksWorker).to have_received(:perform_async).with(project.id) } allow(RefreshLicenseComplianceChecksWorker).to receive(:perform_async)
result
end
specify { expect(result[:status]).to be(:success) }
specify { expect(result[:software_license_policy]).to be_present }
specify { expect(result[:software_license_policy]).to be_persisted }
specify { expect(result[:software_license_policy].name).to eql(params[:name]) }
specify { expect(result[:software_license_policy].classification).to eql(expected_classification) }
specify { expect(RefreshLicenseComplianceChecksWorker).to have_received(:perform_async).with(project.id) }
end
end end
context "when an argument error is raised" do context "when an argument error is raised" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment