Skip to content

Commit 7f89a47

Browse files
authored
fix(node-sdk): include userId when syncing company context (#589)
1 parent 2976a8d commit 7f89a47

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

.changeset/solid-oranges-sort.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@reflag/node-sdk": patch
3+
---
4+
5+
fix: correctly associate users with companies

packages/node-sdk/src/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@ export class ReflagClient {
12281228
const { id: _, ...attributes } = options.company;
12291229
promises.push(
12301230
this.updateCompany(options.company.id, {
1231+
userId: options.user?.id,
12311232
attributes,
12321233
meta: options.meta,
12331234
}),

packages/node-sdk/test/client.test.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ describe("ReflagClient", () => {
13481348
active: true,
13491349
},
13501350
type: "company",
1351-
userId: undefined,
1351+
userId: user.id,
13521352
},
13531353
{
13541354
attributes: {
@@ -1546,7 +1546,7 @@ describe("ReflagClient", () => {
15461546
employees: 100,
15471547
name: "Acme Inc.",
15481548
},
1549-
userId: undefined, // this is a bug, will fix in separate PR
1549+
userId: user.id,
15501550
context: undefined,
15511551
},
15521552
{
@@ -1635,7 +1635,14 @@ describe("ReflagClient", () => {
16351635
await client.initialize();
16361636
client.getFlags({ user, company, other: otherContext });
16371637

1638-
expect(isAllowedSpy).toHaveBeenCalledWith("1GHpP+QfYperQ0AtD8bWPiRE4H0=");
1638+
expect(isAllowedSpy).toHaveBeenNthCalledWith(
1639+
1,
1640+
"5Zt35h50IPRNU8yXAj/YbPME/qE=",
1641+
);
1642+
expect(isAllowedSpy).toHaveBeenNthCalledWith(
1643+
2,
1644+
"J3G4oF56f2t+T6xYzES6inc78+c=",
1645+
);
16391646
});
16401647

16411648
it("should return evaluated flags when only user is defined", async () => {
@@ -1901,7 +1908,7 @@ describe("ReflagClient", () => {
19011908
employees: 100,
19021909
name: "Acme Inc.",
19031910
},
1904-
userId: undefined, // this is a bug, will fix in separate PR
1911+
userId: user.id,
19051912
context: undefined,
19061913
},
19071914
{
@@ -2559,7 +2566,14 @@ describe("ReflagClient", () => {
25592566
await client.initialize();
25602567
client.getFlagsForBootstrap({ user, company, other: otherContext });
25612568

2562-
expect(isAllowedSpy).toHaveBeenCalledWith("1GHpP+QfYperQ0AtD8bWPiRE4H0=");
2569+
expect(isAllowedSpy).toHaveBeenNthCalledWith(
2570+
1,
2571+
"5Zt35h50IPRNU8yXAj/YbPME/qE=",
2572+
);
2573+
expect(isAllowedSpy).toHaveBeenNthCalledWith(
2574+
2,
2575+
"J3G4oF56f2t+T6xYzES6inc78+c=",
2576+
);
25632577
});
25642578

25652579
it("should work in offline mode", async () => {

0 commit comments

Comments
 (0)