diff --git a/.changeset/solid-oranges-sort.md b/.changeset/solid-oranges-sort.md new file mode 100644 index 00000000..57fa2fc8 --- /dev/null +++ b/.changeset/solid-oranges-sort.md @@ -0,0 +1,5 @@ +--- +"@reflag/node-sdk": patch +--- + +fix: correctly associate users with companies diff --git a/packages/node-sdk/src/client.ts b/packages/node-sdk/src/client.ts index 67cd5e32..39062270 100644 --- a/packages/node-sdk/src/client.ts +++ b/packages/node-sdk/src/client.ts @@ -1228,6 +1228,7 @@ export class ReflagClient { const { id: _, ...attributes } = options.company; promises.push( this.updateCompany(options.company.id, { + userId: options.user?.id, attributes, meta: options.meta, }), diff --git a/packages/node-sdk/test/client.test.ts b/packages/node-sdk/test/client.test.ts index 30f15a09..548909e1 100644 --- a/packages/node-sdk/test/client.test.ts +++ b/packages/node-sdk/test/client.test.ts @@ -1348,7 +1348,7 @@ describe("ReflagClient", () => { active: true, }, type: "company", - userId: undefined, + userId: user.id, }, { attributes: { @@ -1546,7 +1546,7 @@ describe("ReflagClient", () => { employees: 100, name: "Acme Inc.", }, - userId: undefined, // this is a bug, will fix in separate PR + userId: user.id, context: undefined, }, { @@ -1635,7 +1635,14 @@ describe("ReflagClient", () => { await client.initialize(); client.getFlags({ user, company, other: otherContext }); - expect(isAllowedSpy).toHaveBeenCalledWith("1GHpP+QfYperQ0AtD8bWPiRE4H0="); + expect(isAllowedSpy).toHaveBeenNthCalledWith( + 1, + "5Zt35h50IPRNU8yXAj/YbPME/qE=", + ); + expect(isAllowedSpy).toHaveBeenNthCalledWith( + 2, + "J3G4oF56f2t+T6xYzES6inc78+c=", + ); }); it("should return evaluated flags when only user is defined", async () => { @@ -1901,7 +1908,7 @@ describe("ReflagClient", () => { employees: 100, name: "Acme Inc.", }, - userId: undefined, // this is a bug, will fix in separate PR + userId: user.id, context: undefined, }, { @@ -2559,7 +2566,14 @@ describe("ReflagClient", () => { await client.initialize(); client.getFlagsForBootstrap({ user, company, other: otherContext }); - expect(isAllowedSpy).toHaveBeenCalledWith("1GHpP+QfYperQ0AtD8bWPiRE4H0="); + expect(isAllowedSpy).toHaveBeenNthCalledWith( + 1, + "5Zt35h50IPRNU8yXAj/YbPME/qE=", + ); + expect(isAllowedSpy).toHaveBeenNthCalledWith( + 2, + "J3G4oF56f2t+T6xYzES6inc78+c=", + ); }); it("should work in offline mode", async () => {