Skip to content

Commit

Permalink
feat(customer_portal): Remove premium restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
rsempe committed Sep 12, 2024
1 parent 967255e commit 159531b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 53 deletions.
1 change: 0 additions & 1 deletion app/services/customer_portal/generate_url_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
41 changes: 13 additions & 28 deletions spec/requests/api/v1/customers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 11 additions & 24 deletions spec/services/customer_portal/generate_url_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 159531b

Please sign in to comment.