-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: proxified model props were missing context before attribution (#…
- Loading branch information
Showing
7 changed files
with
138 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"@rocket.chat/models": patch | ||
--- | ||
|
||
Fix proxified model props were missing context before attribution |
This file contains 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,5 @@ | ||
--- | ||
"@rocket.chat/meteor": patch | ||
--- | ||
|
||
Fix error during migration 304. Throwing `Cannot read property 'finally' of undefined` error. |
This file contains 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 |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
"oauthapps", | ||
"omnichannel", | ||
"photoswipe", | ||
"proxify", | ||
"searchbox", | ||
"tmid", | ||
"tshow" | ||
|
This file contains 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,14 @@ | ||
export default { | ||
preset: 'ts-jest', | ||
errorOnDeprecated: true, | ||
testEnvironment: 'jsdom', | ||
modulePathIgnorePatterns: ['<rootDir>/dist/'], | ||
testMatch: ['**/**.spec.ts'], | ||
transform: { | ||
'^.+\\.(t|j)sx?$': '@swc/jest', | ||
}, | ||
moduleNameMapper: { | ||
'\\.css$': 'identity-obj-proxy', | ||
}, | ||
collectCoverage: true, | ||
}; |
This file contains 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 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,91 @@ | ||
import { proxify, registerModel } from './proxify'; | ||
|
||
type MockedModel = { | ||
method: () => MockedModel; | ||
}; | ||
|
||
describe('non lazy proxify', () => { | ||
it('should keep this inside functions', () => { | ||
const collectionMocked = proxify('collection') as MockedModel; | ||
const collection = { | ||
method() { | ||
return this; | ||
}, | ||
}; | ||
registerModel<any>('collection', collection); | ||
|
||
expect(collectionMocked.method()).toBe(collection); | ||
}); | ||
it('should throw an error if the model is not found', () => { | ||
const collectionMocked = proxify('collection-not-found') as MockedModel; | ||
expect(() => collectionMocked.method()).toThrowError('Model collection-not-found not found'); | ||
}); | ||
|
||
it('should return a proxified property', () => { | ||
const collectionMocked = proxify('collection-prop') as { | ||
prop: string; | ||
}; | ||
const collection = { | ||
prop: 'value', | ||
}; | ||
registerModel<any>('collection-prop', collection); | ||
expect(collectionMocked.prop).toBe('value'); | ||
}); | ||
|
||
it('should throw an error if trying to set a property from the proxified object', () => { | ||
const collectionMocked = proxify('collection-prop') as { | ||
prop: string; | ||
}; | ||
const collection = { | ||
prop: 'value', | ||
}; | ||
registerModel<any>('collection-prop', collection); | ||
expect(() => { | ||
collectionMocked.prop = 'new value'; | ||
}).toThrowError('Models accessed via proxify are read-only, use the model instance directly to modify it.'); | ||
}); | ||
}); | ||
|
||
describe('lazy proxify', () => { | ||
it('should keep this inside functions', () => { | ||
const collectionMocked = proxify('collection-lazy') as MockedModel; | ||
const collection = { | ||
method() { | ||
return this; | ||
}, | ||
}; | ||
|
||
registerModel<any>('collection-lazy', () => collection); | ||
|
||
expect(collectionMocked.method()).toBe(collection); | ||
}); | ||
|
||
it('should throw an error if the model is not found', () => { | ||
const collectionMocked = proxify('collection-not-found') as MockedModel; | ||
expect(() => collectionMocked.method()).toThrowError('Model collection-not-found not found'); | ||
}); | ||
|
||
it('should return a proxified property', () => { | ||
const collectionMocked = proxify('collection-prop') as { | ||
prop: string; | ||
}; | ||
const collection = { | ||
prop: 'value', | ||
}; | ||
registerModel<any>('collection-prop', () => collection); | ||
expect(collectionMocked.prop).toBe('value'); | ||
}); | ||
|
||
it('should throw an error if trying to set a property from the proxified object', () => { | ||
const collectionMocked = proxify('collection-prop') as { | ||
prop: string; | ||
}; | ||
const collection = { | ||
prop: 'value', | ||
}; | ||
registerModel<any>('collection-prop', () => collection); | ||
expect(() => { | ||
collectionMocked.prop = 'new value'; | ||
}).toThrowError('Models accessed via proxify are read-only, use the model instance directly to modify it.'); | ||
}); | ||
}); |
This file contains 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