Skip to content

Commit

Permalink
test(globals): increase the test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Arturo Riveron Borodovisina committed Feb 28, 2022
1 parent 32f85dd commit af4462c
Showing 1 changed file with 160 additions and 1 deletion.
161 changes: 160 additions & 1 deletion test/client/global.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/* @flow */

import { getHost, getHostName, getPort, getPath, getEnv, getDefaultStageHost, getVersion, getCorrelationID } from '../../src';
import { PLATFORM, PROTOCOL } from '@paypal/sdk-constants/src';

import { getSDKHost, getHost, getProtocol,
getHostName, getPort, getDefaultServiceStageHost,
getDefaultAPIStageHost, getStageHost, getFundingEligibility,
getAPIStageHost, getDebug, getComponents,
getPath, getEnv, getDefaultStageHost,
getVersion, getCorrelationID, getPlatform
} from '../../src';

describe(`globals cases`, () => {

Expand Down Expand Up @@ -49,6 +57,17 @@ describe(`globals cases`, () => {
}
});

it('should get the default stage host equal to undefined', () => {
const originalValue = 'msmaster.qa.paypal.com';
window.__STAGE_HOST__ = undefined;
const result = getDefaultStageHost();

if (result !== undefined) {
throw new Error('Expected default stage host to be undefined');
}
window.__STAGE_HOST__ = originalValue;
});

it('should successfully get the default stage host', () => {
const expectedResult = 'msmaster.qa.paypal.com';
const result = getDefaultStageHost();
Expand Down Expand Up @@ -86,4 +105,144 @@ describe(`globals cases`, () => {

delete window.__CORRELATION_ID__;
});

it('should successfully get the SDK host', () => {
const result = getSDKHost();

if (__SDK_HOST__ !== result) {
throw new Error(`Expected SDK host to be ${ __SDK_HOST__ }, got ${ result }`);
}
});

it('should successfully get the default protocol', () => {
const result = getProtocol();

if (PROTOCOL.HTTPS !== result) {
throw new Error(`Expected protocol to be ${ PROTOCOL.HTTPS }, got ${ result }`);
}
});

it('should successfully get the set global protocol', () => {
window.__PROTOCOL__ = 'http';
const result = getProtocol();

if (PROTOCOL.HTTP !== result) {
throw new Error(`Expected set protocol to be ${ PROTOCOL.HTTP }, got ${ result }`);
}
delete window.__PROTOCOL__;
});

it('should get the default service stage host equal to undefined', () => {
window.__SERVICE_STAGE_HOST__ = undefined;
const result = getDefaultServiceStageHost();

if (result !== undefined) {
throw new Error(`Expected to be undefine the default service stage host`);
}
delete window.__SERVICE_STAGE_HOST__;
});

it('should successfully get the default service stage host', () => {
window.__SERVICE_STAGE_HOST__ = 'mock://msmaster.qa.paypal.com';
const result = getDefaultServiceStageHost();

if (__SERVICE_STAGE_HOST__ !== result) {
throw new Error(`Expected to be the default service stage host`);
}
delete window.__SERVICE_STAGE_HOST__;
});

it('should successfully identify desktop platform', () => {
const result = getPlatform();

if (PLATFORM.DESKTOP !== result) {
throw new Error(`Expected to be desktop platform, got ${ result }`);
}
});

it('should get the API stage from the default service stage host', () => {
window.__SERVICE_STAGE_HOST__ = 'mock://msmaster.qa.paypal.com';
const result = getDefaultAPIStageHost();

if (window.__SERVICE_STAGE_HOST__ !== result) {
throw new Error(`Expected default API stage host to be ${ window.__SERVICE_STAGE_HOST__ }, got ${ result || '' }`);
}
delete window.__SERVICE_STAGE_HOST__;
});

it('should get the API stage from the default stage host', () => {
const result = getDefaultAPIStageHost();

if (__STAGE_HOST__ !== result) {
throw new Error(`Expected default API stage host to be ${ window.__STAGE_HOST__ }, got ${ result || '' }`);
}
});

it('should get the API stage equal to undefined', () => {
window.__STAGE_HOST__ = undefined;
const result = getDefaultAPIStageHost();

if (result !== undefined) {
throw new Error('Expected API stage to be undefined');
}
window.__STAGE_HOST__ = 'msmaster.qa.paypal.com';
});


it('should successfully get the stage host', () => {
const result = getStageHost();

if (__STAGE_HOST__ !== result) {
throw new Error(`Expected stage host to be ${ window.__STAGE_HOST__ }, got ${ result || '' }`);
}
});

it('should successfully get the API stage host', () => {
const result = getAPIStageHost();

if (__STAGE_HOST__ !== result) {
throw new Error(`Expected API stage host to be ${ window.__STAGE_HOST__ }, got ${ result || '' }`);
}
});

it('should get the API stage host equal to undefined', () => {
window.__STAGE_HOST__ = undefined;
const result = getAPIStageHost();

if (result !== undefined) {
throw new Error('Expected API stage host to be undefined');
}
window.__STAGE_HOST__ = 'msmaster.qa.paypal.com';
});

it('should successfully get the debug flag', () => {
window.__DEBUG__ = true;
const result = getDebug();

if (window.__DEBUG__ !== result) {
throw new Error(`Expected debug flag to be ${ window.__DEBUG__ }, got ${ result.toString() }`);
}
delete window.__DEBUG__;
});

it('should successfully get the components list', () => {
window.__COMPONENTS__ = [ 'buttons', 'venmo' ];
const result = getComponents();

if (result[0] !== 'buttons' || result[1] !== 'venmo') {
throw new Error(`Expected components to be ${ window.__COMPONENTS__ }, got ${ result.toString() }`);
}
delete window.__COMPONENTS__;
});

it('should successfully get the funding eligibility type', () => {
window.__FUNDING_ELIGIBILITY__ = 'credit';
const result = getFundingEligibility();

if (window.__FUNDING_ELIGIBILITY__ !== result) {
throw new Error(`Expected funding eligibility type to be ${ window.__FUNDING_ELIGIBILITY__ }, got ${ result.toString() }`);
}
delete window.__FUNDING_ELIGIBILITY__;
});

});

0 comments on commit af4462c

Please sign in to comment.