Skip to content

Commit

Permalink
improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Harper committed Dec 4, 2019
1 parent 10e5709 commit 9059c01
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion modules/consentManagementUsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions test/spec/modules/consentManagementUsp_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
35 changes: 30 additions & 5 deletions test/spec/modules/consentManagement_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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',
Expand Down

0 comments on commit 9059c01

Please sign in to comment.