-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce jest and test coverage like other SDKs * Introduce test-sdk make target and update buildkite * lib/addons/try-identify.ts test coverage
- Loading branch information
Showing
9 changed files
with
9,158 additions
and
2,495 deletions.
There are no files selected for viewing
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
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,6 @@ | ||
module.exports = { | ||
presets: [ | ||
["@babel/preset-env", { targets: { node: "current" } }], | ||
["@babel/preset-typescript", { targets: { node: "current" } }], | ||
], | ||
}; |
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 OptableSDK from "../sdk"; | ||
import "./try-identify"; | ||
|
||
describe("tryIdentifyFromParams", () => { | ||
var SDK = null; | ||
|
||
beforeEach(() => { | ||
delete window.location; | ||
SDK = new OptableSDK({ host: "localhost", site: "test" }); | ||
SDK.identify = jest.fn(); | ||
}); | ||
|
||
function setURL(url) { | ||
window.location = { | ||
search: url, | ||
}; | ||
} | ||
|
||
test("is correct", () => { | ||
setURL( | ||
"http://some.domain.com/some/path?some=query&something=else&oeid=a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3&foo=bar&baz" | ||
); | ||
SDK.tryIdentifyFromParams(); | ||
|
||
const expected = "e:a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3"; | ||
expect(SDK.identify.mock.calls.length).toBe(1); | ||
expect(SDK.identify.mock.calls[0][0]).toEqual(expected); | ||
}); | ||
|
||
test("identify not called when oeid absent", () => { | ||
setURL("http://some.domain.com/some/path?some=query&something=else"); | ||
SDK.tryIdentifyFromParams(); | ||
|
||
expect(SDK.identify.mock.calls.length).toBe(0); | ||
}); | ||
|
||
test("identify not called when oeid not a SHA256 value", () => { | ||
setURL( | ||
"http://some.domain.com/some/path?some=query&something=else&oeid=AAAAAAAa665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3&foo=bar&baz" | ||
); | ||
SDK.tryIdentifyFromParams(); | ||
|
||
expect(SDK.identify.mock.calls.length).toBe(0); | ||
}); | ||
|
||
test("detects oeid regardless of case", () => { | ||
setURL( | ||
"http://some.domain.com/some/path?some=query&something=else&oEId=A665A45920422F9D417E4867EFDC4FB8A04A1F3FFF1FA07E998E86f7f7A27AE3&foo=bar&baz" | ||
); | ||
SDK.tryIdentifyFromParams(); | ||
|
||
const expected = "e:a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3"; | ||
expect(SDK.identify.mock.calls.length).toBe(1); | ||
expect(SDK.identify.mock.calls[0][0]).toEqual(expected); | ||
}); | ||
}); |
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,37 @@ | ||
import OptableSDK from "./sdk"; | ||
|
||
test("eid is correct", () => { | ||
const expected = "e:a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3"; | ||
|
||
expect(OptableSDK.eid("123")).toEqual(expected); | ||
expect(OptableSDK.eid("123 ")).toEqual(expected); | ||
expect(OptableSDK.eid(" 123")).toEqual(expected); | ||
expect(OptableSDK.eid(" 123 ")).toEqual(expected); | ||
}); | ||
|
||
test("eid ignores case", () => { | ||
const var1 = "[email protected]"; | ||
const var2 = "[email protected]"; | ||
const var3 = "[email protected]"; | ||
const var4 = "[email protected]"; | ||
const eid = OptableSDK.eid(var1); | ||
|
||
expect(eid).toEqual(OptableSDK.eid(var2)); | ||
expect(eid).toEqual(OptableSDK.eid(var3)); | ||
expect(eid).toEqual(OptableSDK.eid(var4)); | ||
}); | ||
|
||
test("cid is correct", () => { | ||
const expected = "c:FooBarBAZ-01234#98765.!!!"; | ||
|
||
expect(expected).toEqual(OptableSDK.cid("FooBarBAZ-01234#98765.!!!")); | ||
expect(expected).toEqual(OptableSDK.cid(" FooBarBAZ-01234#98765.!!!")); | ||
expect(expected).toEqual(OptableSDK.cid("FooBarBAZ-01234#98765.!!! ")); | ||
expect(expected).toEqual(OptableSDK.cid(" FooBarBAZ-01234#98765.!!! ")); | ||
}); | ||
|
||
test("cid is case sensitive", () => { | ||
const unexpected = "c:FooBarBAZ-01234#98765.!!!"; | ||
|
||
expect(OptableSDK.cid("foobarBAZ-01234#98765.!!!")).not.toEqual(unexpected); | ||
}); |
Oops, something went wrong.