-
Notifications
You must be signed in to change notification settings - Fork 83
[FSSDK-12097] refactor OptimizelyUserContext tests using TS and vitest #1114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the OptimizelyUserContext test suite from JavaScript (using Chai/Sinon) to TypeScript with vitest. The refactoring modernizes the test infrastructure while maintaining comprehensive test coverage for user context functionality including attribute management, decision-making, forced decisions, and segment qualification.
Key Changes
- Migrated from Chai assertions to vitest's
expectAPI - Replaced Sinon mocks with vitest's
vi.fn()mocking utilities - Updated mock helpers to use TypeScript types and standardized mock functions (
getMockLogger,getMockEventDispatcher) - Removed deprecated parameters (
shouldIdentifyUser,isValidInstance,eventBatchSize) that are no longer part of the API
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| expect(user.qualifiedSegments).toEqual(['a']); | ||
| }); | ||
|
|
||
| it('should return true for empty returned segements', async () => { |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling error: "segements" should be "segments".
| it('should return true for empty returned segements', async () => { | |
| it('should return true for empty returned segments', async () => { |
| * limitations under the License. | ||
| */ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| import { describe, it, beforeEach, afterEach, expect, vi, Mocked } from 'vitest'; |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import afterEach.
| import { describe, it, beforeEach, afterEach, expect, vi, Mocked } from 'vitest'; | |
| import { describe, it, beforeEach, expect, vi, Mocked } from 'vitest'; |
| import OptimizelyUserContext from './'; | ||
| import Optimizely from '../optimizely'; | ||
| import testData from '../tests/test_data'; | ||
| import { EventDispatcher, NotificationCenter, OptimizelyDecideOption } from '../shared_types'; |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused imports EventDispatcher, NotificationCenter.
| import { EventDispatcher, NotificationCenter, OptimizelyDecideOption } from '../shared_types'; | |
| import { OptimizelyDecideOption } from '../shared_types'; |
| import { getMockProjectConfigManager } from '../tests/mock/mock_project_config_manager'; | ||
| import { createProjectConfig } from '../project_config/project_config'; | ||
| import { getForwardingEventProcessor } from '../event_processor/event_processor_factory'; | ||
| import { FORCED_DECISION_NULL_RULE_KEY } from './index'; |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import FORCED_DECISION_NULL_RULE_KEY.
| import { FORCED_DECISION_NULL_RULE_KEY } from './index'; |
Summary
Test plan
Issues