Repository navigation
Expand file tree
/
Copy pathadswagBidAdapter_spec.js
More file actions
2178 lines (1989 loc) · 80.6 KB
/
Copy pathadswagBidAdapter_spec.js
File metadata and controls
2178 lines (1989 loc) · 80.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { expect } from "chai";
import { dep, spec, storage } from "modules/adswagBidAdapter.js";
import { config } from "src/config.js";
// Everything below lives in ONE outer describe: mocha attaches file-scope
// hooks to the ROOT suite, so a bare beforeEach here would run before every
// test of every OTHER module in Prebid's bundled karma run (and its
// config.resetConfig() wrecked sibling suites that configure in before()).
// The outer describe scopes the hook to this adapter's tests only.
describe("adswagBidAdapter", () => {
// Explicit test-config endpoint every test in this file relies on unless it
// is specifically exercising endpoint resolution (the "endpoint
// configuration" describe block below); it takes precedence over the
// built-in production endpoint. The host must live under adswag.ai: endpoint
// overrides are honored only on Adswag-operated hosts (endpoint domains are
// not variable — review checklist).
const TEST_ENDPOINT = "https://bid.test.adswag.ai/prebid/bid";
// --- helpers ---------------------------------------------------------------
function makeBid(overrides = {}) {
return {
bidder: "adswag",
bidId: "bid-1",
adUnitCode: "div-ad-300x250-2",
mediaTypes: { banner: { sizes: [[300, 250], [300, 600]] } },
ortb2Imp: { ext: { gpid: "/pub-nl-news-1/sport#div-ad-300x250-2" } },
params: { publisherId: "pub-nl-news-1" },
...overrides,
};
}
function makeVideoBid(videoOverrides = {}, bidOverrides = {}) {
return makeBid({
bidId: "bid-v1",
adUnitCode: "div-video-player",
mediaTypes: {
video: {
context: "instream",
playerSize: [[640, 480]],
mimes: ["video/mp4", "video/webm"],
minduration: 5,
maxduration: 30,
protocols: [2, 3, 7, 8],
...videoOverrides,
},
},
ortb2Imp: { ext: { gpid: "/pub-nl-news-1/video#player" } },
...bidOverrides,
});
}
// Feature-gated suites: FEATURES.* is a compile-time constant in real
// Prebid builds (the babel plugin replaces the member expression with a
// boolean literal), so runtime toggling is impossible there. Suites that
// need a flag register conditionally — the upstream convention for
// feature-dependent adapter tests (Prebid's test pipeline forbids
// describe.skip, so the disabled case must not register at all).
const describeIfAudio = FEATURES.AUDIO ? describe : (_title, _fn) => {};
function makeAudioBid(audioOverrides = {}, bidOverrides = {}) {
return makeBid({
bidId: "bid-a1",
adUnitCode: "div-audio-slot",
mediaTypes: {
audio: {
mimes: ["audio/mpeg", "audio/mp4"],
minduration: 10,
maxduration: 30,
protocols: [2, 3, 7, 8],
...audioOverrides,
},
},
ortb2Imp: { ext: { gpid: "/pub-nl-news-1/audio#slot" } },
...bidOverrides,
});
}
function makeBidderRequest(overrides = {}) {
return {
bidderRequestId: "req-abc",
timeout: 300,
refererInfo: { page: "https://nlnews.example.nl/sport", domain: "nlnews.example.nl" },
ortb2: {},
...overrides,
};
}
function parseRequest(serverRequests) {
return JSON.parse(serverRequests[0].data);
}
beforeEach(() => {
config.resetConfig();
// Explicit config endpoint, matching how a real dev/test integration must
// configure the adapter when there is no built-in default. Tests
// exercising resolution itself override/unset this.
config.setConfig({ adswag: { endpoint: TEST_ENDPOINT } });
});
// --- spec object shape -----------------------------------------------------
describe("adswagBidAdapter spec object", () => {
it("registers the adswag bidder code and the served media types", () => {
expect(spec.code).to.equal("adswag");
// Native is deliberately absent (owner decision 2026-08-10): a media
// type is declared only when its documented test unit consistently
// returns creatives, per Prebid's submission checklist. Native returns
// as a follow-up when platform-side serving ships.
// AUDIO rides the FEATURES.AUDIO build flag: audio-less builds must
// not advertise audio support (the gate matches validation/imp
// building). supportedMediaTypes is fixed at module load, so assert
// against the flag's load-time value.
const expected = FEATURES.AUDIO
? ["banner", "video", "audio"]
: ["banner", "video"];
expect(spec.supportedMediaTypes).to.deep.equal(expected);
});
it("declares the TCF device-storage disclosure URL", () => {
// Consumed by Prebid's metadata pipeline; must match the JSON the GVL
// vendor-1417 entry declares (adswag_uuid localStorage+cookie, aswg_uid).
expect(spec.disclosureURL).to.equal(
"https://content.adswag.ai/iab/vendorjson.json",
);
});
it("declares the IAB TCF vendor id (GVL 1417)", () => {
// Prebid core may block bidders without a gvlid when GDPR applies —
// launch-relevant for an EU-only platform, not cosmetic.
expect(spec.gvlid).to.equal(1417);
});
it("exposes the required spec functions", () => {
for (const fn of ["isBidRequestValid", "buildRequests", "interpretResponse"]) {
expect(typeof spec[fn]).to.equal("function");
}
});
});
// --- isBidRequestValid -----------------------------------------------------
describe("isBidRequestValid", () => {
const cases = [
["valid: publisherId + banner sizes", makeBid(), true],
["missing publisherId", makeBid({ params: {} }), false],
["empty publisherId", makeBid({ params: { publisherId: " " } }), false],
["non-string publisherId", makeBid({ params: { publisherId: 123 } }), false],
[
"no sizes at all",
makeBid({ mediaTypes: { banner: {} }, sizes: undefined }),
false,
],
[
"sizes only via bid.sizes",
makeBid({ mediaTypes: {}, sizes: [[728, 90]] }),
true,
],
["null bid (fail-open)", null, false],
["undefined bid (fail-open)", undefined, false],
];
cases.forEach(([name, bid, expected]) => {
it(`${name} → ${expected}`, () => {
expect(spec.isBidRequestValid(bid)).to.equal(expected);
});
});
const videoCases = [
["video: mimes + playerSize", makeVideoBid(), true],
[
"video: mimes without playerSize (lenient)",
makeVideoBid({ playerSize: undefined }),
true,
],
[
"video: playerSize as flat [w,h]",
makeVideoBid({ playerSize: [640, 360] }),
true,
],
["video: no mimes → invalid", makeVideoBid({ mimes: undefined }), false],
["video: empty mimes → invalid", makeVideoBid({ mimes: [] }), false],
[
"video: mimes supplied via params.video override",
makeVideoBid(
{ mimes: undefined },
{ params: { publisherId: "p", video: { mimes: ["video/mp4"] } } },
),
true,
],
["video: outstream context", makeVideoBid({ context: "outstream" }), true],
[
"video: missing publisherId still invalid",
makeVideoBid({}, { params: {} }),
false,
],
[
"mixed unit: valid banner + broken video → still valid",
makeBid({
mediaTypes: {
banner: { sizes: [[300, 250]] },
video: { context: "instream" }, // no mimes
},
}),
true,
],
[
"mixed unit: broken banner + valid video → still valid",
makeBid({
mediaTypes: {
banner: {},
video: { mimes: ["video/mp4"], playerSize: [[640, 480]] },
},
sizes: undefined,
}),
true,
],
];
videoCases.forEach(([name, bid, expected]) => {
it(`${name} → ${expected}`, () => {
expect(spec.isBidRequestValid(bid)).to.equal(expected);
});
});
});
// --- buildRequests ---------------------------------------------------------
describe("buildRequests", () => {
it("produces one POST to the configured endpoint", () => {
const reqs = spec.buildRequests([makeBid()], makeBidderRequest());
expect(reqs).to.have.lengthOf(1);
expect(reqs[0].method).to.equal("POST");
expect(reqs[0].url).to.equal(TEST_ENDPOINT);
});
// withCredentials is consent-conditional (credentials ride only with
// identity consent) — asserted per
// permutation in the "identity consent gate" table below.
it("honors a per-bid endpoint override", () => {
const url = "https://per-bid.test.adswag.ai/prebid/bid";
const reqs = spec.buildRequests(
[makeBid({ params: { publisherId: "p", endpoint: url } })],
makeBidderRequest(),
);
expect(reqs[0].url).to.equal(url);
});
it("honors a global config endpoint override", () => {
const url = "https://cfg.test.adswag.ai/prebid/bid";
config.setConfig({ adswag: { endpoint: url } });
const reqs = spec.buildRequests([makeBid()], makeBidderRequest());
expect(reqs[0].url).to.equal(url);
});
it("maps the imp shape the server reads (id, banner.format, gpid, adunitcode, cur)", () => {
const body = parseRequest(spec.buildRequests([makeBid()], makeBidderRequest()));
expect(body.cur).to.deep.equal(["EUR"]);
expect(body.imp).to.have.lengthOf(1);
const imp = body.imp[0];
expect(imp.id).to.equal("bid-1");
expect(imp.banner.format).to.deep.equal([{ w: 300, h: 250 }, { w: 300, h: 600 }]);
expect(imp.banner.w).to.equal(300);
expect(imp.banner.h).to.equal(250);
expect(imp.ext.gpid).to.equal("/pub-nl-news-1/sport#div-ad-300x250-2");
expect(imp.ext.data.adunitcode).to.equal("div-ad-300x250-2");
expect(body.site.publisher.id).to.equal("pub-nl-news-1");
expect(body.site.page).to.equal("https://nlnews.example.nl/sport");
expect(body.tmax).to.equal(300);
});
it("carries an explicit placementId override into imp.ext.adswag", () => {
const body = parseRequest(
spec.buildRequests(
[makeBid({ params: { publisherId: "p", placementId: "plc-x" } })],
makeBidderRequest(),
),
);
expect(body.imp[0].ext.adswag).to.deep.equal({ placement_id: "plc-x" });
});
it("reads a floor from getFloor (Prebid floors module)", () => {
const bid = makeBid({
getFloor: () => ({ floor: 0.62, currency: "EUR" }),
});
const body = parseRequest(spec.buildRequests([bid], makeBidderRequest()));
expect(body.imp[0].bidfloor).to.equal(0.62);
expect(body.imp[0].bidfloorcur).to.equal("EUR");
});
it("forwards the floors-module floor verbatim — never re-rounded", () => {
// The Price Floors module deliberately rounds UP, to four decimals.
// Re-rounding to two here would hand the endpoint 1.33 for a 1.3334
// floor: a lower floor than the publisher configured, admitting bids
// the floor exists to reject.
const bid = makeBid({ getFloor: () => ({ floor: 1.3334, currency: "EUR" }) });
const body = parseRequest(spec.buildRequests([bid], makeBidderRequest()));
expect(body.imp[0].bidfloor).to.equal(1.3334);
});
it("falls back to params.bidFloor when getFloor is absent", () => {
const bid = makeBid({ params: { publisherId: "p", bidFloor: 1.25 } });
const body = parseRequest(spec.buildRequests([bid], makeBidderRequest()));
expect(body.imp[0].bidfloor).to.equal(1.25);
expect(body.imp[0].bidfloorcur).to.equal("EUR");
});
it("forwards a static params.bidFloor verbatim too", () => {
const bid = makeBid({ params: { publisherId: "p", bidFloor: 0.4567 } });
const body = parseRequest(spec.buildRequests([bid], makeBidderRequest()));
expect(body.imp[0].bidfloor).to.equal(0.4567);
});
it("fails open when getFloor throws — no floor, still builds the imp", () => {
const bid = makeBid({
getFloor: () => {
throw new Error("floors module error");
},
});
const body = parseRequest(spec.buildRequests([bid], makeBidderRequest()));
expect(body.imp[0].bidfloor).to.be.undefined;
expect(body.imp[0].id).to.equal("bid-1");
});
it("forwards TCF consent to user.ext.consent and both regs.gdpr locations", () => {
const bidderRequest = makeBidderRequest({
gdprConsent: { gdprApplies: true, consentString: "CONSENT-STRING" },
});
const body = parseRequest(spec.buildRequests([makeBid()], bidderRequest));
expect(body.user.ext.consent).to.equal("CONSENT-STRING");
expect(body.regs.gdpr).to.equal(1);
expect(body.regs.ext.gdpr).to.equal(1);
});
it("sets regs.gdpr = 0 when gdpr does not apply", () => {
const bidderRequest = makeBidderRequest({
gdprConsent: { gdprApplies: false, consentString: "" },
});
const body = parseRequest(spec.buildRequests([makeBid()], bidderRequest));
expect(body.regs.gdpr).to.equal(0);
expect(body.regs.ext.gdpr).to.equal(0);
});
it("forwards GPP consent to regs.gpp / regs.gpp_sid", () => {
const bidderRequest = makeBidderRequest({
gppConsent: { gppString: "GPP-STRING", applicableSections: [2, 6] },
});
const body = parseRequest(spec.buildRequests([makeBid()], bidderRequest));
expect(body.regs.gpp).to.equal("GPP-STRING");
expect(body.regs.gpp_sid).to.deep.equal([2, 6]);
});
it("forwards the supply chain from ortb2.source.ext.schain", () => {
const schain = {
complete: 1,
ver: "1.0",
nodes: [{ asi: "nlnews.example.nl", sid: "pub-nl-news-1", hp: 1 }],
};
const bidderRequest = makeBidderRequest({
ortb2: { source: { ext: { schain } } },
});
const body = parseRequest(spec.buildRequests([makeBid()], bidderRequest));
expect(body.source.ext.schain).to.deep.equal(schain);
});
it("ignores the legacy bid.schain location (upstream conformance)", () => {
// Prebid review checklist: adapters cannot accept an schain parameter;
// the conventional ortb2 location is the only read.
const schain = { complete: 1, ver: "1.0", nodes: [] };
const body = parseRequest(
spec.buildRequests([makeBid({ schain })], makeBidderRequest()),
);
expect(body.source?.ext?.schain).to.be.undefined;
});
it("never forwards user identifiers when GDPR applies without a vendor-1417 grant", () => {
const bidderRequest = makeBidderRequest({
gdprConsent: { gdprApplies: true, consentString: "C" },
ortb2: {
user: { eids: [{ source: "example.com", uids: [{ id: "abc" }] }] },
},
});
const body = parseRequest(spec.buildRequests([makeBid()], bidderRequest));
expect(body.user.ext.consent).to.equal("C");
expect(body.user.eids).to.be.undefined;
});
it("returns [] when there are no valid bids", () => {
expect(spec.buildRequests([], makeBidderRequest())).to.deep.equal([]);
expect(spec.buildRequests(null, null)).to.deep.equal([]);
});
it("fails open to [] when an internal error is thrown", () => {
const exploding = makeBid();
Object.defineProperty(exploding, "bidId", {
get() {
throw new Error("boom");
},
});
expect(spec.buildRequests([exploding], makeBidderRequest())).to.deep.equal([]);
});
it("forwards ortb2.source.tid and ortb2Imp.ext.tid", () => {
const bidderRequest = makeBidderRequest({
ortb2: { source: { tid: "auction-tid-1" } },
});
const bid = makeBid({
ortb2Imp: { ext: { gpid: "/g", tid: "imp-tid-1" } },
});
const body = parseRequest(spec.buildRequests([bid], bidderRequest));
expect(body.source.tid).to.equal("auction-tid-1");
expect(body.imp[0].ext.tid).to.equal("imp-tid-1");
});
it("handles absent transaction ids cleanly (deprecated fields never read)", () => {
const body = parseRequest(spec.buildRequests([makeBid()], makeBidderRequest()));
expect(body.source).to.be.undefined;
expect(body.imp[0].ext.tid).to.be.undefined;
});
});
// --- request grouping: endpoint + publisher attribution ---------------------
//
// site.publisher.id and the POST url are REQUEST-level, so bids are grouped
// by (resolved endpoint, publisherId) and each group gets its own request.
// A page carrying ad units of two different publisher accounts must not
// report — and pay — every impression under whichever one came first.
describe("buildRequests grouping", () => {
function twoPublisherBids() {
return [
makeBid({
bidId: "bid-pub-a",
adUnitCode: "div-a",
params: { publisherId: "pub-a" },
}),
makeBid({
bidId: "bid-pub-b",
adUnitCode: "div-b",
params: { publisherId: "pub-b" },
}),
];
}
it("emits one request per publisherId, each carrying only its own imps", () => {
const reqs = spec.buildRequests(twoPublisherBids(), makeBidderRequest());
expect(reqs).to.have.lengthOf(2);
const bodies = reqs.map((r) => JSON.parse(r.data));
// The money-relevant assertion: each publisher's impressions are sent
// under that publisher's own account.
expect(bodies[0].site.publisher.id).to.equal("pub-a");
expect(bodies[1].site.publisher.id).to.equal("pub-b");
// Disjoint imps — no impression appears in more than one request.
expect(bodies[0].imp.map((i) => i.id)).to.deep.equal(["bid-pub-a"]);
expect(bodies[1].imp.map((i) => i.id)).to.deep.equal(["bid-pub-b"]);
});
it("gives every group a unique request id (bidderRequestId is not reused)", () => {
const bodies = spec
.buildRequests(twoPublisherBids(), makeBidderRequest())
.map((r) => JSON.parse(r.data));
// First group keeps the id Prebid gave us; the rest get fresh UUIDs.
expect(bodies[0].id).to.equal("req-abc");
expect(bodies[1].id).to.be.a("string").and.not.equal("");
expect(bodies[1].id).to.not.equal(bodies[0].id);
});
it("keeps request-level fields on every group (consent, schain, tid, tmax, device)", () => {
const schain = {
complete: 1,
ver: "1.0",
nodes: [{ asi: "nlnews.example.nl", sid: "s", hp: 1 }],
};
const bidderRequest = makeBidderRequest({
gdprConsent: { gdprApplies: true, consentString: "TC" },
ortb2: {
source: { tid: "auction-tid-1", ext: { schain } },
device: { ua: "UA/1.0" },
},
});
const bodies = spec
.buildRequests(twoPublisherBids(), bidderRequest)
.map((r) => JSON.parse(r.data));
expect(bodies).to.have.lengthOf(2);
bodies.forEach((body) => {
expect(body.user.ext.consent).to.equal("TC");
expect(body.regs.gdpr).to.equal(1);
expect(body.source.ext.schain).to.deep.equal(schain);
// The shared auction correlator across the groups' differing ids.
expect(body.source.tid).to.equal("auction-tid-1");
expect(body.device.ua).to.equal("UA/1.0");
expect(body.tmax).to.equal(300);
expect(body.cur).to.deep.equal(["EUR"]);
});
});
it("keeps ad units of the SAME publisher in one request", () => {
const bids = [
makeBid({ bidId: "bid-1", adUnitCode: "div-1" }),
makeBid({ bidId: "bid-2", adUnitCode: "div-2" }),
];
const reqs = spec.buildRequests(bids, makeBidderRequest());
expect(reqs).to.have.lengthOf(1);
expect(JSON.parse(reqs[0].data).imp.map((i) => i.id)).to.deep.equal([
"bid-1",
"bid-2",
]);
});
it("splits on a differing endpoint too, and posts each group to its own url", () => {
const other = "https://bid.other.adswag.ai/prebid/bid";
const bids = [
makeBid({ bidId: "bid-default" }),
makeBid({
bidId: "bid-override",
adUnitCode: "div-override",
params: { publisherId: "pub-nl-news-1", endpoint: other },
}),
];
const reqs = spec.buildRequests(bids, makeBidderRequest());
expect(reqs).to.have.lengthOf(2);
expect(reqs.map((r) => r.url)).to.deep.equal([TEST_ENDPOINT, other]);
expect(reqs.map((r) => JSON.parse(r.data).imp[0].id)).to.deep.equal([
"bid-default",
"bid-override",
]);
});
it("carries only the group's own bids in the client-side meta array", () => {
const bids = [
makeBid({ bidId: "bid-pub-a", adUnitCode: "div-a", params: { publisherId: "pub-a" } }),
makeVideoBid({}, {
bidId: "bid-pub-b-video",
adUnitCode: "div-b",
params: { publisherId: "pub-b" },
}),
];
const reqs = spec.buildRequests(bids, makeBidderRequest());
expect(reqs.map((r) => r.bidRequests.map((m) => m.bidId))).to.deep.equal([
["bid-pub-a"],
["bid-pub-b-video"],
]);
// Per-group meta is what interpretResponse resolves media types from.
expect(reqs[0].bidRequests[0].hasBanner).to.equal(true);
expect(reqs[0].bidRequests[0].hasVideo).to.equal(false);
expect(reqs[1].bidRequests[0].hasVideo).to.equal(true);
expect(reqs[1].bidRequests[0].videoSize).to.deep.equal([640, 480]);
});
it("interpretResponse resolves each group's bids against that group's request", () => {
const bids = [
makeBid({ bidId: "bid-pub-a", adUnitCode: "div-a", params: { publisherId: "pub-a" } }),
makeVideoBid({}, {
bidId: "bid-pub-b-video",
adUnitCode: "div-b",
params: { publisherId: "pub-b" },
}),
];
const reqs = spec.buildRequests(bids, makeBidderRequest());
const banner = spec.interpretResponse(
{
body: {
cur: "EUR",
seatbid: [
{ bid: [{ impid: "bid-pub-a", price: 1.5, crid: "c1", adm: "<div>ad</div>" }] },
],
},
},
reqs[0],
);
expect(banner[0].mediaType).to.equal("banner");
expect([banner[0].width, banner[0].height]).to.deep.equal([300, 250]);
const video = spec.interpretResponse(
{
body: {
cur: "EUR",
seatbid: [
{
bid: [
{
impid: "bid-pub-b-video",
price: 2.5,
crid: "c2",
adm: "<VAST version=\"4.2\"></VAST>",
},
],
},
],
},
},
reqs[1],
);
expect(video[0].mediaType).to.equal("video");
expect([video[0].width, video[0].height]).to.deep.equal([640, 480]);
});
});
// --- endpoint configuration -------------------------------------------------
//
// Endpoint resolution: params.endpoint > setConfig({adswag:{endpoint}}) >
// the built-in production endpoint (Module Rule 9).
describe("endpoint configuration", () => {
it("uses the built-in production endpoint when nothing is configured", () => {
config.resetConfig();
const reqs = spec.buildRequests([makeBid()], makeBidderRequest());
expect(reqs[0].url).to.equal("https://bid.adswag.ai/prebid/bid");
});
it("falls back to the built-in endpoint on a whitespace-only global config endpoint", () => {
config.resetConfig();
config.setConfig({ adswag: { endpoint: " " } });
const reqs = spec.buildRequests([makeBid()], makeBidderRequest());
expect(reqs[0].url).to.equal("https://bid.adswag.ai/prebid/bid");
});
it("falls back to the built-in endpoint on a whitespace-only per-bid endpoint param", () => {
config.resetConfig();
const bid = makeBid({ params: { publisherId: "p", endpoint: " " } });
const reqs = spec.buildRequests([bid], makeBidderRequest());
expect(reqs[0].url).to.equal("https://bid.adswag.ai/prebid/bid");
});
it("ignores an endpoint override off the adswag.ai domain (endpoint domains are not variable)", () => {
config.resetConfig();
const bid = makeBid({
params: { publisherId: "p", endpoint: "https://collector.example.com/prebid/bid" },
});
const reqs = spec.buildRequests([bid], makeBidderRequest());
expect(reqs[0].url).to.equal("https://bid.adswag.ai/prebid/bid");
});
it("ignores a global config endpoint off the adswag.ai domain", () => {
config.resetConfig();
config.setConfig({ adswag: { endpoint: "https://collector.example.com/prebid/bid" } });
const reqs = spec.buildRequests([makeBid()], makeBidderRequest());
expect(reqs[0].url).to.equal("https://bid.adswag.ai/prebid/bid");
});
it("honors an endpoint override on an adswag.ai host (Adswag dev/staging integrations)", () => {
config.resetConfig();
config.setConfig({ adswag: { endpoint: "https://bid.dev.adswag.ai/prebid/bid" } });
const reqs = spec.buildRequests([makeBid()], makeBidderRequest());
expect(reqs[0].url).to.equal("https://bid.dev.adswag.ai/prebid/bid");
});
it("an ignored off-domain override does not split the batch (both bids ride the built-in endpoint)", () => {
// With a built-in default the endpoint always resolves, so an ignored
// override leaves both ad units in the same publisher/endpoint group.
config.resetConfig();
const bids = [
makeBid({ bidId: "bid-1" }),
makeBid({
bidId: "bid-2",
adUnitCode: "div-2",
params: { publisherId: "pub-nl-news-1", endpoint: "https://collector.example.com/prebid/bid" },
}),
];
const reqs = spec.buildRequests(bids, makeBidderRequest());
expect(reqs).to.have.lengthOf(1);
expect(reqs[0].url).to.equal("https://bid.adswag.ai/prebid/bid");
expect(JSON.parse(reqs[0].data).imp.map((i) => i.id)).to.deep.equal(["bid-1", "bid-2"]);
});
it("a per-bid endpoint override wins over a global config endpoint", () => {
// beforeEach already set adswag.endpoint = TEST_ENDPOINT globally.
const url = "https://per-bid.test.adswag.ai/prebid/bid";
const bid = makeBid({ params: { publisherId: "p", endpoint: url } });
const reqs = spec.buildRequests([bid], makeBidderRequest());
expect(reqs[0].url).to.equal(url);
});
});
// --- identity waterfall (consent-gated, graduated 2026-07-13) ---------------
function fullConsent(
vendorData = {
vendor: { consents: { 1417: true } },
purpose: { consents: { 1: true } },
},
) {
return { gdprApplies: true, consentString: "TC-FULL", vendorData };
}
const EID_A = { source: "id-a.example", uids: [{ id: "a-1", atype: 1 }] };
const EID_B = { source: "id-b.example", uids: [{ id: "b-1", atype: 1 }] };
// Patches the module's exported StorageManager for the duration of fn.
// This is the only cross-environment seam: swapping window is impossible in
// a real browser (window is a getter-only self reference), and Prebid's
// real manager routes through core activity controls — patching the
// manager's own methods works identically against both.
function withStorage(overrides, fn) {
const patched = Object.keys(overrides);
const prev = {};
patched.forEach((k) => {
prev[k] = storage[k];
storage[k] = overrides[k];
});
try {
return fn();
} finally {
patched.forEach((k) => {
storage[k] = prev[k];
});
}
}
function makeFakeLocalStorage() {
const store = new Map();
return {
setItem: (k, v) => store.set(k, String(v)),
getItem: (k) => (store.has(k) ? store.get(k) : null),
removeItem: (k) => store.delete(k),
store,
};
}
function makeFakeCookieDocument() {
const jar = new Map();
const writes = [];
return {
get cookie() {
return [...jar.entries()].map(([k, v]) => `${k}=${v}`).join("; ");
},
set cookie(str) {
writes.push(str);
// browsers trim whitespace around the value, so does this jar
const pair = str.split(";")[0];
const i = pair.indexOf("=");
jar.set(pair.slice(0, i).trim(), pair.slice(i + 1).trim());
},
jar,
writes,
};
}
// StorageManager overrides backed by a fake localStorage (cookies off).
function localStorageOnlyManager(ls) {
return {
localStorageIsEnabled: () => true,
getDataFromLocalStorage: (k) => ls.getItem(k),
setDataInLocalStorage: (k, v) => ls.setItem(k, v),
cookiesAreEnabled: () => false,
getCookie: () => null,
setCookie: () => {},
};
}
// StorageManager overrides backed by a fake cookie jar (localStorage off).
// Same cookie-string format as the real manager (`value ;expires=...`).
function cookieOnlyManager(doc) {
return {
localStorageIsEnabled: () => false,
getDataFromLocalStorage: () => null,
setDataInLocalStorage: () => {},
cookiesAreEnabled: () => true,
getCookie: (name) => {
const m = doc.cookie.match(
"(^|;)\\s*" + name + "\\s*=\\s*([^;]*)\\s*(;|$)",
);
return m ? decodeURIComponent(m[2]) : null;
},
setCookie: (key, value, expires, sameSite, domain) => {
doc.cookie =
`${key}=${encodeURIComponent(value)}` +
(expires ? ` ;expires=${expires}` : "") +
"; path=/" +
(domain ? ` ;domain=${encodeURIComponent(domain)}` : "") +
(sameSite ? `; SameSite=${sameSite}` : "");
},
};
}
describe("identity consent gate (vendor 1417)", () => {
// permutation → [eids attach, withCredentials]
const cases = [
["no gdprConsent at all", undefined, true],
["gdprApplies false", { gdprApplies: false }, true],
["gdprApplies undefined", { consentString: "C" }, true],
["gdpr on + vendor 1417 + purpose 1", fullConsent(), true],
[
"gdpr on + vendor 1417 denied",
fullConsent({ vendor: { consents: { 1417: false } } }),
false,
],
["gdpr on + missing vendorData", fullConsent(null), false],
["gdpr on + vendorData not an object", fullConsent("garbage"), false],
["gdpr on + empty vendorData", fullConsent({}), false],
[
"gdpr on + malformed vendor block",
fullConsent({ vendor: "broken", purpose: { consents: { 1: true } } }),
false,
],
];
cases.forEach(([name, gdprConsent, permitted]) => {
it(`${name} → identity permitted: ${permitted}`, () => {
const bid = makeBid({ userIdAsEids: [EID_A] });
const reqs = spec.buildRequests([bid], makeBidderRequest({ gdprConsent }));
// layer 3: credentialed transport tracks the same gate
expect(reqs[0].options).to.deep.equal({ withCredentials: permitted });
expect(parseRequest(reqs).user?.eids).to.deep.equal(
permitted ? [EID_A] : undefined,
);
});
});
});
describe("eids forwarding (layer 1)", () => {
it("merges userIdAsEids with publisher eids from ortb2, deduped by (source, uids[0].id)", () => {
const bid = makeBid({ userIdAsEids: [EID_A, EID_B] });
const bidderRequest = makeBidderRequest({
gdprConsent: fullConsent(),
ortb2: {
user: {
eids: [EID_B, { source: "id-c.example", uids: [{ id: "c-1" }] }],
ext: { eids: [EID_A] },
},
},
});
const body = parseRequest(spec.buildRequests([bid], bidderRequest));
expect(body.user.eids).to.deep.equal([
EID_A,
EID_B,
{ source: "id-c.example", uids: [{ id: "c-1" }] },
]);
});
it("skips malformed eids (no source, empty uids, missing id) without throwing", () => {
const bid = makeBid({
userIdAsEids: [
{ uids: [{ id: "no-source" }] },
{ source: "id-a.example", uids: [] },
{ source: "id-a.example", uids: [{ id: " " }] },
"not-an-object",
EID_A,
],
});
const body = parseRequest(
spec.buildRequests([bid], makeBidderRequest({ gdprConsent: fullConsent() })),
);
expect(body.user.eids).to.deep.equal([EID_A]);
});
});
describe("first-party UUID (layer 2)", () => {
const UUID_RE = /^[0-9a-f-]{36}$/;
function adswagEid(body) {
// eid source adswag.ai — owner decision 2026-08-06 (matches the
// endpoint + maintainer-contact domain family; frozen at submission).
return (body.user?.eids || []).find((e) => e.source === "adswag.ai");
}
function build(bidderRequest = makeBidderRequest({ gdprConsent: fullConsent() })) {
return parseRequest(spec.buildRequests([makeBid()], bidderRequest));
}
it("mints, persists (localStorage) and reuses adswag_uuid across auctions; reads a pre-existing one", () => {
const localStorage = makeFakeLocalStorage();
withStorage(localStorageOnlyManager(localStorage), () => {
const first = adswagEid(build());
expect(first.uids).to.have.lengthOf(1);
expect(first.uids[0].id).to.match(UUID_RE);
expect(first.uids[0].atype).to.equal(1);
expect(localStorage.store.get("adswag_uuid")).to.equal(first.uids[0].id);
expect(adswagEid(build()).uids[0].id).to.equal(first.uids[0].id);
localStorage.setItem("adswag_uuid", "existing-uuid");
expect(adswagEid(build()).uids[0].id).to.equal("existing-uuid");
});
});
it("falls back to a 365d first-party cookie when localStorage is unavailable", () => {
const document = makeFakeCookieDocument();
withStorage(cookieOnlyManager(document), () => {
const id = adswagEid(build()).uids[0].id;
expect(document.jar.get("adswag_uuid")).to.equal(id);
const write = document.writes[0];
const expires = new Date(write.match(/expires=([^;]+)/)[1]).getTime();
expect(expires - Date.now()).to.be.greaterThan(364 * 86400000);
expect(expires - Date.now()).to.be.lessThan(366 * 86400000);
// reuse on the next auction — no second mint
expect(adswagEid(build()).uids[0].id).to.equal(id);
});
});
it("purpose-1 denial: identity attaches, but no storage read/write and no adswag.ai eid", () => {
const gdprConsent = fullConsent({
vendor: { consents: { 1417: true } },
purpose: { consents: { 1: false } },
});
// Record every data read/write — the purpose-1 gate must keep the
// adapter from touching storage at all (enabled-probes tolerated).
const calls = [];
withStorage(
{
localStorageIsEnabled: () => true,
cookiesAreEnabled: () => true,
getDataFromLocalStorage: (k) => {
calls.push(["get", k]);
return null;
},
setDataInLocalStorage: (k, v) => {
calls.push(["set", k, v]);
},
getCookie: (k) => {
calls.push(["getCookie", k]);
return null;
},
setCookie: (...args) => {
calls.push(["setCookie", ...args]);
},
},
() => {
const bid = makeBid({ userIdAsEids: [EID_A] });
const reqs = spec.buildRequests([bid], makeBidderRequest({ gdprConsent }));
expect(reqs[0].options.withCredentials).to.equal(true); // layer 3 still on
const body = parseRequest(reqs);
expect(body.user.eids).to.deep.equal([EID_A]); // layer 1 still on
expect(adswagEid(body)).to.be.undefined; // layer 2 off
expect(calls).to.deep.equal([]); // no storage read or write
},
);
});
it("fails open when storage is unavailable or throws — no eid, no error, auction proceeds", () => {
// all storage reported unavailable
withStorage(
{
localStorageIsEnabled: () => false,
cookiesAreEnabled: () => false,
getDataFromLocalStorage: () => null,
setDataInLocalStorage: () => {},
getCookie: () => null,
setCookie: () => {},
},
() => {
const body = build();
expect(adswagEid(body)).to.be.undefined;
expect(body.imp).to.have.lengthOf(1);
},
);
// every storage access throws
const boom = () => {
throw new Error("storage blocked");
};
withStorage(
{
localStorageIsEnabled: boom,
cookiesAreEnabled: boom,
getDataFromLocalStorage: boom,
setDataInLocalStorage: boom,
getCookie: boom,
setCookie: boom,
},
() => {
const body = build();
expect(adswagEid(body)).to.be.undefined;
expect(body.imp).to.have.lengthOf(1);
},
);
});
});
// --- publisher key/values (design §4.10 / bid-edge decision record #22) ------
describe("publisher key/values", () => {
it("maps params.kv into imp.ext.data alongside adunitcode/pbadslot", () => {
const bid = makeBid({
ortb2Imp: {
ext: {
gpid: "/pub/slot",
data: { pbadslot: "/1/top", section: "from-ortb2" },
},
},
params: {
publisherId: "pub-nl-news-1",
kv: { slot: ["mid", "x"], year: 2026, tags: ["a", "b"] },
},
});
const data = parseRequest(spec.buildRequests([bid], makeBidderRequest())).imp[0]
.ext.data;
expect(data.adunitcode).to.equal("div-ad-300x250-2");
expect(data.pbadslot).to.equal("/1/top");
expect(data.section).to.equal("from-ortb2");
expect(data.slot).to.deep.equal(["mid", "x"]);
expect(data.year).to.equal(2026);
expect(data.tags).to.deep.equal(["a", "b"]);
});
it("merges ortb2Imp.ext.data and params.kv; the bidder param wins on clash", () => {
const bid = makeBid({
ortb2Imp: {