npm package diff

Package: @forge/kvs

Versions: 1.1.1-next.1-experimental-994fcd3 - 1.1.1-next.1-experimental-cd26ead

File: package/out/__test__/index.test.js

Index: package/out/__test__/index.test.js
===================================================================
--- package/out/__test__/index.test.js
+++ package/out/__test__/index.test.js
@@ -657,5 +657,114 @@
                 delete: [{ key: 'bar' }]
             })
         }));
     });
+    it('should batchSet correctly with mixed entity and non-entity items', async () => {
+        const response = new Response(JSON.stringify({
+            successfulKeys: [{ key: 'foo', entityName: 'employees' }, { key: 'bar' }],
+            failedKeys: [
+                {
+                    key: 'baz',
+                    entityName: 'departments',
+                    error: { code: 'VALIDATION_ERROR', message: 'Invalid value' }
+                }
+            ]
+        }), {
+            status: 200,
+            headers: { 'x-trace-id': traceId }
+        });
+        const { sut, apiClient } = prepare(response);
+        const items = [
+            { key: 'foo', value: 'John Doe', entityName: 'employees' },
+            { key: 'bar', value: 'simple value' },
+            { key: 'baz', value: 'IT Department', entityName: 'departments' }
+        ];
+        const rs = await sut.batchSet(items);
+        expect(rs).toEqual({
+            successfulKeys: [{ key: 'foo', entityName: 'employees' }, { key: 'bar' }],
+            failedKeys: [
+                {
+                    key: 'baz',
+                    entityName: 'departments',
+                    error: { code: 'VALIDATION_ERROR', message: 'Invalid value' }
+                }
+            ]
+        });
+        expect(apiClient).toHaveBeenCalledWith('/api/v1/batch/set', expect.objectContaining({
+            body: JSON.stringify(items)
+        }));
+    });
+    it('should handle batchSet with all successful keys', async () => {
+        const response = new Response(JSON.stringify({
+            successfulKeys: [{ key: 'foo' }, { key: 'bar' }],
+            failedKeys: []
+        }), {
+            status: 200,
+            headers: { 'x-trace-id': traceId }
+        });
+        const { sut, apiClient } = prepare(response);
+        const items = [
+            { key: 'foo', value: 'value1' },
+            { key: 'bar', value: 'value2' }
+        ];
+        const rs = await sut.batchSet(items);
+        expect(rs).toEqual({
+            successfulKeys: [{ key: 'foo' }, { key: 'bar' }],
+            failedKeys: []
+        });
+        expect(apiClient).toHaveBeenCalledWith('/api/v1/batch/set', expect.objectContaining({
+            body: JSON.stringify(items)
+        }));
+    });
+    it('should handle batchSet with all failed keys', async () => {
+        const response = new Response(JSON.stringify({
+            successfulKeys: [],
+            failedKeys: [
+                {
+                    key: 'foo',
+                    error: { code: 'PERMISSION_DENIED', message: 'Access denied' }
+                },
+                {
+                    key: 'bar',
+                    entityName: 'employees',
+                    error: { code: 'STORAGE_LIMIT_EXCEEDED', message: 'Storage limit exceeded' }
+                }
+            ]
+        }), {
+            status: 200,
+            headers: { 'x-trace-id': traceId }
+        });
+        const { sut, apiClient } = prepare(response);
+        const items = [
+            { key: 'foo', value: 'value1' },
+            { key: 'bar', value: 'value2', entityName: 'employees' }
+        ];
+        const rs = await sut.batchSet(items);
+        expect(rs).toEqual({
+            successfulKeys: [],
+            failedKeys: [
+                {
+                    key: 'foo',
+                    error: { code: 'PERMISSION_DENIED', message: 'Access denied' }
+                },
+                {
+                    key: 'bar',
+                    entityName: 'employees',
+                    error: { code: 'STORAGE_LIMIT_EXCEEDED', message: 'Storage limit exceeded' }
+                }
+            ]
+        });
+        expect(apiClient).toHaveBeenCalledWith('/api/v1/batch/set', expect.objectContaining({
+            body: JSON.stringify(items)
+        }));
+    });
+    it('should handle batchSet API error response', async () => {
+        const response = new Response(JSON.stringify({ code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }), {
+            status: 500,
+            statusText: 'Internal Server Error',
+            headers: { 'x-trace-id': traceId }
+        });
+        const { sut } = prepare(response);
+        const items = [{ key: 'foo', value: 'bar' }];
+        await expect(sut.batchSet(items)).rejects.toMatchError(new errors_1.ForgeKvsAPIError({ status: 500, statusText: 'Internal Server Error', traceId }, { code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }));
+    });
 });