From 9059c0136970814ec1adf070cb39d64c3f151d2e Mon Sep 17 00:00:00 2001 From: Eric Harper Date: Wed, 4 Dec 2019 01:05:27 -0500 Subject: [PATCH] improved tests --- modules/consentManagementUsp.js | 2 +- .../spec/modules/consentManagementUsp_spec.js | 7 ++++ test/spec/modules/consentManagement_spec.js | 35 ++++++++++++++++--- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/modules/consentManagementUsp.js b/modules/consentManagementUsp.js index ef9410894ba..70446a13255 100644 --- a/modules/consentManagementUsp.js +++ b/modules/consentManagementUsp.js @@ -76,7 +76,7 @@ function lookupUspConsent(uspSuccess, uspError, hookConfig) { } if (!uspapiFrame) { - return uspError('CMP not found.', hookConfig); + return uspError('USP CMP not found.', hookConfig); } try { diff --git a/test/spec/modules/consentManagementUsp_spec.js b/test/spec/modules/consentManagementUsp_spec.js index b1844ef700e..d6e0ef22f83 100644 --- a/test/spec/modules/consentManagementUsp_spec.js +++ b/test/spec/modules/consentManagementUsp_spec.js @@ -56,6 +56,13 @@ describe('consentManagement', function () { sinon.assert.calledOnce(utils.logWarn); sinon.assert.notCalled(utils.logInfo); }); + + it('should exit the consent manager if only config.gdpr is an object', function() { + setConsentConfig({ gdpr: { cmpApi: 'iab' } }); + expect(consentAPI).to.be.undefined; + sinon.assert.calledOnce(utils.logWarn); + sinon.assert.notCalled(utils.logInfo); + }); }); describe('valid setConsentConfig value', function () { diff --git a/test/spec/modules/consentManagement_spec.js b/test/spec/modules/consentManagement_spec.js index 6ca74ddbbd9..9731164c655 100644 --- a/test/spec/modules/consentManagement_spec.js +++ b/test/spec/modules/consentManagement_spec.js @@ -34,6 +34,12 @@ describe('consentManagement', function () { expect(userCMP).to.be.undefined; sinon.assert.calledOnce(utils.logWarn); }); + + it('should exit consent manager if gdpr not set with new config structure', function() { + setConsentConfig({ usp: { cmpApi: 'iab', timeout: 50 } }); + expect(userCMP).to.be.undefined; + sinon.assert.calledOnce(utils.logWarn); + }); }); describe('valid setConsentConfig value', function () { @@ -57,23 +63,42 @@ describe('consentManagement', function () { it('should use new consent manager config structure for gdpr', function() { setConsentConfig({ - gdpr: { cmpApi: 'iab', timeout: 8700 } + gdpr: { cmpApi: 'daa', timeout: 8700 } }); - expect(userCMP).to.be.equal('iab'); + expect(userCMP).to.be.equal('daa'); expect(consentTimeout).to.be.equal(8700); }); - it('should ignore config.usp and use config.gdpr', function() { + it('should ignore config.usp and use config.gdpr, with default cmpApi', function() { setConsentConfig({ - gdpr: { cmpApi: 'iab', timeout: 5000 }, - usp: { cmpApi: 'iab', timeout: 50 } + gdpr: { timeout: 5000 }, + usp: { cmpApi: 'daa', timeout: 50 } }); expect(userCMP).to.be.equal('iab'); expect(consentTimeout).to.be.equal(5000); }); + it('should ignore config.usp and use config.gdpr, with default cmpAip and timeout', function() { + setConsentConfig({ + gdpr: {}, + usp: { cmpApi: 'daa', timeout: 50 } + }); + + expect(userCMP).to.be.equal('iab'); + expect(consentTimeout).to.be.equal(10000); + }); + + it('should recognize config.gdpr, with default cmpAip and timeout', function() { + setConsentConfig({ + gdpr: {} + }); + + expect(userCMP).to.be.equal('iab'); + expect(consentTimeout).to.be.equal(10000); + }); + it('should fallback to old consent manager config object if no config.gdpr', function() { setConsentConfig({ cmpApi: 'iab',