Skip to content

Commit

Permalink
feat: add testMode as an alias to skipDomainVerification
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanbuchar committed Jan 24, 2019
1 parent 7039d7c commit 6d5178b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/defaults.js
Expand Up @@ -5,5 +5,6 @@ export default {
debug: false,
locale: settings.locales.EN_US,
skipDomainVerification: false,
testMode: false,
timeout: 30000, // 30 seconds
};
11 changes: 6 additions & 5 deletions src/embedded.js
Expand Up @@ -320,15 +320,15 @@ class HelloSign extends Emitter {
* Validates and appends the "skip_domain_verification"
* parameter to the iFrame params object.
*
* @throws {TypeError} if skipDomainVerification is invalid
* @throws {TypeError} if testMode is invalid
* @param {URLSearchParams} params
* @private
*/
_applySkipDomainVerification(params) {
const val = this._config.skipDomainVerification;
_applyTestMode(params) {
const val = this._config.skipDomainVerification || this._config.testMode;

if (typeof val !== 'boolean') {
throw new TypeError('"skipDomainVerification" must be a boolean');
throw new TypeError('"testMode" must be a boolean');
}

params.append('skip_domain_verification', val ? 1 : 0);
Expand Down Expand Up @@ -394,7 +394,7 @@ class HelloSign extends Emitter {
this._applyParentURL(params);
this._applyRedirectTo(params);
this._applyRequestingEmail(params);
this._applySkipDomainVerification(params);
this._applyTestMode(params);
this._applyUxVersion(params);
this._applyVersion(params);
this._applyWhiteLabeling(params);
Expand Down Expand Up @@ -996,6 +996,7 @@ class HelloSign extends Emitter {
* @property {string} [redirectTo]
* @property {string} [requestingEmail]
* @property {boolean} [skipDomainVerification=false]
* @property {boolean} [testMode=false]
* @property {number} [timeout=30000]
* @property {Object} [whiteLabeling]
*/
Expand Down
42 changes: 41 additions & 1 deletion src/embedded.test.js
Expand Up @@ -428,7 +428,7 @@ describe('HelloSign', () => {
client.open(mockSignURL, {
skipDomainVerification: 42,
});
}).toThrow(/"skipDomainVerification" must be a boolean/);
}).toThrow(/"testMode" must be a boolean/);
});

test('appends default value for "skip_domain_verification" to the iFrame URL if "skipDomainVerification" is not specified', (done) => {
Expand Down Expand Up @@ -461,6 +461,46 @@ describe('HelloSign', () => {
});
});

test('throws if "testMode" is not a boolean', () => {
client = new HelloSign({ clientId: mockClientId });

expect(() => {
client.open(mockSignURL, {
testMode: 42,
});
}).toThrow(/"testMode" must be a boolean/);
});

test('appends default value for "skip_domain_verification" to the iFrame URL if "testMode" is not specified', (done) => {
client = new HelloSign({ clientId: mockClientId });

client.on(HelloSign.events.OPEN, (data) => {
const url = new URL(data.url);

expect(url.searchParams.has('skip_domain_verification')).toBe(true);
expect(url.searchParams.get('skip_domain_verification')).toBe('0');
done();
});

client.open(mockSignURL);
});

test('appends "skip_domain_verification" to the iFrame URL if "testMode" is valid', (done) => {
client = new HelloSign({ clientId: mockClientId });

client.on(HelloSign.events.OPEN, (data) => {
const url = new URL(data.url);

expect(url.searchParams.has('skip_domain_verification')).toBe(true);
expect(url.searchParams.get('skip_domain_verification')).toBe('1');
done();
});

client.open(mockSignURL, {
testMode: true,
});
});

test('throws if "whiteLabeling" is not an object', () => {
client = new HelloSign({ clientId: mockClientId });

Expand Down

0 comments on commit 6d5178b

Please sign in to comment.