-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:AgileVentures/WebsiteOne-FE into…
… 74-add-spinner-to-createBillingAgreement
- Loading branch information
Showing
7 changed files
with
11,557 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import axios from 'axios' | ||
|
||
export default (cookies, id) => event => { | ||
event.preventDefault() | ||
return axios({ | ||
method: 'POST', | ||
timeout: 50000, | ||
url: '/paypal/new.json', | ||
data: { | ||
plan: id | ||
}, | ||
headers: { | ||
Authorization: cookies.get('_WebsiteOne_session') | ||
} | ||
}) | ||
.then(response => window.location.assign(response.data.redirect_url)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import axios from 'axios' | ||
|
||
export default (props, params) => { | ||
return axios({ | ||
method: 'GET', | ||
timeout: 50000, | ||
url: '/paypal/create.json', | ||
params: { | ||
plan: params.plan, | ||
token: params.token | ||
}, | ||
headers: { | ||
Authorization: props.cookies.get('_WebsiteOne_session') | ||
} | ||
}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import moxios from 'moxios' | ||
import billingAgreementResponse from '../../fixtures/billingAgreementResponse' | ||
import createBillingAgreement from '../../helpers/createBillingAgreement' | ||
|
||
describe('createBillingAgreement helper', () => { | ||
const cookies = { get: jest.fn() } | ||
const event = { preventDefault: jest.fn() } | ||
const { assign } = window.location | ||
beforeEach(() => { | ||
moxios.install() | ||
Object.defineProperty(window.location, 'assign', { | ||
configurable: true | ||
}) | ||
window.location.assign = jest.fn() | ||
}) | ||
|
||
afterEach(() => { | ||
moxios.uninstall() | ||
window.location.assign = assign | ||
}) | ||
|
||
it('posts plan info to Rails backend and returns with redirect url', () => { | ||
moxios.stubRequest('/paypal/new.json', { | ||
status: 200, | ||
response: billingAgreementResponse | ||
}) | ||
createBillingAgreement(cookies)(event) | ||
expect(billingAgreementResponse.data.redirect_url).toEqual( | ||
'https://www.sandbox.paypal.com/cgi-bin/webscr' | ||
) | ||
}) | ||
|
||
it('calls window.location.assign to redirect to PayPal site', () => { | ||
moxios.stubRequest('/paypal/new.json', { | ||
status: 200, | ||
response: billingAgreementResponse | ||
}) | ||
createBillingAgreement(cookies)(event).then( | ||
window.location.assign(billingAgreementResponse.data.redirect_url) | ||
) | ||
expect(window.location.assign).toHaveBeenCalled() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import moxios from 'moxios' | ||
import { executedBillingAgreementResponse } from '../../fixtures/billingAgreementResponse' | ||
import executeBillingAgreement from '../../helpers/executeBillingAgreement' | ||
|
||
describe('executeBillingAgreement helper', () => { | ||
const props = { cookies: { get: jest.fn() } } | ||
const params = { plan: 'premium', token: 'valid_token' } | ||
beforeEach(() => { | ||
moxios.install() | ||
}) | ||
|
||
afterEach(() => { | ||
moxios.uninstall() | ||
}) | ||
|
||
it('posts plan info to Rails backend and returns with redirect url', () => { | ||
moxios.stubRequest('/paypal/create.json', { | ||
status: 200, | ||
response: executedBillingAgreementResponse | ||
}) | ||
executeBillingAgreement(props, params) | ||
expect(executedBillingAgreementResponse).toEqual({ data: { message: 'Success' } }) | ||
}) | ||
}) |
Oops, something went wrong.