Skip to content

Commit

Permalink
Replace name with domain
Browse files Browse the repository at this point in the history
  • Loading branch information
michaloo committed Mar 23, 2017
1 parent a7e34f2 commit db3a4b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Configuration {

if (config.userClaim || config.accountClaim) {
assertClaimValidity("user", config.userClaim, ["id", "email", "external_id", "anonymous_id"]);
assertClaimValidity("account", config.accountClaim, ["id", "external_id", "name", "domain"]);
assertClaimValidity("account", config.accountClaim, ["id", "external_id", "domain"]);
const accessToken = crypto.lookupToken(config, config.subjectType, {
user: config.userClaim,
account: config.accountClaim
Expand Down
17 changes: 10 additions & 7 deletions tests/client-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("Hull", () => {
it("should return scoped client with traits and track methods", () => {
const hull = new Hull({ id: "562123b470df84b740000042", secret: "1234", organization: "test" });

const scopedAccount = hull.asAccount({ name: "Hull" });
const scopedAccount = hull.asAccount({ domain: "hull.io" });
const scopedUser = hull.asUser("1234");

expect(scopedAccount).to.has.property("traits")
Expand Down Expand Up @@ -67,35 +67,38 @@ describe("Hull", () => {
.that.eql("123456");
});

it("should allow to pass account name as an object property", () => {
it("should allow to pass account domain as an object property", () => {
const hull = new Hull({ id: "562123b470df84b740000042", secret: "1234", organization: "test" });

const scoped = hull.asAccount({ name: "Hull" });
const scoped = hull.asAccount({ domain: "hull.io" });
const scopedConfig = scoped.configuration();
const scopedJwtClaims = jwt.decode(scopedConfig.accessToken, scopedConfig.secret);
expect(scopedJwtClaims)
.to.have.property("io.hull.asAccount")
.that.eql({ name: "Hull" });
.that.eql({ domain: "hull.io" });
expect(scopedJwtClaims)
.to.have.property("io.hull.subjectType")
.that.eql("account");
});

it("should allow to link user to an account", () => {
const hull = new Hull({ id: "562123b470df84b740000042", secret: "1234", organization: "test" });

const scoped = hull.asUser({ email: "foo@bar.com" }).account({ name: "Hull" });
const scoped = hull.asUser({ email: "foo@bar.com" }).account({ domain: "hull.io" });
const scopedJwtClaims = jwt.decode(scoped.configuration().accessToken, scoped.configuration().secret);

expect(scopedJwtClaims)
.to.have.property("io.hull.subjectType")
.that.eql("account");
expect(scopedJwtClaims)
.to.have.property("io.hull.asAccount")
.that.eql({ name: "Hull" });
.that.eql({ domain: "hull.io" });
expect(scopedJwtClaims)
.to.have.property("io.hull.asUser")
.that.eql({ email: "foo@bar.com" });
});

it("should allow to link user to an existing account", () => {
it("should allow to resolve an existing account user is linked to", () => {
const hull = new Hull({ id: "562123b470df84b740000042", secret: "1234", organization: "test" });

const scoped = hull.asUser({ email: "foo@bar.com" }).account();
Expand Down

0 comments on commit db3a4b7

Please sign in to comment.