You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request introduces several changes to enhance the functionality and testing of the FlutterwaveProvider payment provider. Key updates include improving secrets management, refining test cases, and adding comprehensive model validations.
spec/factories/payment_providers.rb: Updated the secrets and settings attributes in the factory to reflect the new secrets structure, ensuring webhook_secret is properly handled.
• Moved webhook_secret from settings to secrets for better security
• Added comprehensive test coverage for FlutterwaveProvider model
• Fixed queue testing to use proper enqueue matchers
• Updated factory to reflect new secrets structure
The factory adds webhook_secret to the secrets JSON but doesn't define it as a transient attribute, which could cause factory build failures or inconsistent test data generation.
The webhook secret generation test creates a provider with an existing secret but doesn't verify that the before_create callback is properly skipped when a secret already exists, potentially missing edge cases in the generation logic.
The test creates a provider with a duplicate code which will fail validation due to uniqueness constraints. Use a unique code or the factory to avoid validation errors.
it "does not override existing webhook secret" do
existing_secret = "existing_secret"
provider = described_class.new(
organization: create(:organization),
name: "Test Provider",
- code: "test_provider",+ code: "test_provider_#{SecureRandom.uuid}",
secret_key: "test_key",
webhook_secret: existing_secret
)
provider.save!
expect(provider.reload.webhook_secret).to eq(existing_secret)
end
Apply / Chat
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies that using a hardcoded code is a bad practice when a uniqueness validation exists. While the test creates a new organization, making the test fragile, using a dynamically generated unique code as suggested makes the test more robust and prevents potential future failures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
This pull request introduces several changes to enhance the functionality and testing of the
FlutterwaveProviderpayment provider. Key updates include improving secrets management, refining test cases, and adding comprehensive model validations.Enhancements to secrets management:
app/models/payment_providers/flutterwave_provider.rb: Addedwebhook_secrettosecrets_accessorsto centralize its management alongsidesecret_key.spec/factories/payment_providers.rb: Updated thesecretsandsettingsattributes in the factory to reflect the new secrets structure, ensuringwebhook_secretis properly handled.spec/services/payment_providers/flutterwave/handle_incoming_webhook_service_spec.rb: Adjusted the test setup to removewebhook_secretfrom thesecretsJSON structure instead ofsettings.Improvements to test coverage:
spec/models/payment_providers/flutterwave_provider_spec.rb: Added extensive tests for validations, constants, secrets accessors, webhook secret generation, and theFlutterwavePaymentdata structure to ensure robust functionality.Refinements in job queue testing:
spec/jobs/payment_providers/flutterwave/handle_event_job_spec.rb: Updated tests to usehave_enqueued_jobmatcher, improving readability and accuracy in verifying job queue assignments.PR Type
Enhancement
Description
• Moved
webhook_secretfrom settings to secrets for better security• Added comprehensive test coverage for FlutterwaveProvider model
• Fixed queue testing to use proper enqueue matchers
• Updated factory to reflect new secrets structure
Changes walkthrough 📝
flutterwave_provider.rb
Move webhook_secret to secrets accessorsapp/models/payment_providers/flutterwave_provider.rb
• Moved
webhook_secretfromsettings_accessorstosecrets_accessors•
Removed extra blank line for cleaner formatting
payment_providers.rb
Update factory for new secrets structurespec/factories/payment_providers.rb
• Added
webhook_secretto secrets JSON structure• Removed
webhook_secretfrom settings hash• Added transient
webhook_secretattribute
handle_event_job_spec.rb
Fix queue testing with proper matchersspec/jobs/payment_providers/flutterwave/handle_event_job_spec.rb
• Replaced
queue_nameassertions withhave_enqueued_job.on_queuematchers
• Added proper job enqueuing expectations for both queue
scenarios
flutterwave_provider_spec.rb
Add comprehensive FlutterwaveProvider model testsspec/models/payment_providers/flutterwave_provider_spec.rb
• Added comprehensive test suite for FlutterwaveProvider model
• Tests
validations, constants, webhook secret generation, and data structures
• Covers secrets accessors and payment type functionality
handle_incoming_webhook_service_spec.rb
Update webhook service test for secretsspec/services/payment_providers/flutterwave/handle_incoming_webhook_service_spec.rb
• Updated test to remove
webhook_secretfrom secrets JSON instead ofsettings
• Fixed webhook secret handling test for new secrets
structure