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
policy = SoftwareLicense.create_policy_for!(
project: project,
name: params[:name],
classification: params[:approval_status]
classification: map_from(params[:approval_status])
)
RefreshLicenseComplianceChecksWorker.perform_async(project.id)
policy
end
def map_from(approval_status)
case approval_status
when 'blacklisted'
'denied'
else
approval_status
end
end
end
end
......@@ -36,23 +36,34 @@ describe SoftwareLicensePolicies::CreateService do
software_license_policy = project.software_license_policies.last
expect(software_license_policy).to be_persisted
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
context "when valid parameters are specified" do
let(:result) { subject.execute }
before do
allow(RefreshLicenseComplianceChecksWorker).to receive(:perform_async)
result
context 'when valid parameters are specified' do
where(:approval_status, :expected_classification) do
[
['approved', 'approved'],
['denied', 'denied'],
['blacklisted', 'denied'],
]
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('blacklisted') }
specify { expect(RefreshLicenseComplianceChecksWorker).to have_received(:perform_async).with(project.id) }
with_them do
let(:params) { { name: 'MIT', approval_status: approval_status } }
let(:result) { subject.execute }
before do
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
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