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

Mantis Bid Adapter: add adomain support and update storage testing #6969

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion modules/mantisBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';

const storage = getStorageManager();
export const storage = getStorageManager();

function inIframe() {
try {
Expand Down Expand Up @@ -247,6 +247,9 @@ export const spec = {
width: ad.width,
height: ad.height,
ad: ad.html,
meta: {
advertiserDomains: ad.domains || []
},
ttl: ad.ttl || serverResponse.body.ttl || 86400,
creativeId: ad.view,
netRevenue: true,
Expand Down
31 changes: 22 additions & 9 deletions test/spec/modules/mantisBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import {expect} from 'chai';
import {spec} from 'modules/mantisBidAdapter.js';
import {spec, storage} from 'modules/mantisBidAdapter.js';
import {newBidder} from 'src/adapters/bidderFactory.js';
import {sfPostMessage, iframePostMessage} from 'modules/mantisBidAdapter';

describe('MantisAdapter', function () {
const adapter = newBidder(spec);
let sandbox;
const sandbox = sinon.sandbox.create();
let clock;

beforeEach(function() {
sandbox = sinon.sandbox.create();
beforeEach(function () {
clock = sandbox.useFakeTimers();
});

afterEach(function() {
afterEach(function () {
sandbox.restore();
});

Expand Down Expand Up @@ -171,13 +170,12 @@ describe('MantisAdapter', function () {
});

it('use storage uuid', function () {
window.localStorage.setItem('mantis:uuid', 'bar');
sandbox.stub(storage, 'hasLocalStorage').callsFake(() => true);
sandbox.stub(storage, 'getDataFromLocalStorage').withArgs('mantis:uuid').returns('bar');

const request = spec.buildRequests(bidRequests);

expect(request.url).to.include('uuid=bar');

window.localStorage.removeItem('mantis:uuid');
});

it('detect amp', function () {
Expand Down Expand Up @@ -249,6 +247,9 @@ describe('MantisAdapter', function () {
ad: '<!-- Creative -->',
creativeId: 'view',
netRevenue: true,
meta: {
advertiserDomains: []
},
currency: 'USD'
}
];
Expand All @@ -268,6 +269,7 @@ describe('MantisAdapter', function () {
bid: 'bid',
cpm: 1,
view: 'view',
domains: ['foobar.com'],
width: 300,
height: 250,
html: '<!-- Creative -->'
Expand All @@ -286,6 +288,9 @@ describe('MantisAdapter', function () {
ad: '<!-- Creative -->',
creativeId: 'view',
netRevenue: true,
meta: {
advertiserDomains: ['foobar.com']
},
currency: 'USD'
}
];
Expand All @@ -305,6 +310,7 @@ describe('MantisAdapter', function () {
cpm: 1,
view: 'view',
width: 300,
domains: ['foobar.com'],
height: 250,
html: '<!-- Creative -->'
}
Expand All @@ -322,15 +328,22 @@ describe('MantisAdapter', function () {
ad: '<!-- Creative -->',
creativeId: 'view',
netRevenue: true,
meta: {
advertiserDomains: ['foobar.com']
},
currency: 'USD'
}
];
let bidderRequest;

sandbox.stub(storage, 'hasLocalStorage').returns(true);
const spy = sandbox.spy(storage, 'setDataInLocalStorage');

let result = spec.interpretResponse(response, {bidderRequest});

expect(spy.calledWith('mantis:uuid', 'uuid'));
expect(result[0]).to.deep.equal(expectedResponse[0]);
expect(window.mantis_uuid).to.equal(response.body.uuid);
expect(window.localStorage.getItem('mantis:uuid')).to.equal(response.body.uuid);
});

it('no ads returned', function () {
Expand Down