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 e7086bd
Showing 1 changed file with 162 additions and 3 deletions.
165 changes: 162 additions & 3 deletions test/client/global.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
/* @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`, () => {

beforeEach(() => {
window.__DEBUG__ = true;
window.__COMPONENTS__ = [ 'buttons', 'venmo' ];
window.__SERVICE_STAGE_HOST__ = 'mock://msmaster.qa.paypal.com';
window.__FUNDING_ELIGIBILITY__ = 'credit';
});

afterEach(() => {
window.__STAGE_HOST__ = 'mock://msmaster.qa.paypal.com';
delete window.__PROTOCOL__;
delete window.__SERVICE_STAGE_HOST__;
delete window.__COMPONENTS__;
delete window.__FUNDING_ELIGIBILITY__;
});

it('should successfully get the host', () => {
const expectedResult = 'test.paypal.com';
const result = getHost();
Expand Down Expand Up @@ -49,12 +72,21 @@ describe(`globals cases`, () => {
}
});

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

if (result !== undefined) {
throw new Error(`Expected default stage host to be undefined, got ${ String(result) }`);
}
});

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

if (expectedResult !== result) {
throw new Error(`Expected default stage host to be ${ expectedResult }, got ${ result || 'undefined' }`);
throw new Error(`Expected default stage host to be ${ expectedResult }, got ${ String(result) }`);
}
});

Expand Down Expand Up @@ -86,4 +118,131 @@ 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 }`);
}
});

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, got ${ String(result) }`);
}
});

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

if (__SERVICE_STAGE_HOST__ !== result) {
throw new Error(`Expected to be the default 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', () => {
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 || '' }`);
}
});

it('should get the API stage from the default stage host', () => {
window.__SERVICE_STAGE_HOST__ = undefined;
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__ = window.__SERVICE_STAGE_HOST__ = undefined;
const result = getDefaultAPIStageHost();

if (result !== undefined) {
throw new Error(`Expected API stage to be undefined, but got ${ String(result) }`);
}
});


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__ = window.__SERVICE_STAGE_HOST__ = undefined;
const result = getAPIStageHost();

if (result !== undefined) {
throw new Error(`Expected API stage host to be undefined, got ${ String(result) }`);
}
});

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

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

it('should successfully get the components list', () => {
const result = getComponents();

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

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

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

});

0 comments on commit e7086bd

Please sign in to comment.