mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 15:02:02 +00:00
57 lines
2 KiB
JavaScript
57 lines
2 KiB
JavaScript
const mockDownload = jest.fn();
|
|
const mockGetBlockBlobClient = jest.fn(() => ({ download: mockDownload }));
|
|
const mockGetAzureContainerClient = jest.fn(async () => ({
|
|
url: 'https://account.blob.core.windows.net/files',
|
|
getBlockBlobClient: mockGetBlockBlobClient,
|
|
}));
|
|
|
|
jest.mock('@librechat/data-schemas', () => ({
|
|
logger: { error: jest.fn() },
|
|
}));
|
|
|
|
jest.mock('@librechat/api', () => ({
|
|
deleteRagFile: jest.fn(),
|
|
assertRemoteFileURL: jest.fn((url) => url),
|
|
getAzureContainerClient: (...args) => mockGetAzureContainerClient(...args),
|
|
getRemoteFileFetchMaxBytes: jest.fn(() => 1024),
|
|
getRemoteFileFetchTimeoutMs: jest.fn(() => 1000),
|
|
assertRemoteFileContentLength: jest.fn(),
|
|
}));
|
|
|
|
const { getAzureFileStream } = require('./crud');
|
|
|
|
describe('getAzureFileStream', () => {
|
|
it('downloads private blobs through the authenticated Azure client', async () => {
|
|
const stream = { pipe: jest.fn() };
|
|
mockDownload.mockResolvedValue({ readableStreamBody: stream });
|
|
|
|
await expect(
|
|
getAzureFileStream(
|
|
{},
|
|
'https://account.blob.core.windows.net/private-files/uploads/user/report%20one.pdf',
|
|
),
|
|
).resolves.toBe(stream);
|
|
|
|
expect(mockGetAzureContainerClient).toHaveBeenCalledWith('private-files');
|
|
expect(mockGetBlockBlobClient).toHaveBeenCalledWith('uploads/user/report one.pdf');
|
|
});
|
|
|
|
it('resolves Azurite blobs relative to the configured account and container path', async () => {
|
|
const stream = { pipe: jest.fn() };
|
|
mockDownload.mockResolvedValue({ readableStreamBody: stream });
|
|
mockGetAzureContainerClient.mockResolvedValueOnce({
|
|
url: 'http://127.0.0.1:10000/devstoreaccount1/files',
|
|
getBlockBlobClient: mockGetBlockBlobClient,
|
|
});
|
|
|
|
await expect(
|
|
getAzureFileStream(
|
|
{},
|
|
'http://127.0.0.1:10000/devstoreaccount1/files/uploads/user/report%20one.pdf',
|
|
),
|
|
).resolves.toBe(stream);
|
|
|
|
expect(mockGetAzureContainerClient).toHaveBeenCalledWith();
|
|
expect(mockGetBlockBlobClient).toHaveBeenCalledWith('uploads/user/report one.pdf');
|
|
});
|
|
});
|