Skip to content

Commit

Permalink
simplify groups, map columns
Browse files Browse the repository at this point in the history
  • Loading branch information
johndavidsimmons committed May 1, 2019
1 parent 7fd80a6 commit 30dd8ed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 92 deletions.
64 changes: 4 additions & 60 deletions src/providers/Comscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ComscoreProvider extends BaseProvider {
constructor() {
super();
this._key = "COMSCORE";
this._pattern = /sb\.scorecardresearch\.com.+(?<!\.js)$/;
this._pattern = /sb\.scorecardresearch\.com(?!.*\.js($|[?#]))/;
this._name = "Comscore";
this._type = "marketing";
}
Expand All @@ -23,7 +23,7 @@ class ComscoreProvider extends BaseProvider {
get columnMapping() {
return {
account: "c2",
requestType: "requestType"
requestType: "c1"
};
}

Expand All @@ -34,35 +34,13 @@ class ComscoreProvider extends BaseProvider {
*/
get groups() {
return [
{
key: "general",
name: "General"
},
{
key: "custom",
name: "Custom"
}
];
}

/**
* Get all of the available URL parameter keys
*
* @returns {{}}
*/
get keys() {
return {
c1: {
name: "Tag Type",
group: "general"
},
c2: {
name: "Client ID",
group: "general"
}
};
}

/**
* Parse a given URL parameter into human-readable form
*
Expand All @@ -73,8 +51,8 @@ class ComscoreProvider extends BaseProvider {
*/
handleQueryParam(name, value) {
let result = {};

if (name.startsWith("c")) {
const customRegex = /^c\S+$/;
if (name.match(customRegex)) {
result = {
key: name,
field: name,
Expand All @@ -86,38 +64,4 @@ class ComscoreProvider extends BaseProvider {
}
return result;
}

/**
* Parse custom properties for a given URL
*
* @param {string} url
* @param {object} params
*
* @returns {Array}
*/
handleCustom(url, params) {
let results = [],
c1 = params.get("c1"),
c2 = params.get("c2");

if (c1) {
results.push({
key: "tagType",
field: "Tag Type",
value: c1,
group: "general"
});
}

if (c2) {
results.push({
key: "clientID",
field: "Client ID",
value: c2,
group: "general"
});
}

return results;
}
}
32 changes: 0 additions & 32 deletions test/providers/Comscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,6 @@ test("OmnibugProvider returns ComscoreProvider", t => {
t.is(results.provider.key, "COMSCORE", "Results provider is Comscore");
});

test("Provider returns client ID code", t => {
let provider = new ComscoreProvider(),
url =
"https://sb.scorecardresearch.com/p?c1=2&c2=123456789&ns_type=hidden&cv=2.0&cj=1&c4=https://www.example.com";

let results = provider.parseUrl(url),
clientID = results.data.find(result => {
return result.key === "clientID";
});

t.is(typeof clientID, "object", "clientID exists");
t.is(clientID.field, "Client ID", "Field is Client ID");
t.is(clientID.value, "123456789", "Client Code value is correct");
t.is(clientID.group, "general", "Client ID group is general");
});

test("Provider returns tag type", t => {
let provider = new ComscoreProvider(),
url =
"https://sb.scorecardresearch.com/p?c1=2&c2=123456789&ns_type=hidden&cv=2.0&cj=1&c4=https://www.example.com";

let results = provider.parseUrl(url),
tagType = results.data.find(result => {
return result.key === "tagType";
});

t.is(typeof tagType, "object", "tagType exists");
t.is(tagType.field, "Tag Type", "Field is Tag Type");
t.is(tagType.value, "2", "Tag Type value is correct");
t.is(tagType.group, "general", "Tag Type group is general");
});

test("Custom parameters group populates with c parameters", t => {
let provider = new ComscoreProvider(),
url =
Expand Down

0 comments on commit 30dd8ed

Please sign in to comment.