Skip to content

Commit

Permalink
fix-test-and-code
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Aleksashkin committed Dec 9, 2021
1 parent bea4801 commit 3511dcc
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 10 deletions.
11 changes: 5 additions & 6 deletions modules/kubientBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { isArray, deepAccess } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import URLSearchParams from 'core-js-pure/web/url-search-params'
import URLSearchParams from 'core-js-pure/web/url-search-params';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import { config } from '../src/config.js';


const BIDDER_CODE = 'kubient';
const END_POINT = 'https://kssp.kbntx.ch/kubprebidjs';
const VERSION = '1.1';
Expand Down Expand Up @@ -117,16 +116,16 @@ export const spec = {
},
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];
var values = new URLSearchParams();
let values = new URLSearchParams();

if (gdprConsent && typeof gdprConsent.consentString === 'string') {
values.append("consent", gdprConsent.consentString);
values.append('consent', gdprConsent.consentString);
if (typeof gdprConsent.gdprApplies === 'boolean') {
values.append("gdpr", Number(gdprConsent.gdprApplies));
values.append('gdpr', Number(gdprConsent.gdprApplies));
}
}
if (uspConsent) {
values.append("usp", uspConsent);
values.append('usp', uspConsent);
}

if (syncOptions.pixelEnabled) {
Expand Down
109 changes: 105 additions & 4 deletions test/spec/modules/kubientBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { expect, assert } from 'chai';
import { spec } from 'modules/kubientBidAdapter.js';
import { BANNER, VIDEO } from '../../../src/mediaTypes.js';
import URLSearchParams from 'core-js-pure/web/url-search-params';
import {config} from '../../../src/config';

describe('KubientAdapter', function () {
let bidBanner = {
Expand Down Expand Up @@ -175,6 +177,94 @@ describe('KubientAdapter', function () {
});
}
});
describe('buildRequestBanner', function () {
config.setConfig({coppa: true});
let serverRequests = spec.buildRequests([bidBanner], Object.assign({}, bidderRequest, {bids: [bidBanner]}));
config.resetConfig();
it('Creates a ServerRequest object with method, URL and data', function () {
expect(serverRequests).to.be.an('array');
});
for (let i = 0; i < serverRequests.length; i++) {
let serverRequest = serverRequests[i];
it('Creates a ServerRequest object with method, URL and data', function () {
expect(serverRequest.method).to.be.a('string');
expect(serverRequest.url).to.be.a('string');
expect(serverRequest.data).to.be.a('string');
});
it('Returns POST method', function () {
expect(serverRequest.method).to.equal('POST');
});
it('Returns valid URL', function () {
expect(serverRequest.url).to.equal('https://kssp.kbntx.ch/kubprebidjs');
});
it('Returns valid data if array of bids is valid', function () {
let data = JSON.parse(serverRequest.data);
expect(data).to.be.an('object');
expect(data).to.have.all.keys('v', 'requestId', 'adSlots', 'gdpr', 'coppa', 'referer', 'tmax', 'consent', 'consentGiven', 'uspConsent');
expect(data.v).to.exist.and.to.be.a('string');
expect(data.requestId).to.exist.and.to.be.a('string');
expect(data.coppa).to.be.a('number').and.to.equal(1);
expect(data.referer).to.be.a('string');
expect(data.tmax).to.exist.and.to.be.a('number');
expect(data.gdpr).to.exist.and.to.be.within(0, 1);
expect(data.consent).to.equal(consentString);
expect(data.uspConsent).to.exist.and.to.equal(uspConsentData);
for (let j = 0; j < data['adSlots'].length; j++) {
let adSlot = data['adSlots'][i];
expect(adSlot).to.have.all.keys('bidId', 'zoneId', 'floor', 'banner', 'schain');
expect(adSlot.bidId).to.be.a('string').and.to.equal(bidBanner.bidId);
expect(adSlot.zoneId).to.be.a('string').and.to.equal(bidBanner.params.zoneid);
expect(adSlot.floor).to.be.a('number');
expect(adSlot.schain).to.be.an('object');
expect(adSlot.banner).to.be.an('object');
}
});
}
});
describe('buildRequestVideo', function () {
config.setConfig({coppa: true});
let serverRequests = spec.buildRequests([bidVideo], Object.assign({}, bidderRequest, {bids: [bidVideo]}));
config.resetConfig();
it('Creates a ServerRequest object with method, URL and data', function () {
expect(serverRequests).to.be.an('array');
});
for (let i = 0; i < serverRequests.length; i++) {
let serverRequest = serverRequests[i];
it('Creates a ServerRequest object with method, URL and data', function () {
expect(serverRequest.method).to.be.a('string');
expect(serverRequest.url).to.be.a('string');
expect(serverRequest.data).to.be.a('string');
});
it('Returns POST method', function () {
expect(serverRequest.method).to.equal('POST');
});
it('Returns valid URL', function () {
expect(serverRequest.url).to.equal('https://kssp.kbntx.ch/kubprebidjs');
});
it('Returns valid data if array of bids is valid', function () {
let data = JSON.parse(serverRequest.data);
expect(data).to.be.an('object');
expect(data).to.have.all.keys('v', 'requestId', 'adSlots', 'gdpr', 'coppa', 'referer', 'tmax', 'consent', 'consentGiven', 'uspConsent');
expect(data.v).to.exist.and.to.be.a('string');
expect(data.requestId).to.exist.and.to.be.a('string');
expect(data.coppa).to.be.a('number').and.to.equal(1);
expect(data.referer).to.be.a('string');
expect(data.tmax).to.exist.and.to.be.a('number');
expect(data.gdpr).to.exist.and.to.be.within(0, 1);
expect(data.consent).to.equal(consentString);
expect(data.uspConsent).to.exist.and.to.equal(uspConsentData);
for (let j = 0; j < data['adSlots'].length; j++) {
let adSlot = data['adSlots'][i];
expect(adSlot).to.have.all.keys('bidId', 'zoneId', 'floor', 'video', 'schain');
expect(adSlot.bidId).to.be.a('string').and.to.equal(bidVideo.bidId);
expect(adSlot.zoneId).to.be.a('string').and.to.equal(bidVideo.params.zoneid);
expect(adSlot.floor).to.be.a('number');
expect(adSlot.schain).to.be.an('object');
expect(adSlot.video).to.be.an('object');
}
});
}
});

describe('isBidRequestValid', function () {
it('Should return true when required params are found', function () {
Expand Down Expand Up @@ -297,35 +387,41 @@ describe('KubientAdapter', function () {
let syncOptions = {
pixelEnabled: true
};
let values = new URLSearchParams();
let serverResponses = null;
let gdprConsent = {
consentString: consentString
};
let uspConsent = null;
let syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent);
values.append('consent', consentString);
expect(syncs).to.be.an('array').and.to.have.length(1);
expect(syncs[0].type).to.equal('image');
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?consent=' + consentString);
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + values.toString());
});
it('should register the sync image with gdpr', function () {
let syncOptions = {
pixelEnabled: true
};
let values = new URLSearchParams();
let serverResponses = null;
let gdprConsent = {
gdprApplies: true,
consentString: consentString
};
let uspConsent = null;
let syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent);
values.append('consent', consentString);
values.append('gdpr', 1);
expect(syncs).to.be.an('array').and.to.have.length(1);
expect(syncs[0].type).to.equal('image');
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?consent=' + consentString + '&gdpr=1');
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + values.toString());
});
it('should register the sync image with gdpr vendor', function () {
let syncOptions = {
pixelEnabled: true
};
let values = new URLSearchParams();
let serverResponses = null;
let gdprConsent = {
gdprApplies: true,
Expand All @@ -341,23 +437,28 @@ describe('KubientAdapter', function () {
};
let uspConsent = null;
let syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent);
values.append('consent', consentString);
values.append('gdpr', 1);
expect(syncs).to.be.an('array').and.to.have.length(1);
expect(syncs[0].type).to.equal('image');
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?consent=' + consentString + '&gdpr=1');
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + values.toString());
});
it('should register the sync image without gdpr and with uspConsent', function () {
let syncOptions = {
pixelEnabled: true
};
let values = new URLSearchParams();
let serverResponses = null;
let gdprConsent = {
consentString: consentString
};
let uspConsent = '1YNN';
let syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent);
values.append('consent', consentString);
values.append('usp', uspConsent);
expect(syncs).to.be.an('array').and.to.have.length(1);
expect(syncs[0].type).to.equal('image');
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?consent=' + consentString + '&usp=' + uspConsent);
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + values.toString());
});
})
});

0 comments on commit 3511dcc

Please sign in to comment.