-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 2.1.0 See merge request cleeng/gummybear-2!194
- Loading branch information
Showing
186 changed files
with
4,827 additions
and
25,162 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
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,27 @@ | ||
import jwtDecode from 'jwt-decode'; | ||
import { getData } from 'util/appConfigHelper'; | ||
|
||
const applyCoupon = async (subscriptionId, couponCode) => { | ||
const token = getData('CLEENG_AUTH_TOKEN') || ''; | ||
const decoded = jwtDecode(token); | ||
const { customerId } = decoded; | ||
|
||
const url = `${ENVIRONMENT_CONFIGURATION.API_URL}/customers/${customerId}/subscriptions/${subscriptionId}`; | ||
|
||
const resp = await fetch(url, { | ||
method: 'PATCH', | ||
body: JSON.stringify({ couponCode }), | ||
headers: { | ||
Authorization: `Bearer ${token}` | ||
} | ||
}); | ||
|
||
const json = await resp.json(); | ||
|
||
return { | ||
status: resp.status, | ||
...json | ||
}; | ||
}; | ||
|
||
export default applyCoupon; |
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,20 @@ | ||
import jwtDecode from 'jwt-decode'; | ||
import { getData } from 'util/appConfigHelper'; | ||
|
||
const getCaptureStatus = async () => { | ||
const token = getData('CLEENG_AUTH_TOKEN') || ''; | ||
const decoded = jwtDecode(token); | ||
const { customerId } = decoded; | ||
|
||
const url = `${ENVIRONMENT_CONFIGURATION.API_URL}/customers/${customerId}/capture/status`; | ||
return fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
Authorization: `Bearer ${token}` | ||
} | ||
}).then(res => { | ||
return res.json(); | ||
}); | ||
}; | ||
|
||
export default getCaptureStatus; |
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 jwtDecode from 'jwt-decode'; | ||
import { getData } from 'util/appConfigHelper'; | ||
|
||
const updateCaptureAnswers = async anwsers => { | ||
const token = getData('CLEENG_AUTH_TOKEN') || ''; | ||
const decoded = jwtDecode(token); | ||
const { customerId } = decoded; | ||
|
||
const url = `${ENVIRONMENT_CONFIGURATION.API_URL}/customers/${customerId}/capture`; | ||
|
||
const payload = { | ||
firstName: anwsers.firstName || null, | ||
lastName: anwsers.lastName || null, | ||
address: anwsers.address || null, | ||
address2: anwsers.address2 || null, | ||
city: anwsers.city || null, | ||
state: anwsers.state || null, | ||
postCode: anwsers.postCode || null, | ||
country: anwsers.country || null, | ||
email: anwsers.email || null, | ||
birthDate: anwsers.birthDate || null, | ||
companyName: anwsers.companyName || null, | ||
phoneNumber: anwsers.phoneNumber || null, | ||
customAnswers: anwsers.customAnswers || null | ||
}; | ||
|
||
const resp = await fetch(url, { | ||
method: 'PUT', | ||
body: JSON.stringify(payload), | ||
headers: { | ||
Authorization: `Bearer ${token}` | ||
} | ||
}); | ||
|
||
const json = await resp.json(); | ||
|
||
return { | ||
status: resp.status, | ||
...json | ||
}; | ||
}; | ||
|
||
export default updateCaptureAnswers; |
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,46 @@ | ||
import getCaptureStatus from 'api/Customer/getCaptureStatus'; | ||
import { setData } from 'util/appConfigHelper'; | ||
|
||
describe('getCaptureStatus', () => { | ||
it('calls remote endpoint with authorization token', done => { | ||
const mockToken = | ||
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21lcklkIjoiOTUzODAwMDE5Iiwib2ZmZXJJZCI6IlM4NzczNjU4MjBfWlcifQ.BIkzQFE40F6Ig510zaw4aGDa-T0qcrQrWJU8yg3vQvYmjIdVip_9jGxVDA68TT7EF5VmLkTOvEQ-YdLLpygiyCgmncPM_dBvFBx13dwpji2aojqz03hWwHxfYlxQEbMFOiro80XBapmcJQh4kMaZNpQHE9Axx3ooHuOGPXrDy2SzVZTSW3-tG2AoSdkGWVmXBcngDUZjdZdBO9R8j4S1sZ3KxAtWexUHjOmiZos-OOTihp5aFutxm1Faq5qD7f19xBopQ-j3T3gr06oAbcdIyPF8pTUlEmRU1MuFMcMlpVtwPG-P5LoJ_W7fbF7HI-B3DyYHcSXNAehVB54_ETd34g'; | ||
const mockResponse = { | ||
responseData: { | ||
isCaptureEnabled: true, | ||
shouldCaptureBeDisplayed: true, | ||
settings: [] | ||
} | ||
}; | ||
jest.spyOn(Storage.prototype, 'setItem'); | ||
jest.spyOn(global, 'fetch').mockImplementation( | ||
async (url, { headers: { Authorization } }) => | ||
new Promise((resolve, reject) => { | ||
if (Authorization === `Bearer ${mockToken}`) { | ||
resolve({ | ||
json: () => mockResponse | ||
}); | ||
} else { | ||
reject(); | ||
} | ||
}) | ||
); | ||
|
||
setData('CLEENG_AUTH_TOKEN', mockToken); | ||
getCaptureStatus().then(res => { | ||
expect(res).toEqual(mockResponse); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('fails on remote call error', done => { | ||
const mockError = new Error('error'); | ||
const mockFetch = jest.spyOn(global, 'fetch').mockRejectedValue(mockError); | ||
|
||
getCaptureStatus().catch(err => { | ||
expect(mockFetch).toHaveBeenCalled(); | ||
expect(err).toEqual(mockError); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,62 @@ | ||
import updateCaptureAnswers from 'api/Customer/updateCaptureAnswers'; | ||
import { setData } from 'util/appConfigHelper'; | ||
|
||
const data = { | ||
firstName: 'TestName', | ||
lastName: 'TestLastName', | ||
address: null, | ||
address2: null, | ||
city: null, | ||
state: null, | ||
postCode: null, | ||
country: null, | ||
email: 'test@test.com', | ||
birthDate: null, | ||
companyName: 'testcompany', | ||
phoneNumber: null, | ||
customAnswers: null | ||
}; | ||
|
||
describe('updateCaptureAnswers', () => { | ||
it('should calls remote endpoint with authorization token', done => { | ||
const mockToken = | ||
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21lcklkIjoiOTUzODAwMDE5Iiwib2ZmZXJJZCI6IlM4NzczNjU4MjBfWlcifQ.BIkzQFE40F6Ig510zaw4aGDa-T0qcrQrWJU8yg3vQvYmjIdVip_9jGxVDA68TT7EF5VmLkTOvEQ-YdLLpygiyCgmncPM_dBvFBx13dwpji2aojqz03hWwHxfYlxQEbMFOiro80XBapmcJQh4kMaZNpQHE9Axx3ooHuOGPXrDy2SzVZTSW3-tG2AoSdkGWVmXBcngDUZjdZdBO9R8j4S1sZ3KxAtWexUHjOmiZos-OOTihp5aFutxm1Faq5qD7f19xBopQ-j3T3gr06oAbcdIyPF8pTUlEmRU1MuFMcMlpVtwPG-P5LoJ_W7fbF7HI-B3DyYHcSXNAehVB54_ETd34g'; | ||
const mockResponse = { | ||
responseData: { | ||
success: true | ||
}, | ||
errors: [] | ||
}; | ||
jest.spyOn(Storage.prototype, 'setItem'); | ||
|
||
jest.spyOn(global, 'fetch').mockImplementation( | ||
async (url, { headers: { Authorization } }) => | ||
new Promise((resolve, reject) => { | ||
if (Authorization === `Bearer ${mockToken}`) { | ||
resolve({ | ||
json: () => mockResponse | ||
}); | ||
} else { | ||
reject(); | ||
} | ||
}) | ||
); | ||
|
||
setData('CLEENG_AUTH_TOKEN', mockToken); | ||
updateCaptureAnswers(data).then(res => { | ||
expect(res).toEqual(mockResponse); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should fails on remote call error', done => { | ||
const mockError = new Error('error'); | ||
const mockFetch = jest.spyOn(global, 'fetch').mockRejectedValue(mockError); | ||
|
||
updateCaptureAnswers(data).catch(err => { | ||
expect(mockFetch).toHaveBeenCalled(); | ||
expect(err).toEqual(mockError); | ||
done(); | ||
}); | ||
}); | ||
}); |
Binary file not shown.
Oops, something went wrong.