From 526195cd0c3a6397d553814f49ae4cffe8457e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Semp=C3=A9?= Date: Thu, 12 Sep 2024 13:31:24 +0100 Subject: [PATCH] feat(customer_portal): Remove premium restriction --- .../customer_portal/generate_url_service.rb | 1 - .../api/v1/customers_controller_spec.rb | 41 ++++++------------- .../generate_url_service_spec.rb | 35 +++++----------- 3 files changed, 24 insertions(+), 53 deletions(-) diff --git a/app/services/customer_portal/generate_url_service.rb b/app/services/customer_portal/generate_url_service.rb index 2f71b65fc6d..470be96befe 100644 --- a/app/services/customer_portal/generate_url_service.rb +++ b/app/services/customer_portal/generate_url_service.rb @@ -9,7 +9,6 @@ def initialize(customer:) end def call - return result.forbidden_failure! unless License.premium? return result.not_found_failure!(resource: 'customer') if customer.blank? public_authenticator = ActiveSupport::MessageVerifier.new(ENV['SECRET_KEY_BASE']) diff --git a/spec/requests/api/v1/customers_controller_spec.rb b/spec/requests/api/v1/customers_controller_spec.rb index f1f737e200a..dc603e75eec 100644 --- a/spec/requests/api/v1/customers_controller_spec.rb +++ b/spec/requests/api/v1/customers_controller_spec.rb @@ -241,43 +241,28 @@ let(:customer) { create(:customer, organization:) } let(:organization) { create(:organization) } - context 'when licence is premium' do - around { |test| lago_premium!(&test) } - - it 'returns the portal url' do - get_with_token( - organization, - "/api/v1/customers/#{customer.external_id}/portal_url" - ) - - aggregate_failures do - expect(response).to have_http_status(:success) - expect(json[:customer][:portal_url]).to include('/customer-portal/') - end - end - - context 'when customer does not belongs to the organization' do - let(:customer) { create(:customer) } - - it 'returns not found error' do - get_with_token( - organization, - "/api/v1/customers/#{customer.external_id}/portal_url" - ) + it 'returns the portal url' do + get_with_token( + organization, + "/api/v1/customers/#{customer.external_id}/portal_url" + ) - expect(response).to have_http_status(:not_found) - end + aggregate_failures do + expect(response).to have_http_status(:success) + expect(json[:customer][:portal_url]).to include('/customer-portal/') end end - context 'when licence is not premium' do - it 'returns error' do + context 'when customer does not belongs to the organization' do + let(:customer) { create(:customer) } + + it 'returns not found error' do get_with_token( organization, "/api/v1/customers/#{customer.external_id}/portal_url" ) - expect(response).to have_http_status(:forbidden) + expect(response).to have_http_status(:not_found) end end end diff --git a/spec/services/customer_portal/generate_url_service_spec.rb b/spec/services/customer_portal/generate_url_service_spec.rb index 19852938348..0b2bbee4911 100644 --- a/spec/services/customer_portal/generate_url_service_spec.rb +++ b/spec/services/customer_portal/generate_url_service_spec.rb @@ -8,39 +8,26 @@ let(:customer) { create(:customer) } describe '#call' do - context 'when licence is premium' do - around { |test| lago_premium!(&test) } + it 'generates valid customer portal url' do + result = generate_url_service.call - it 'generates valid customer portal url' do - result = generate_url_service.call - - message = result.url.split('/customer-portal/')[1] - public_authenticator = ActiveSupport::MessageVerifier.new(ENV['SECRET_KEY_BASE']) + message = result.url.split('/customer-portal/')[1] + public_authenticator = ActiveSupport::MessageVerifier.new(ENV['SECRET_KEY_BASE']) - aggregate_failures do - expect(result.url).to include('/customer-portal/') - expect(public_authenticator.verify(message)).to eq(customer.id) - end - end - - context 'when customer does not exist' do - let(:customer) { nil } - - it 'returns an error' do - result = generate_url_service.call - - expect(result).not_to be_success - expect(result.error.error_code).to eq('customer_not_found') - end + aggregate_failures do + expect(result.url).to include('/customer-portal/') + expect(public_authenticator.verify(message)).to eq(customer.id) end end - context 'when licence is not premium' do + context 'when customer does not exist' do + let(:customer) { nil } + it 'returns an error' do result = generate_url_service.call expect(result).not_to be_success - expect(result.error.code).to eq('feature_unavailable') + expect(result.error.error_code).to eq('customer_not_found') end end end