Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(customer_portal): Remove premium restriction #2574

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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