-
Notifications
You must be signed in to change notification settings - Fork 83
[FSSDK-11510] add validation to factories #1060
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright 2025, Optimizely | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { describe, it, expect } from 'vitest'; | ||
|
||
import { getOptimizelyInstance } from './client_factory'; | ||
import { createStaticProjectConfigManager } from './project_config/config_manager_factory'; | ||
import Optimizely from './optimizely'; | ||
|
||
describe('getOptimizelyInstance', () => { | ||
it('should throw if the projectConfigManager is not a valid ProjectConfigManager', () => { | ||
expect(() => getOptimizelyInstance({ | ||
projectConfigManager: undefined as any, | ||
Check warning on line 26 in lib/client_factory.spec.ts
|
||
requestHandler: {} as any, | ||
Check warning on line 27 in lib/client_factory.spec.ts
|
||
})).toThrow('Invalid config manager'); | ||
|
||
expect(() => getOptimizelyInstance({ | ||
projectConfigManager: null as any, | ||
Check warning on line 31 in lib/client_factory.spec.ts
|
||
requestHandler: {} as any, | ||
Check warning on line 32 in lib/client_factory.spec.ts
|
||
})).toThrow('Invalid config manager'); | ||
|
||
expect(() => getOptimizelyInstance({ | ||
projectConfigManager: 'abc' as any, | ||
Check warning on line 36 in lib/client_factory.spec.ts
|
||
requestHandler: {} as any, | ||
Check warning on line 37 in lib/client_factory.spec.ts
|
||
})).toThrow('Invalid config manager'); | ||
|
||
expect(() => getOptimizelyInstance({ | ||
projectConfigManager: 123 as any, | ||
Check warning on line 41 in lib/client_factory.spec.ts
|
||
requestHandler: {} as any, | ||
Check warning on line 42 in lib/client_factory.spec.ts
|
||
})).toThrow('Invalid config manager'); | ||
|
||
expect(() => getOptimizelyInstance({ | ||
projectConfigManager: {} as any, | ||
Check warning on line 46 in lib/client_factory.spec.ts
|
||
requestHandler: {} as any, | ||
Check warning on line 47 in lib/client_factory.spec.ts
|
||
})).toThrow('Invalid config manager'); | ||
}); | ||
|
||
it('should return an instance of Optimizely if a valid projectConfigManager is provided', () => { | ||
const optimizelyInstance = getOptimizelyInstance({ | ||
projectConfigManager: createStaticProjectConfigManager({ | ||
datafile: '{}', | ||
}), | ||
requestHandler: {} as any, | ||
}); | ||
|
||
expect(optimizelyInstance).toBeInstanceOf(Optimizely); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright 2025, Optimizely | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { describe, it, expect } from 'vitest'; | ||
import { createErrorNotifier } from './error_notifier_factory'; | ||
|
||
describe('createErrorNotifier', () => { | ||
it('should throw errors for invalid error handlers', () => { | ||
expect(() => createErrorNotifier(null as any)).toThrow('Invalid error handler'); | ||
expect(() => createErrorNotifier(undefined as any)).toThrow('Invalid error handler'); | ||
|
||
|
||
expect(() => createErrorNotifier('abc' as any)).toThrow('Invalid error handler'); | ||
expect(() => createErrorNotifier(123 as any)).toThrow('Invalid error handler'); | ||
|
||
expect(() => createErrorNotifier({} as any)).toThrow('Invalid error handler'); | ||
|
||
expect(() => createErrorNotifier({ handleError: 'abc' } as any)).toThrow('Invalid error handler'); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.