|
| 1 | +import { collab } from '@/proto/messages'; |
| 2 | +import { getAxios } from '@/application/services/js-services/http/core'; |
| 3 | + |
| 4 | +import { collabFullSyncBatch } from '../collab-api'; |
| 5 | + |
| 6 | +jest.mock('@/application/services/js-services/device-id', () => ({ |
| 7 | + getOrCreateDeviceId: jest.fn(() => 'test-device-id'), |
| 8 | +})); |
| 9 | + |
| 10 | +jest.mock('@/application/services/js-services/http/core', () => ({ |
| 11 | + executeAPIRequest: jest.fn(), |
| 12 | + executeAPIVoidRequest: jest.fn(), |
| 13 | + getAxios: jest.fn(), |
| 14 | + parseRetryAfterSecs: jest.fn(), |
| 15 | +})); |
| 16 | + |
| 17 | +const mockGetAxios = getAxios as unknown as jest.Mock; |
| 18 | + |
| 19 | +describe('collabFullSyncBatch', () => { |
| 20 | + beforeEach(() => { |
| 21 | + jest.clearAllMocks(); |
| 22 | + }); |
| 23 | + |
| 24 | + it('sends the encoded protobuf view instead of the pooled backing buffer', async () => { |
| 25 | + const responseBody = collab.CollabBatchSyncResponse.encode( |
| 26 | + collab.CollabBatchSyncResponse.create({ |
| 27 | + results: [], |
| 28 | + responseCompression: collab.PayloadCompressionType.COMPRESSION_NONE, |
| 29 | + }) |
| 30 | + ).finish(); |
| 31 | + const post = jest.fn().mockResolvedValue({ |
| 32 | + status: 200, |
| 33 | + data: responseBody, |
| 34 | + headers: {}, |
| 35 | + }); |
| 36 | + |
| 37 | + mockGetAxios.mockReturnValue({ post }); |
| 38 | + |
| 39 | + await collabFullSyncBatch('workspace-id', [ |
| 40 | + { |
| 41 | + objectId: 'object-id', |
| 42 | + collabType: 0, |
| 43 | + stateVector: new Uint8Array([1]), |
| 44 | + docState: new Uint8Array([2]), |
| 45 | + }, |
| 46 | + ]); |
| 47 | + |
| 48 | + const [, requestBody, config] = post.mock.calls[0]; |
| 49 | + |
| 50 | + expect(ArrayBuffer.isView(requestBody)).toBe(true); |
| 51 | + expect(requestBody.byteLength).toBeLessThan(requestBody.buffer.byteLength); |
| 52 | + expect(config.transformRequest[0](requestBody)).toBe(requestBody); |
| 53 | + }); |
| 54 | +}); |
0 commit comments