-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15bb318
commit d37b7e2
Showing
5 changed files
with
153 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import * as mocks from "../mocks"; | ||
import { ClientSideIdentityOptions } from "../uid2ClientSideIdentityOptions"; | ||
import { sdkWindow, UID2 } from "../uid2Sdk"; | ||
|
||
let callback: any; | ||
let uid2: UID2; | ||
let xhrMock: any; | ||
let _cryptoMock; | ||
|
||
const clientSideOpt: ClientSideIdentityOptions = { | ||
serverPublicKey: | ||
"UID2-X-L-24B8a/eLYBmRkXA9yPgRZt+ouKbXewG2OPs23+ov3JC8mtYJBCx6AxGwJ4MlwUcguebhdDp2CvzsCgS9ogwwGA==", | ||
subscriptionId: "subscription-id", | ||
}; | ||
|
||
mocks.setupFakeTime(); | ||
|
||
beforeEach(() => { | ||
callback = jest.fn(); | ||
uid2 = new UID2(); | ||
xhrMock = new mocks.XhrMock(sdkWindow); | ||
_cryptoMock = new mocks.CryptoMock(sdkWindow); | ||
mocks.setCookieMock(sdkWindow.document); | ||
removeUid2LocalStorage(); | ||
}); | ||
|
||
afterEach(() => { | ||
mocks.resetFakeTime(); | ||
}); | ||
|
||
const getUid2LocalStorage = mocks.getUid2LocalStorage; | ||
const removeUid2LocalStorage = mocks.removeUid2LocalStorage; | ||
|
||
describe.only("Using Client-side token generation", () => { | ||
let scenarios = [ | ||
{ | ||
validIdentity: "[email protected]", | ||
invalidIdentity: "test.com", | ||
setIdentityFn: "setIdentityFromEmail", | ||
}, | ||
{ | ||
identity: "lz3+Rj7IV4X1+Vr1ujkG7tstkxwk5pgkqJ6mXbpOgTs=", | ||
invalidIdentity: "[email protected]", | ||
setIdentity: "setIdentityFromEmailHash", | ||
}, | ||
{ | ||
identity: "+12345678910", | ||
invalidIdentity: "12345678910", | ||
setIdentity: "setIdentityFromPhone", | ||
}, | ||
{ | ||
identity: "kVJ+4ilhrqm3HZDDnCQy4niZknvCoM4MkoVzZrQSdJw=", | ||
invalidIdentity: "+12345678910", | ||
setIdentity: "setIdentityFromPhoneHash", | ||
}, | ||
]; | ||
|
||
scenarios.forEach((scenario) => { | ||
describe(scenario.setIdentity!, () => { | ||
describe("When invalid identity is provided", () => { | ||
test("should throw error and not generate UID2", () => {}); | ||
}); | ||
|
||
describe("When valid identity is provided", () => { | ||
describe("when call cstg API succeeds", () => { | ||
test("should invoke the callback", () => {}); | ||
test("should set identity to storage", () => {}); | ||
test("should auto refresh token once token expired", () => {}); | ||
test("should be in available state", () => {}); | ||
}); | ||
|
||
describe("when call cstg API failed", () => { | ||
test("should not set identity", () => {}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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
Empty file.
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,65 @@ | ||
import { makeCstgOption } from "../mocks"; | ||
import { | ||
ClientSideIdentityOptions, | ||
isClientSideIdentityOptionsOrThrow, | ||
} from "../uid2ClientSideIdentityOptions"; | ||
import { UID2 } from "../uid2Sdk"; | ||
|
||
let uid2: UID2; | ||
|
||
const clientSideOpt: ClientSideIdentityOptions = { | ||
serverPublicKey: | ||
"UID2-X-L-24B8a/eLYBmRkXA9yPgRZt+ouKbXewG2OPs23+ov3JC8mtYJBCx6AxGwJ4MlwUcguebhdDp2CvzsCgS9ogwwGA==", | ||
subscriptionId: "subscription-id", | ||
}; | ||
|
||
describe("CSTG Set Identity Tests", () => { | ||
beforeEach(() => { | ||
uid2 = new UID2(); | ||
}); | ||
|
||
describe("When setIdentity is called before init", () => { | ||
test("should throw init not complete error", async () => { | ||
try { | ||
await uid2.setIdentityFromEmail("[email protected]", makeCstgOption()); | ||
fail("Expected an error to be thrown"); | ||
} catch (err: unknown) { | ||
expect(err).toBeInstanceOf(Error); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe("#isClientSideIdentityOptionsOrThrow", () => { | ||
test("should throw opts must be an object error when config is not object", () => { | ||
expect(() => isClientSideIdentityOptionsOrThrow("")).toThrow( | ||
"opts must be an object" | ||
); | ||
}); | ||
test("should throw serverPublicKey must be a string error when serverPublicKey is not a string", () => { | ||
expect(() => | ||
isClientSideIdentityOptionsOrThrow( | ||
makeCstgOption({ serverPublicKey: {} }) | ||
) | ||
).toThrow("opts.serverPublicKey must be a string"); | ||
}); | ||
test("should throw serverPublicKey prefix when serverPublicKey is invalid", () => { | ||
expect(() => | ||
isClientSideIdentityOptionsOrThrow( | ||
makeCstgOption({ serverPublicKey: "test-server-public-key" }) | ||
) | ||
).toThrow( | ||
"opts.serverPublicKey must match the regular expression /^UID2-X-[A-Z]-.+/" | ||
); | ||
}); | ||
test("should throw subscriptionId must be a string error when subscriptionId is not a string", () => { | ||
expect(() => | ||
isClientSideIdentityOptionsOrThrow(makeCstgOption({ subscriptionId: {} })) | ||
).toThrow("opts.subscriptionId must be a string"); | ||
}); | ||
test("should throw subscriptionId is empty error when subscriptionId is not given", () => { | ||
expect(() => | ||
isClientSideIdentityOptionsOrThrow(makeCstgOption({ subscriptionId: "" })) | ||
).toThrow("opts.subscriptionId is empty"); | ||
}); | ||
}); |
File renamed without changes.