Skip to content

Commit

Permalink
Merge pull request #37 from smartadserver/split-imp
Browse files Browse the repository at this point in the history
split imp[0] into seperate requests and fix u.t.
  • Loading branch information
eszponder authored Dec 3, 2024
2 parents 65905e0 + 28a1e74 commit 9aae66c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
22 changes: 15 additions & 7 deletions modules/equativBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { config } from '../src/config.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { getBidFloor } from '../libraries/equativUtils/equativUtils.js'
import { getStorageManager } from '../src/storageManager.js';
Expand Down Expand Up @@ -45,12 +46,18 @@ export const spec = {
return undefined;
}

return {
data: converter.toORTB({ bidderRequest, bidRequests }),
method: 'POST',
// url: 'https://ssb-engine-argocd-dev.internal.smartadserver.com/api/bid?callerId=169'
url: 'https://ssb-global.smartadserver.com/api/bid?callerId=169',
};
const requests = [];

bidRequests.forEach(bid => {
const data = converter.toORTB({bidRequests: [bid], bidderRequest});
requests.push({
data,
method: 'POST',
url: 'https://ssb-global.smartadserver.com/api/bid?callerId=169',
})
});

return requests;
},

/**
Expand Down Expand Up @@ -107,11 +114,12 @@ export const converter = ortbConverter({

imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
const mediaType = deepAccess(bidRequest, 'mediaTypes.video') ? VIDEO : BANNER;
const { siteId, pageId, formatId } = bidRequest.params;

delete imp.dt;

imp.bidfloor = imp.bidfloor || getBidFloor(bidRequest);
imp.bidfloor = imp.bidfloor || getBidFloor(bidRequest, config.getConfig('currency.adServerCurrency'), mediaType);
imp.secure = 1;
imp.tagid = bidRequest.adUnitCode;

Expand Down
52 changes: 26 additions & 26 deletions test/spec/modules/equativBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('Equativ bid adapter tests', () => {
};

describe('buildRequests', () => {
it('should build correct request using ORTB converter', () => {
it('should build correct requests using ORTB converter', () => {
const request = spec.buildRequests(
DEFAULT_BANNER_BID_REQUESTS,
DEFAULT_BANNER_BIDDER_REQUEST
Expand All @@ -127,8 +127,8 @@ describe('Equativ bid adapter tests', () => {
bidderRequest: DEFAULT_BANNER_BIDDER_REQUEST,
bidRequests: DEFAULT_BANNER_BID_REQUESTS,
});
expect(request).to.deep.equal({
data: { ...dataFromConverter, id: request.data.id },
expect(request[0]).to.deep.equal({
data: { ...dataFromConverter, id: request[0].data.id },
method: 'POST',
url: 'https://ssb-global.smartadserver.com/api/bid?callerId=169',
});
Expand All @@ -139,7 +139,7 @@ describe('Equativ bid adapter tests', () => {
{ ...DEFAULT_BANNER_BID_REQUESTS[0], params: { siteId: 123 } },
];
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.imp[0].ext.bidder).to.deep.equal({
siteId: 123,
});
Expand All @@ -150,7 +150,7 @@ describe('Equativ bid adapter tests', () => {
{ ...DEFAULT_BANNER_BID_REQUESTS[0], params: { pageId: 123 } },
];
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.imp[0].ext.bidder).to.deep.equal({
pageId: 123,
});
Expand All @@ -161,7 +161,7 @@ describe('Equativ bid adapter tests', () => {
{ ...DEFAULT_BANNER_BID_REQUESTS[0], params: { formatId: 123 } },
];
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.imp[0].ext.bidder).to.deep.equal({
formatId: 123,
});
Expand All @@ -170,15 +170,15 @@ describe('Equativ bid adapter tests', () => {
it('should not add ext.bidder to imp object when siteId, pageId, formatId are not defined', () => {
const bidRequests = [{ ...DEFAULT_BANNER_BID_REQUESTS[0], params: {} }];
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.imp[0].ext.bidder).to.be.undefined;
});

it('should add site.publisher.id param', () => {
const request = spec.buildRequests(
DEFAULT_BANNER_BID_REQUESTS,
DEFAULT_BANNER_BIDDER_REQUEST
);
)[0];
expect(request.data.site.publisher.id).to.equal(111);
});

Expand All @@ -195,7 +195,7 @@ describe('Equativ bid adapter tests', () => {
}];
delete bidRequests[0].params;
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.site.publisher.id).to.equal(98);
});

Expand All @@ -209,7 +209,7 @@ describe('Equativ bid adapter tests', () => {
}
}];
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.site.publisher.id).to.equal(111);
});

Expand All @@ -226,7 +226,7 @@ describe('Equativ bid adapter tests', () => {
}];
delete bidRequests[0].params;
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.app.publisher.id).to.equal(27);
});

Expand All @@ -240,7 +240,7 @@ describe('Equativ bid adapter tests', () => {
}
}];
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.app.publisher.id).to.equal(111);
});

Expand All @@ -257,7 +257,7 @@ describe('Equativ bid adapter tests', () => {
}];
delete bidRequests[0].params;
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.dooh.publisher.id).to.equal(35);
});

Expand All @@ -271,31 +271,31 @@ describe('Equativ bid adapter tests', () => {
}
}];
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.dooh.publisher.id).to.equal(111);
});

it('should send default floor of 0.0', () => {
const request = spec.buildRequests(
DEFAULT_BANNER_BID_REQUESTS,
DEFAULT_BANNER_BIDDER_REQUEST
);
)[0];
expect(request.data.imp[0]).to.have.property('bidfloor').that.eq(0.0);
});

it('should send secure connection', () => {
const request = spec.buildRequests(
DEFAULT_BANNER_BID_REQUESTS,
DEFAULT_BANNER_BIDDER_REQUEST
);
)[0];
expect(request.data.imp[0]).to.have.property('secure').that.eq(1);
});

it('should have tagid', () => {
const request = spec.buildRequests(
DEFAULT_BANNER_BID_REQUESTS,
DEFAULT_BANNER_BIDDER_REQUEST
);
)[0];
expect(request.data.imp[0]).to.have.property('tagid').that.eq(DEFAULT_BANNER_BID_REQUESTS[0].adUnitCode);
});

Expand All @@ -304,7 +304,7 @@ describe('Equativ bid adapter tests', () => {
{ ...DEFAULT_BANNER_BID_REQUESTS[0], ortb2Imp: { dt: 1728377558235 } }
];
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest);
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.imp[0]).to.not.have.property('dt');
});

Expand All @@ -318,7 +318,7 @@ describe('Equativ bid adapter tests', () => {
const request = spec.buildRequests(
DEFAULT_BANNER_BID_REQUESTS,
DEFAULT_BANNER_BIDDER_REQUEST
);
)[0];

expect(request.data.user).to.have.property('buyeruid').that.eq(cookieData['eqt_pid']);

Expand All @@ -332,7 +332,7 @@ describe('Equativ bid adapter tests', () => {
const request = spec.buildRequests(
DEFAULT_BANNER_BID_REQUESTS,
DEFAULT_BANNER_BIDDER_REQUEST
);
)[0];

expect(request.data).to.not.have.property('user');

Expand All @@ -351,7 +351,7 @@ describe('Equativ bid adapter tests', () => {
}
}
};
const request = spec.buildRequests([ DEFAULT_BANNER_BID_REQUESTS[0] ], bidRequest);
const request = spec.buildRequests([ DEFAULT_BANNER_BID_REQUESTS[0] ], bidRequest)[0];

expect(request.data.user.buyeruid).to.deep.eq(bidRequest.ortb2.user.buyeruid);

Expand All @@ -362,7 +362,7 @@ describe('Equativ bid adapter tests', () => {
// ASSEMBLE
if (FEATURES.VIDEO) {
// ACT
const request = spec.buildRequests(DEFAULT_VIDEO_BID_REQUESTS, {}).data;
const request = spec.buildRequests(DEFAULT_VIDEO_BID_REQUESTS, {})[0].data;

// ASSERT
expect(request.imp[0]).to.have.property('video');
Expand Down Expand Up @@ -400,7 +400,7 @@ describe('Equativ bid adapter tests', () => {
}
];
// ACT
const request = spec.buildRequests(bidRequestsWithOrtb2ImpRwdd, {}).data;
const request = spec.buildRequests(bidRequestsWithOrtb2ImpRwdd, {})[0].data;

// ASSERT
expect(request.imp[0]).to.have.property('rwdd').and.to.equal(1);
Expand All @@ -423,7 +423,7 @@ describe('Equativ bid adapter tests', () => {
}
];
// ACT
const request = spec.buildRequests(bidRequestsWithExtReworded, {}).data;
const request = spec.buildRequests(bidRequestsWithExtReworded, {})[0].data;

// ASSERT
expect(request.imp[0]).to.have.property('rwdd').and.to.equal(1);
Expand All @@ -449,7 +449,7 @@ describe('Equativ bid adapter tests', () => {
}
];
// ACT
const request = spec.buildRequests(bidRequestsWithBothRewordedParams, {}).data;
const request = spec.buildRequests(bidRequestsWithBothRewordedParams, {})[0].data;

// ASSERT
expect(request.imp[0]).to.have.property('rwdd').and.to.equal(2);
Expand Down Expand Up @@ -654,7 +654,7 @@ describe('Equativ bid adapter tests', () => {
const request = spec.buildRequests(
DEFAULT_BANNER_BID_REQUESTS,
DEFAULT_BANNER_BIDDER_REQUEST
);
)[0];
const bids = spec.interpretResponse(SAMPLE_RESPONSE, request);
expect(bids).to.deep.equal(
converter.fromORTB({
Expand Down

0 comments on commit 9aae66c

Please sign in to comment.