-
Notifications
You must be signed in to change notification settings - Fork 10
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
Feature/complete tests for subscription #292
Open
tomivm
wants to merge
5
commits into
master
Choose a base branch
from
feature/add-more-tests-for-subscription
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cf78a6f
add mocks for PayPal Transactions
tomivm 66a1e27
Add test for create a PayPal transaction
tomivm 90e61b8
move Paypal tests to the end
tomivm 95ebdbd
Update postman tests
tomivm b90566a
response with plan id for both platforms
tomivm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,6 +234,32 @@ const subscriber = { | |
isAcknowledged: false, | ||
renewalIntent: 'Renew', | ||
}, | ||
payPalTransactionData: { | ||
className: 'Transaction', | ||
subscriptionId: 'subscriptionID', | ||
transactionId: 'subscriptionID', | ||
state: 'approved', | ||
products: [{ | ||
"id": "test-monthly", | ||
"subscriptionId": "test", | ||
"billingPeriod": "P1M", | ||
"price": { | ||
"currencyCode": "USD", | ||
"units": "6" | ||
}, | ||
"title": "Test Subscription", | ||
"tag": "test-monthly", | ||
"paypalId": "P-7CR38290D5111153BMRDNDLA" | ||
}], | ||
platform: 'paypal', | ||
nativePurchase: '', | ||
purchaseId: 'orderID', | ||
purchaseDate: '', | ||
isPending: false, | ||
subscriptionState: 'active', | ||
expiryDate: '', | ||
facilitatorAccessToken:'facilitatorAccessToken' | ||
}, | ||
createSubscriber: async (userId) => { | ||
const newSubscriber = subscriber.subscriberData; | ||
newSubscriber.userId = userId; | ||
|
@@ -307,6 +333,91 @@ const subscriber = { | |
}, | ||
}); | ||
}, | ||
mockPayPalVerification: ({ isValid }) => { | ||
nock('https://api-m.sandbox.paypal.com') | ||
.post(`/v1/oauth2/token`) | ||
.reply(200,{data:{access_token:'ttttoken'}}); | ||
|
||
if (isValid) { | ||
const subscriptionDetails = { | ||
status: 'ACTIVE', | ||
status_update_time: '2023-04-27T20:30:29Z', | ||
id: 'I-9UN3TA1TXMC7', | ||
plan_id: 'P-7CR38290D5111153BMRDNDLA', | ||
start_time: '2023-04-27T20:29:47Z', | ||
quantity: '1', | ||
shipping_amount: { currency_code: 'USD', value: '0.0' }, | ||
subscriber: { | ||
email_address: '[email protected]', | ||
payer_id: '587FW7S4CZNEG', | ||
name: { given_name: 'SANTIAGO', surname: 'EL QUESO' }, | ||
shipping_address: { address: {} } | ||
}, | ||
billing_info: { | ||
outstanding_balance: { currency_code: 'USD', value: '0.0' }, | ||
cycle_executions: [ {} ], | ||
last_payment: { amount: {}, time: '2023-04-27T20:30:28Z' }, | ||
next_billing_time: '2023-05-27T10:00:00Z', | ||
final_payment_time: '2027-03-27T10:00:00Z', | ||
failed_payments_count: 0 | ||
}, | ||
create_time: '2023-04-27T20:30:28Z', | ||
update_time: '2023-04-27T20:30:29Z', | ||
plan_overridden: false, | ||
links: [ | ||
{ | ||
href: 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-9UN3FA1TXHC7/cancel', | ||
rel: 'cancel', | ||
method: 'POST' | ||
}, | ||
{ | ||
href: 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-9UN3FA1TXHC7', | ||
rel: 'edit', | ||
method: 'PATCH' | ||
}, | ||
{ | ||
href: 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-9UN3FA1TXHC7', | ||
rel: 'self', | ||
method: 'GET' | ||
}, | ||
{ | ||
href: 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-9UN3FA1TXHC7/suspend', | ||
rel: 'suspend', | ||
method: 'POST' | ||
}, | ||
{ | ||
href: 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-9UN3FA1TXHC7/capture', | ||
rel: 'capture', | ||
method: 'POST' | ||
} | ||
] | ||
} | ||
|
||
const { subscriptionId } = subscriber.payPalTransactionData; | ||
nock( | ||
`https://api-m.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}` | ||
) | ||
.get('') | ||
.reply(200, subscriptionDetails); | ||
return subscriptionDetails; | ||
} | ||
|
||
const invalidResponse = { | ||
name: 'RESOURCE_NOT_FOUND', | ||
message: 'The specified resource does not exist.', | ||
debug_id: 'e662698658963', | ||
details: [], | ||
links: [] | ||
} | ||
|
||
const { subscriptionId } = subscriber.payPalTransactionData; | ||
nock( | ||
`https://api-m.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}` | ||
) | ||
.get('') | ||
.reply(404, invalidResponse); | ||
return invalidResponse; | ||
} | ||
}; | ||
|
||
const subscription = { | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a logical operation, it will always return
false
ortrue
, but never the id