|
1 | 1 | /**
|
2 |
| - * Copyright 2024, Optimizely |
| 2 | + * Copyright 2024-2025, Optimizely |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -28,9 +28,9 @@ vi.mock('./odp_manager_factory', () => {
|
28 | 28 |
|
29 | 29 | import { describe, it, expect, beforeEach, vi } from 'vitest';
|
30 | 30 | import { getOpaqueOdpManager, OdpManagerOptions } from './odp_manager_factory';
|
31 |
| -import { BROWSER_DEFAULT_API_TIMEOUT, createOdpManager } from './odp_manager_factory.browser'; |
| 31 | +import { BROWSER_DEFAULT_API_TIMEOUT, BROWSER_DEFAULT_BATCH_SIZE, BROWSER_DEFAULT_FLUSH_INTERVAL, createOdpManager } from './odp_manager_factory.browser'; |
32 | 32 | import { BrowserRequestHandler } from '../utils/http_request_handler/request_handler.browser';
|
33 |
| -import { pixelApiRequestGenerator } from './event_manager/odp_event_api_manager'; |
| 33 | +import { eventApiRequestGenerator, pixelApiRequestGenerator } from './event_manager/odp_event_api_manager'; |
34 | 34 |
|
35 | 35 | describe('createOdpManager', () => {
|
36 | 36 | const MockBrowserRequestHandler = vi.mocked(BrowserRequestHandler);
|
@@ -77,25 +77,39 @@ describe('createOdpManager', () => {
|
77 | 77 | expect(requestHandlerOptions?.timeout).toBe(BROWSER_DEFAULT_API_TIMEOUT);
|
78 | 78 | });
|
79 | 79 |
|
80 |
| - it('should use batchSize 1 if batchSize is not provided', () => { |
81 |
| - const odpManager = createOdpManager({}); |
| 80 | + it('should use the provided eventBatchSize', () => { |
| 81 | + const odpManager = createOdpManager({ eventBatchSize: 99 }); |
82 | 82 | expect(odpManager).toBe(mockGetOpaqueOdpManager.mock.results[0].value);
|
83 | 83 | const { eventBatchSize } = mockGetOpaqueOdpManager.mock.calls[0][0];
|
84 |
| - expect(eventBatchSize).toBe(1); |
| 84 | + expect(eventBatchSize).toBe(99); |
85 | 85 | });
|
86 | 86 |
|
87 |
| - it('should use batchSize 1 event if some other batchSize value is provided', () => { |
88 |
| - const odpManager = createOdpManager({ eventBatchSize: 99 }); |
| 87 | + it('should use the browser default eventBatchSize if none provided', () => { |
| 88 | + const odpManager = createOdpManager({}); |
89 | 89 | expect(odpManager).toBe(mockGetOpaqueOdpManager.mock.results[0].value);
|
90 | 90 | const { eventBatchSize } = mockGetOpaqueOdpManager.mock.calls[0][0];
|
91 |
| - expect(eventBatchSize).toBe(1); |
| 91 | + expect(eventBatchSize).toBe(BROWSER_DEFAULT_BATCH_SIZE); |
| 92 | + }); |
| 93 | + |
| 94 | + it('should use the provided eventFlushInterval', () => { |
| 95 | + const odpManager = createOdpManager({ eventFlushInterval: 9999 }); |
| 96 | + expect(odpManager).toBe(mockGetOpaqueOdpManager.mock.results[0].value); |
| 97 | + const { eventFlushInterval } = mockGetOpaqueOdpManager.mock.calls[0][0]; |
| 98 | + expect(eventFlushInterval).toBe(9999); |
| 99 | + }); |
| 100 | + |
| 101 | + it('should use the browser default eventFlushInterval if none provided', () => { |
| 102 | + const odpManager = createOdpManager({}); |
| 103 | + expect(odpManager).toBe(mockGetOpaqueOdpManager.mock.results[0].value); |
| 104 | + const { eventFlushInterval } = mockGetOpaqueOdpManager.mock.calls[0][0]; |
| 105 | + expect(eventFlushInterval).toBe(BROWSER_DEFAULT_FLUSH_INTERVAL); |
92 | 106 | });
|
93 | 107 |
|
94 |
| - it('uses the pixel api request generator', () => { |
| 108 | + it('uses the event api request generator', () => { |
95 | 109 | const odpManager = createOdpManager({ });
|
96 | 110 | expect(odpManager).toBe(mockGetOpaqueOdpManager.mock.results[0].value);
|
97 | 111 | const { eventRequestGenerator } = mockGetOpaqueOdpManager.mock.calls[0][0];
|
98 |
| - expect(eventRequestGenerator).toBe(pixelApiRequestGenerator); |
| 112 | + expect(eventRequestGenerator).toBe(eventApiRequestGenerator); |
99 | 113 | });
|
100 | 114 |
|
101 | 115 | it('uses the passed options for relevant fields', () => {
|
|
0 commit comments