Skip to content

Commit c28ee49

Browse files
committed
Test for deterministic data store resolution if there are multiple entries
1 parent 95dc130 commit c28ee49

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

apps/webapp/test/organizationDataStoresRegistry.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,39 @@ describe("OrganizationDataStoresRegistry", () => {
117117
expect(z?.url).toBe(TEST_URL);
118118
});
119119

120+
postgresTest(
121+
"when an org appears in multiple data stores, first row by id asc wins",
122+
async ({ prisma }) => {
123+
const registry = new OrganizationDataStoresRegistry(prisma);
124+
const sharedOrg = "org-dup-overlap";
125+
126+
await registry.addDataStore({
127+
key: "dup-overlap-first",
128+
kind: "CLICKHOUSE",
129+
organizationIds: [sharedOrg],
130+
config: ClickhouseConnectionSchema.parse({ url: TEST_URL }),
131+
});
132+
await registry.addDataStore({
133+
key: "dup-overlap-second",
134+
kind: "CLICKHOUSE",
135+
organizationIds: [sharedOrg],
136+
config: ClickhouseConnectionSchema.parse({ url: TEST_URL_2 }),
137+
});
138+
139+
const [winner] = await prisma.organizationDataStore.findMany({
140+
where: { key: { in: ["dup-overlap-first", "dup-overlap-second"] } },
141+
orderBy: { id: "asc" },
142+
});
143+
expect(winner).toBeDefined();
144+
145+
await registry.loadFromDatabase();
146+
147+
const expectedUrl =
148+
winner!.key === "dup-overlap-first" ? TEST_URL : TEST_URL_2;
149+
expect(registry.get(sharedOrg, "CLICKHOUSE")?.url).toBe(expectedUrl);
150+
}
151+
);
152+
120153
postgresTest("updateDataStore updates organizationIds and rotates the secret", async ({ prisma }) => {
121154
const registry = new OrganizationDataStoresRegistry(prisma);
122155

0 commit comments

Comments
 (0)