Skip to content

Commit

Permalink
pruneIAB test (issue #392)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophieeng committed Jan 3, 2023
1 parent 1ce9d7e commit 0e39a00
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/background/cookiesIAB.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function updateIAB(cookie, value, url) {
* @param {string} signal - the value of an IAB cookie. Example: `1YNN`.
* @return {string} - Updated IAB value to be set
*/
function parseIAB(signal) {
export function parseIAB(signal) {
if (!isValidSignalIAB(signal)) {
return "1NYN";
}
Expand Down
34 changes: 34 additions & 0 deletions test/background/pruneIAB.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import assert from "assert";
import { parseIAB } from "../../src/background/cookiesIAB.js";

/*
function parseIAB(signal) {
if (!isValidSignalIAB(signal)) {
return "1NYN";
}
if (signal === "1---") {
return "1YYY";
} else {
signal = signal.substr(0, 2) + "Y" + signal.substr(3, 1);
return signal;
}
}
*/

describe("Check parsing of IAB signal", () => {
it('Should parse invalid signal to 1NYN', () => {
assert.equal(parseIAB("1WYY"), '1NYN');
});

it('Should parse valid signal 1--- to 1YYY', () => {
assert.equal(parseIAB("1---"), '1YYY');
});

it('Should change third char in valid signal to Y', () => {
assert.equal(parseIAB("1NNN"), '1NYN');
assert.equal(parseIAB("1YNY"), '1YYY');
assert.equal(parseIAB("1NNY"), '1NYY');
});

})

0 comments on commit 0e39a00

Please sign in to comment.