Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the test coverage on the client to avoid failing checks in the CI #117

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 160 additions & 3 deletions test/client/global.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
/* @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`, () => {

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 +65,21 @@ describe(`globals cases`, () => {
}
});

it('should get the default stage host when "window.__STAGE_HOST__" is 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 +111,136 @@ 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 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 when 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', () => {
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`);
}
});

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 || '' }`);
}
});

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 when 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 when 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', () => {
window.__DEBUG__ = true;
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', () => {
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() }`);
}
});

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() }`);
}
});

});