Skip to content

Commit

Permalink
Merge branch 'stage' into 'master'
Browse files Browse the repository at this point in the history
Release 2.1.0

See merge request cleeng/gummybear-2!194
  • Loading branch information
iwonakulacz committed Apr 21, 2021
2 parents 646be1b + 8696820 commit dd02215
Show file tree
Hide file tree
Showing 186 changed files with 4,827 additions and 25,162 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ stages:
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_PROJECT_NAME/$CI_ENVIRONMENT_NAME
script:
- echo ${ENVIRONMENT}
- yarn && yarn build --environment=${ENVIRONMENT}
- STORYBOOK_ENV=${ENVIRONMENT} yarn build-storybook
- mv storybook-static build
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
![Build](https://github.com/Cleeng/media-store-sdk/workflows/Build/badge.svg?branch=master&event=push)
![Tests](https://github.com/Cleeng/media-store-sdk/workflows/Tests/badge.svg?branch=master&event=push)

# MediaStore SDK

This repo is an example app which shows how to integrate with Cleeng MediaStore API. It consists of components that will empower you to build and design a seamless checkout process, help visitors become subscribers, and then allow them to manage their subscription.
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@svgr/webpack": "4.3.2",
"@typescript-eslint/eslint-plugin": "1.13.0",
"@typescript-eslint/parser": "1.13.0",
"axios": "^0.19.2",
"babel-eslint": "^10.1.0",
"babel-jest": "^24.8.0",
"babel-loader": "8.0.6",
Expand Down Expand Up @@ -65,11 +64,13 @@
"react-i18next": "^10.12.5",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"react-select": "^4.1.0",
"redux": "^4.0.5",
"resolve": "1.12.0",
"resolve-url-loader": "3.1.0",
"sass-loader": "7.2.0",
"semver": "6.3.0",
"source-map-explorer": "^2.5.2",
"storybook-addon-jsx": "^7.3.4",
"storybook-addon-mock": "^0.0.4",
"storybook-react-router": "^1.0.8",
Expand All @@ -89,6 +90,7 @@
"test": "node scripts/test.js",
"storybook": "start-storybook -s ./public -p 6006",
"build-storybook": "build-storybook",
"analyze": "source-map-explorer 'build/static/js/*.js'",
"scan-translations": "node -e 'require(`./scripts/translationsBundle.js`).run(false)'"
},
"browserslist": {
Expand Down
27 changes: 27 additions & 0 deletions src/api/Customer/applyCoupon.js
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;
20 changes: 20 additions & 0 deletions src/api/Customer/getCaptureStatus.js
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;
43 changes: 43 additions & 0 deletions src/api/Customer/updateCaptureAnswers.js
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;
10 changes: 9 additions & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import getCustomer from './Customer/getCustomer';
import listCustomerTransactions from './Customer/listCustomerTransactions';
import getCustomerConsents from './Customer/getCustomerConsents';
import submitPayPalPayment from './Offer/submitPayPalPayment';
import applyCoupon from './Customer/applyCoupon';
import getCaptureStatus from './Customer/getCaptureStatus';
import updateCaptureAnswers from './Customer/updateCaptureAnswers';
import submitConsents from './Customer/submitConsents';

export {
getPaymentMethods,
Expand All @@ -25,11 +29,15 @@ export {
submitPayment,
submitPaymentWithoutDetails,
getConsents,
getCaptureStatus,
updateCaptureAnswers,
getOfferDetails,
loginCustomer,
registerCustomer,
resetPassword,
listCustomerTransactions,
getCustomerConsents,
submitPayPalPayment
submitPayPalPayment,
applyCoupon,
submitConsents
};
46 changes: 46 additions & 0 deletions src/api/tests/getCaptureStatus.spec.js
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();
});
});
});
62 changes: 62 additions & 0 deletions src/api/tests/updateCaptureAnswers.spec.js
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 removed src/assets/fonts/black/Geomanist-Black.otf
Binary file not shown.
Loading

0 comments on commit dd02215

Please sign in to comment.