-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Invoca | ||
* https://community.invoca.com/t5/developer-features/an-introduction-to-invocajs-the-technology-behind-your-invoca/ta-p/562 | ||
* | ||
* @class | ||
* @extends BaseProvider | ||
*/ | ||
class InvocaProvider extends BaseProvider { | ||
constructor() { | ||
super(); | ||
this._key = "INVOCA"; | ||
this._pattern = /solutions\.invocacdn\.com\/.*\/tag-(draft|live)\.js/; | ||
this._name = "Invoca"; | ||
this._type = "marketing"; | ||
this._keywords = ["call"]; | ||
} | ||
|
||
/** | ||
* Retrieve the column mappings for default columns (account, event type) | ||
* | ||
* @return {{}} | ||
*/ | ||
get columnMapping() { | ||
return { | ||
"account": "account", | ||
"requestType": "_requestType", | ||
}; | ||
} | ||
|
||
/** | ||
* Retrieve the group names & order | ||
* | ||
* @returns {*[]} | ||
*/ | ||
get groups() | ||
{ | ||
return [ | ||
{ | ||
"key": "general", | ||
"name": "General" | ||
} | ||
]; | ||
} | ||
|
||
/** | ||
* Parse custom properties for a given URL | ||
* | ||
* @param {string} url | ||
* @param {object} params | ||
* | ||
* @returns {void|Array} | ||
*/ | ||
handleCustom(url, params) { | ||
const libraryType = url.pathname.match(/\/tag-([^.]+)\.js/)[1]; | ||
return [ | ||
{ | ||
"key": "account", | ||
"field": "Account ID", | ||
"value": url.pathname.match(/\/(\d+\/\d+)\/tag-/)[1], | ||
"group": "general" | ||
}, | ||
{ | ||
"key": "_requestType", | ||
"value": `Library Load (${libraryType})`, | ||
"hidden": true, | ||
} | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import test from 'ava'; | ||
|
||
import { default as InvocaProvider } from "./../source/providers/Invoca.js"; | ||
import { OmnibugProvider } from "./../source/providers.js"; | ||
|
||
test("InvocaProvider returns provider information", t => { | ||
let provider = new InvocaProvider(); | ||
t.is(provider.key, "INVOCA", "Key should always be INVOCA"); | ||
t.is(provider.type, "Marketing", "Type should always be marketing"); | ||
t.true(typeof provider.name === "string" && provider.name !== "", "Name should exist"); | ||
t.true(typeof provider.pattern === 'object' && provider.pattern instanceof RegExp, "Pattern should be a RegExp value"); | ||
}); | ||
|
||
test("InvocaProvider pattern should match the loader script", t => { | ||
let provider = new InvocaProvider(), | ||
urls = [ | ||
"https://solutions.invocacdn.com/js/networks/1234/123123123/tag-live.js", | ||
"https://solutions.invocacdn.com/js/networks/1234/123123123/tag-draft.js" | ||
], | ||
negativeUrls = [ | ||
"https://static.invoca.com/file.js" | ||
]; | ||
|
||
urls.forEach((url) => { | ||
t.true(provider.checkUrl(url), `Provider should match ${url}`); | ||
}); | ||
negativeUrls.forEach((url) => { | ||
t.false(provider.checkUrl(url), `Provider should not match non-provider url ${url}`); | ||
}); | ||
}); | ||
|
||
test("OmnibugProvider returns InvocaProvider", t => { | ||
let url = "https://solutions.invocacdn.com/js/networks/1234/123123123/tag-live.js"; | ||
|
||
let results = OmnibugProvider.parseUrl(url); | ||
t.true(typeof results === "object" && results !== null, "Results is a non-null object"); | ||
t.is(results.provider.key, "INVOCA", "Results provider is Invoca"); | ||
}); | ||
|
||
test("InvocaProvider returns static data", t => { | ||
let provider = new InvocaProvider(), | ||
url = "https://solutions.invocacdn.com/js/networks/1234/123123123/tag-live.js"; | ||
|
||
let results = provider.parseUrl(url); | ||
|
||
t.is(typeof results.provider, "object", "Results has provider information"); | ||
t.is(results.provider.key, "INVOCA", "Results provider is Invoca"); | ||
t.is(typeof results.data, "object", "Results has data"); | ||
t.true(results.data.length > 0, "Data is returned"); | ||
|
||
let account = results.data.find((result) => { | ||
return result.key === "account"; | ||
}); | ||
|
||
t.is(account.value, "1234/123123123"); | ||
}); |