Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/solid-oranges-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reflag/node-sdk": patch
---

fix: correctly associate users with companies
1 change: 1 addition & 0 deletions packages/node-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down
24 changes: 19 additions & 5 deletions packages/node-sdk/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ describe("ReflagClient", () => {
active: true,
},
type: "company",
userId: undefined,
userId: user.id,
},
{
attributes: {
Expand Down Expand Up @@ -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,
},
{
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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,
},
{
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading