-
Notifications
You must be signed in to change notification settings - Fork 13k
feat: Apps "select" setting updater #35644
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7e1344e
add updateValues
Dnouv 40bd981
add removeValues and tsdocs
Dnouv b40a419
add changeset
Dnouv ea3f594
Merge branch 'develop' into ae/new/settings_updater
Dnouv 9912210
merge both into one and rename for human understanding
Dnouv 0556a0a
add test
Dnouv 6d00119
add a todo for future of good logging from ae
Dnouv 4d9dd36
Update changeset
d-gubert 358abd7
Merge branch 'develop' into ae/new/settings_updater
Dnouv b247633
Merge branch 'develop' into ae/new/settings_updater
kodiakhq[bot] fc8e960
Merge branch 'develop' into ae/new/settings_updater
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@rocket.chat/apps-engine': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Adds the ability to dynamically add and remove options from select/multi-select settings in the Apps Engine to support more flexible configuration scenarios by exposing two new methods on the settings API. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
packages/apps-engine/tests/server/accessors/SettingUpdater.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { AsyncTest, Expect, SetupFixture, SpyOn } from 'alsatian'; | ||
|
|
||
| import type { ProxiedApp } from '../../../src/server/ProxiedApp'; | ||
| import { SettingUpdater } from '../../../src/server/accessors'; | ||
| import type { AppSettingsManager } from '../../../src/server/managers'; | ||
| import type { IAppStorageItem } from '../../../src/server/storage'; | ||
| import { TestData } from '../../test-data/utilities'; | ||
|
|
||
| export class SettingUpdaterAccessorTestFixture { | ||
| private mockStorageItem: IAppStorageItem; | ||
|
|
||
| private mockProxiedApp: ProxiedApp; | ||
|
|
||
| private mockSettingsManager: AppSettingsManager; | ||
|
|
||
| @SetupFixture | ||
| public setupFixture() { | ||
| // Set up mock storage with test settings | ||
| this.mockStorageItem = { | ||
| settings: {}, | ||
| } as IAppStorageItem; | ||
|
|
||
| this.mockStorageItem.settings.singleValue = TestData.getSetting('singleValue'); | ||
| this.mockStorageItem.settings.multiValue = { | ||
| ...TestData.getSetting('multiValue'), | ||
| values: [ | ||
| { key: 'key1', i18nLabel: 'value1' }, | ||
| { key: 'key2', i18nLabel: 'value2' }, | ||
| ], | ||
| }; | ||
|
|
||
| // Mock ProxiedApp | ||
| const si = this.mockStorageItem; | ||
| this.mockProxiedApp = { | ||
| getStorageItem(): IAppStorageItem { | ||
| return si; | ||
| }, | ||
| getID(): string { | ||
| return 'test-app-id'; | ||
| }, | ||
| } as ProxiedApp; | ||
|
|
||
| // Mock AppSettingsManager | ||
| this.mockSettingsManager = {} as AppSettingsManager; | ||
| this.mockSettingsManager.getAppSetting = (appId: string, settingId: string) => { | ||
| return this.mockStorageItem.settings[settingId]; | ||
| }; | ||
| this.mockSettingsManager.updateAppSetting = (appId: string, setting: any) => { | ||
| this.mockStorageItem.settings[setting.id] = setting; | ||
| return Promise.resolve(); | ||
| }; | ||
|
|
||
| SpyOn(this.mockSettingsManager, 'getAppSetting'); | ||
| SpyOn(this.mockSettingsManager, 'updateAppSetting'); | ||
| } | ||
|
|
||
| @AsyncTest() | ||
| public async updateValueSuccessfully() { | ||
| const settingUpdater = new SettingUpdater(this.mockProxiedApp, this.mockSettingsManager); | ||
|
|
||
| await settingUpdater.updateValue('singleValue', 'updated value'); | ||
|
|
||
| Expect(this.mockSettingsManager.updateAppSetting).toHaveBeenCalled(); | ||
| Expect(this.mockStorageItem.settings.singleValue.value).toBe('updated value'); | ||
| // Verify updatedAt was set | ||
| Expect(this.mockStorageItem.settings.singleValue.updatedAt).toBeDefined(); | ||
| } | ||
|
|
||
| @AsyncTest() | ||
| public async updateValueThrowsErrorForNonExistentSetting() { | ||
| const settingUpdater = new SettingUpdater(this.mockProxiedApp, this.mockSettingsManager); | ||
|
|
||
| await Expect(() => settingUpdater.updateValue('nonExistent', 'value')).toThrowErrorAsync(Error, 'Setting "nonExistent" not found for app test-app-id'); | ||
| } | ||
|
|
||
| @AsyncTest() | ||
| public async updateSelectOptionsSuccessfully() { | ||
| const settingUpdater = new SettingUpdater(this.mockProxiedApp, this.mockSettingsManager); | ||
| const newValues = [ | ||
| { key: 'key3', i18nLabel: 'value3' }, | ||
| { key: 'key4', i18nLabel: 'value4' }, | ||
| ]; | ||
|
|
||
| await settingUpdater.updateSelectOptions('multiValue', newValues); | ||
|
|
||
| Expect(this.mockSettingsManager.updateAppSetting).toHaveBeenCalled(); | ||
| const updatedValues = this.mockStorageItem.settings.multiValue.values; | ||
| // Should completely replace old values | ||
| Expect((updatedValues ?? []).length).toBe(2); | ||
| Expect(updatedValues).toEqual(newValues); | ||
| // Verify updatedAt was set | ||
| Expect(this.mockStorageItem.settings.multiValue.updatedAt).toBeDefined(); | ||
| } | ||
|
|
||
| @AsyncTest() | ||
| public async updateSelectOptionsThrowsErrorForNonExistentSetting() { | ||
| const settingUpdater = new SettingUpdater(this.mockProxiedApp, this.mockSettingsManager); | ||
|
|
||
| await Expect(() => settingUpdater.updateSelectOptions('nonExistent', [{ key: 'test', i18nLabel: 'value' }])).toThrowErrorAsync( | ||
| Error, | ||
| 'Setting "nonExistent" not found for app test-app-id', | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.