Skip to content

Commit 5dc0b0a

Browse files
committed
feat(client-core): provide cache option to load method
1 parent 5303ba1 commit 5dc0b0a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/cubejs-client-core/test/CubeApi.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,30 @@ describe('CubeApi with Abort Signal', () => {
217217
expect(requestSpy.mock.calls[0]?.[1]?.signal).toBe(signal);
218218
});
219219

220+
test('should pass cache from options to request', async () => {
221+
// Mock for this specific test
222+
const requestSpy = jest.spyOn(HttpTransport.prototype, 'request').mockImplementation(() => ({
223+
subscribe: (cb) => Promise.resolve(cb({
224+
status: 200,
225+
text: () => Promise.resolve('{"results":[]}'),
226+
json: () => Promise.resolve({ results: [] })
227+
} as any,
228+
async () => undefined as any))
229+
}));
230+
231+
const cubeApi = new CubeApi('token', {
232+
apiUrl: 'http://localhost:4000/cubejs-api/v1'
233+
});
234+
235+
await cubeApi.load(
236+
{ measures: ['Orders.count'] },
237+
{ cache: "stale-if-slow" }
238+
);
239+
240+
expect(requestSpy).toHaveBeenCalled();
241+
expect(requestSpy.mock.calls[0]?.[1]?.cache).toBe("stale-if-slow");
242+
});
243+
220244
test('options signal should override constructor signal', async () => {
221245
const constructorController = new AbortController();
222246
const optionsController = new AbortController();

0 commit comments

Comments
 (0)