• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prebid / Prebid.js / 16598347968

29 Jul 2025 02:01PM UTC coverage: 96.259% (+0.002%) from 96.257%
16598347968

push

github

web-flow
programmaticXBidAdapter: fix tests (#13688)

* programmaticXBidAdapter: fix tests

* Update adplusAnalyticsAdapter_spec.js

---------

Co-authored-by: Patrick McCann <patmmccann@gmail.com>

39401 of 48422 branches covered (81.37%)

51 of 51 new or added lines in 2 files covered. (100.0%)

219 existing lines in 37 files now uncovered.

194969 of 202547 relevant lines covered (96.26%)

83.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.45
/modules/amxIdSystem.js
1
/**
1✔
2
 * This module adds AMX to the User ID Module
3
 * The {@link module:modules/userId} is required
4
 *
5
 * @module modules/amxIdSystem
6
 * @requires module:modules/userId
7
 */
8
import {uspDataHandler} from '../src/adapterManager.js';
9
import {ajaxBuilder} from '../src/ajax.js';
10
import {submodule} from '../src/hook.js';
11
import {getRefererInfo} from '../src/refererDetection.js';
12
import {deepAccess, logError} from '../src/utils.js';
13
import {getStorageManager} from '../src/storageManager.js';
14
import {MODULE_TYPE_UID} from '../src/activities/modules.js';
15
import {domainOverrideToRootDomain} from '../libraries/domainOverrideToRootDomain/index.js';
16

17
import {getGlobalVarName} from '../src/buildOptions.js';
18

19
const NAME = 'amxId';
1✔
20
const GVL_ID = 737;
1✔
21
const ID_KEY = NAME;
1✔
22
const version = '2.0';
1✔
23
const SYNC_URL = 'https://id.a-mx.com/sync/';
1✔
24
const AJAX_TIMEOUT = 300;
1✔
25
const AJAX_OPTIONS = {method: 'GET', withCredentials: true, contentType: 'text/plain'};
1✔
26

27
export const storage = getStorageManager({moduleName: NAME, moduleType: MODULE_TYPE_UID});
1✔
28
const AMUID_KEY = '__amuidpb';
1✔
29
const getBidAdapterID = () => storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(AMUID_KEY) : null;
6!
30

31
function validateConfig(config) {
32
  if (
7✔
33
    config.storage != null &&
14✔
34
    typeof config.storage.expires === 'number' &&
35
    config.storage.expires > 30
36
  ) {
37
    logError(
1✔
38
      `${NAME}: storage.expires must be <= 30. ${config.storage.expires} was provided`
39
    );
40
    return false;
1✔
41
  }
42

43
  return true;
6✔
44
}
45

46
function handleSyncResponse(client, response, params, callback) {
47
  if (response.id != null && response.id.length > 0) {
3✔
48
    callback(response.id);
1✔
49
    return;
1✔
50
  }
51

52
  if (response.u == null || response.u.length === 0) {
2✔
53
    callback(null);
1✔
54
    return;
1✔
55
  }
56

57
  client(response.u, {
1✔
58
    error(e) {
UNCOV
59
      logError(`${NAME} failed on ${response.u}`, e);
×
UNCOV
60
      callback(null);
×
61
    },
62
    success(complete) {
63
      if (complete != null && complete.length > 0) {
1✔
64
        const value = JSON.parse(complete);
1✔
65
        if (value.id != null) {
1✔
66
          callback(value.id);
1✔
67
          return;
1✔
68
        }
69
      }
70

UNCOV
71
      logError(`${NAME} invalid value`, complete);
×
UNCOV
72
      callback(null);
×
73
    },
74
  }, params, AJAX_OPTIONS);
75
}
76

77
export const amxIdSubmodule = {
1✔
78
  /**
79
   * @type {string}
80
   */
81
  name: NAME,
82

83
  /**
84
   * @type {string}
85
   */
86
  version,
87

88
  /**
89
   * IAB TCF Vendor ID
90
   * @type {string}
91
   */
92
  gvlid: GVL_ID,
93

94
  decode: (value) =>
95
    value != null && value.length > 0
7✔
96
      ? { [ID_KEY]: value }
97
      : undefined,
98

99
  domainOverride: domainOverrideToRootDomain(storage, NAME),
100

101
  getId(config, consentData, _extant) {
102
    if (!validateConfig(config)) {
7✔
103
      return undefined;
1✔
104
    }
105

106
    const consent = consentData?.gdpr || { gdprApplies: false, consentString: '' };
6✔
107
    const client = ajaxBuilder(AJAX_TIMEOUT);
6✔
108
    const usp = uspDataHandler.getConsentData();
6✔
109
    const ref = getRefererInfo();
6✔
110

111
    const params = {
6✔
112
      tagId: deepAccess(config, 'params.tagId', ''),
113

114
      ref: ref.ref,
115
      u: ref.location,
116
      tl: ref.topmostLocation,
117
      nf: ref.numIframes,
118
      rt: ref.reachedTop,
119

120
      v: '$prebid.version$',
121
      av: version,
122
      vg: getGlobalVarName(),
123
      us_privacy: usp,
124
      am: getBidAdapterID(),
125
      gdpr: consent.gdprApplies ? 1 : 0,
6!
126
      gdpr_consent: consent.consentString,
127
    };
128

129
    const callback = (done) =>
6✔
130
      client(
5✔
131
        SYNC_URL,
132
        {
133
          error(e) {
134
            logError(`${NAME} failed to load`, e);
1✔
135
            done(null);
1✔
136
          },
137
          success(responseText) {
138
            if (responseText != null && responseText.length > 0) {
4✔
139
              try {
4✔
140
                const parsed = JSON.parse(responseText);
4✔
141
                handleSyncResponse(client, parsed, params, done);
3✔
142
                return;
3✔
143
              } catch (e) {
144
                logError(`${NAME} invalid response`, responseText);
1✔
145
              }
146
            }
147
            done(null);
1✔
148
          },
149
        },
150
        params,
151
        AJAX_OPTIONS
152
      );
153

154
    return { callback };
6✔
155
  },
156
  eids: {
157
    amxId: {
158
      source: 'amxdt.net',
159
      atype: 1,
160
    },
161
  }
162
};
163

164
submodule('userId', amxIdSubmodule);
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc