Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -87,9 +87,12 @@ describe("@hivegrid/foundation", () => {
|
||||
const rows = new Map<string, { requestHash: string; responseStatus: number; responseBody: { ok: boolean } | null; responseHeaders: null }>();
|
||||
const client = {
|
||||
idempotencyKey: {
|
||||
findUnique: vi.fn(async ({ where }) => rows.get(`${where.idempotency_key_scope_key.scope}:${where.idempotency_key_scope_key.key}`) ?? null),
|
||||
findUnique: vi.fn(async ({ where }) => {
|
||||
const key = where.idempotency_key_partition_scope_key;
|
||||
return rows.get(`${key.partitionKey}:${key.scope}:${key.key}`) ?? null;
|
||||
}),
|
||||
create: vi.fn(async ({ data }) => {
|
||||
const key = `${data.scope}:${data.key}`;
|
||||
const key = `${data.partitionKey}:${data.scope}:${data.key}`;
|
||||
if (rows.has(key)) throw Object.assign(new Error("unique"), { code: "P2002" });
|
||||
rows.set(key, {
|
||||
requestHash: data.requestHash,
|
||||
@@ -99,7 +102,8 @@ describe("@hivegrid/foundation", () => {
|
||||
});
|
||||
}),
|
||||
update: vi.fn(async ({ where, data }) => {
|
||||
const key = `${where.idempotency_key_scope_key.scope}:${where.idempotency_key_scope_key.key}`;
|
||||
const unique = where.idempotency_key_partition_scope_key;
|
||||
const key = `${unique.partitionKey}:${unique.scope}:${unique.key}`;
|
||||
const existing = rows.get(key);
|
||||
if (!existing) throw new Error("missing reservation");
|
||||
rows.set(key, {
|
||||
@@ -110,16 +114,16 @@ describe("@hivegrid/foundation", () => {
|
||||
});
|
||||
}),
|
||||
deleteMany: vi.fn(async ({ where }) => {
|
||||
rows.delete(`${where.scope}:${where.key}`);
|
||||
rows.delete(`${where.partitionKey}:${where.scope}:${where.key}`);
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
const first = await withIdempotency({ key: "key_1", fingerprint: { body: "a" } }, client, async () => ({ status: 201, body: { ok: true } }));
|
||||
const replay = await withIdempotency({ key: "key_1", fingerprint: { body: "a" } }, client, async () => ({ status: 500 }));
|
||||
const first = await withIdempotency({ tenantId: "tenant_1", key: "key_1", fingerprint: { body: "a" } }, client, async () => ({ status: 201, body: { ok: true } }));
|
||||
const replay = await withIdempotency({ tenantId: "tenant_1", key: "key_1", fingerprint: { body: "a" } }, client, async () => ({ status: 500 }));
|
||||
expect(first.replayed).toBe(false);
|
||||
expect(replay).toMatchObject({ replayed: true, status: 201, body: { ok: true } });
|
||||
await expect(withIdempotency({ key: "key_1", fingerprint: { body: "b" } }, client, async () => ({ status: 200 }))).rejects.toThrow(CatalogError);
|
||||
await expect(withIdempotency({ tenantId: "tenant_1", key: "key_1", fingerprint: { body: "b" } }, client, async () => ({ status: 200 }))).rejects.toThrow(CatalogError);
|
||||
});
|
||||
|
||||
test("serializes concurrent idempotent operations for the same scope and key", async () => {
|
||||
@@ -134,9 +138,12 @@ describe("@hivegrid/foundation", () => {
|
||||
});
|
||||
const client = {
|
||||
idempotencyKey: {
|
||||
findUnique: vi.fn(async ({ where }) => rows.get(`${where.idempotency_key_scope_key.scope}:${where.idempotency_key_scope_key.key}`) ?? null),
|
||||
findUnique: vi.fn(async ({ where }) => {
|
||||
const key = where.idempotency_key_partition_scope_key;
|
||||
return rows.get(`${key.partitionKey}:${key.scope}:${key.key}`) ?? null;
|
||||
}),
|
||||
create: vi.fn(async ({ data }) => {
|
||||
const key = `${data.scope}:${data.key}`;
|
||||
const key = `${data.partitionKey}:${data.scope}:${data.key}`;
|
||||
if (rows.has(key)) throw Object.assign(new Error("unique"), { code: "P2002" });
|
||||
rows.set(key, {
|
||||
requestHash: data.requestHash,
|
||||
@@ -146,7 +153,8 @@ describe("@hivegrid/foundation", () => {
|
||||
});
|
||||
}),
|
||||
update: vi.fn(async ({ where, data }) => {
|
||||
const key = `${where.idempotency_key_scope_key.scope}:${where.idempotency_key_scope_key.key}`;
|
||||
const unique = where.idempotency_key_partition_scope_key;
|
||||
const key = `${unique.partitionKey}:${unique.scope}:${unique.key}`;
|
||||
const existing = rows.get(key);
|
||||
if (!existing) throw new Error("missing reservation");
|
||||
rows.set(key, {
|
||||
@@ -157,13 +165,13 @@ describe("@hivegrid/foundation", () => {
|
||||
});
|
||||
}),
|
||||
deleteMany: vi.fn(async ({ where }) => {
|
||||
rows.delete(`${where.scope}:${where.key}`);
|
||||
rows.delete(`${where.partitionKey}:${where.scope}:${where.key}`);
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
const first = withIdempotency({ scope: "test", key: "key_concurrent", fingerprint: { body: "a" } }, client, operation);
|
||||
const second = withIdempotency({ scope: "test", key: "key_concurrent", fingerprint: { body: "a" } }, client, operation);
|
||||
const first = withIdempotency({ tenantId: "tenant_1", scope: "test", key: "key_concurrent", fingerprint: { body: "a" } }, client, operation);
|
||||
const second = withIdempotency({ tenantId: "tenant_1", scope: "test", key: "key_concurrent", fingerprint: { body: "a" } }, client, operation);
|
||||
releaseOperation();
|
||||
|
||||
await expect(Promise.all([first, second])).resolves.toEqual([
|
||||
@@ -256,7 +264,7 @@ describe("@hivegrid/foundation", () => {
|
||||
|
||||
expect(client.notificationDelivery.upsert).toHaveBeenCalledWith({
|
||||
where: {
|
||||
tenantId_userId_channel_sourceKey: {
|
||||
notification_delivery_source_key: {
|
||||
tenantId: "tenant_1",
|
||||
userId: "user_1",
|
||||
channel: "EMAIL",
|
||||
|
||||
Reference in new issue
Block a user