-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add SDK Adapter #10256
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
Open
dblythy
wants to merge
10
commits into
parse-community:alpha
Choose a base branch
from
dblythy:feature/sdk-adapter
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: Add SDK Adapter #10256
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eb653a6
feat: Add SDK adapter
dblythy cc7d8b2
add triggerStore
dblythy 0c6b64f
Merge upstream changes, resolve conflict by keeping Parse.Cloud.js de…
dblythy eee657a
coderabbit comments
dblythy 3363158
Update triggers.js
dblythy 6cb61ce
resolve coderabit comments
dblythy de0d965
test: Add e2e tests for TriggerStore, validator cleanup, and _PushSta…
dblythy d6b4443
Merge branch 'alpha' into feature/sdk-adapter
dblythy a7aafe9
fix: Remove unused import and isolate liveQuery handler errors
dblythy 94077a7
Update TriggerStore.ts
dblythy 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
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,158 @@ | ||
| 'use strict'; | ||
|
|
||
| const Parse = require('parse/node'); | ||
|
|
||
| describe('TriggerStore', () => { | ||
| describe('validator cleanup', () => { | ||
| it('should remove stale validator when re-registering function without one', async () => { | ||
| Parse.Cloud.define( | ||
| 'validatedFunc', | ||
| () => 'ok', | ||
| { requireUser: true } | ||
| ); | ||
| await expectAsync( | ||
| Parse.Cloud.run('validatedFunc') | ||
| ).toBeRejectedWith( | ||
| new Parse.Error(Parse.Error.VALIDATION_ERROR, 'Validation failed. Please login to continue.') | ||
| ); | ||
| Parse.Cloud.define('validatedFunc', () => 'ok'); | ||
| const result = await Parse.Cloud.run('validatedFunc'); | ||
| expect(result).toBe('ok'); | ||
| }); | ||
|
|
||
| it('should remove stale validator when re-registering trigger without one', async () => { | ||
| Parse.Cloud.beforeSave('StaleValidatorTest', () => {}, { requireMaster: true }); | ||
| await expectAsync( | ||
| new Parse.Object('StaleValidatorTest').save() | ||
| ).toBeRejectedWith( | ||
| new Parse.Error(Parse.Error.VALIDATION_ERROR, 'Validation failed. Master key is required to complete this request.') | ||
| ); | ||
| Parse.Cloud.beforeSave('StaleValidatorTest', () => {}); | ||
| const obj = new Parse.Object('StaleValidatorTest'); | ||
| await obj.save(); | ||
| expect(obj.id).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('removal cleanup', () => { | ||
| it('should remove validators when removing hooks via _removeAllHooks', async () => { | ||
| Parse.Cloud.define( | ||
| 'hookCleanupFunc', | ||
| () => 'ok', | ||
| { requireUser: true } | ||
| ); | ||
| await expectAsync( | ||
| Parse.Cloud.run('hookCleanupFunc') | ||
| ).toBeRejectedWith( | ||
| new Parse.Error(Parse.Error.VALIDATION_ERROR, 'Validation failed. Please login to continue.') | ||
| ); | ||
| Parse.Cloud._removeAllHooks(); | ||
| Parse.Cloud.define('hookCleanupFunc', () => 'ok'); | ||
| const result = await Parse.Cloud.run('hookCleanupFunc'); | ||
| expect(result).toBe('ok'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('invalid names', () => { | ||
| it('should silently reject function names with quotes', async () => { | ||
| Parse.Cloud.define("test'injection", () => 'bad'); | ||
| await expectAsync( | ||
| Parse.Cloud.run("test'injection") | ||
| ).toBeRejectedWith( | ||
| new Parse.Error(Parse.Error.SCRIPT_FAILED, 'Invalid function: "test\'injection"') | ||
| ); | ||
| }); | ||
|
|
||
| it('should silently reject function names with backticks', async () => { | ||
| Parse.Cloud.define('test`injection', () => 'bad'); | ||
| await expectAsync( | ||
| Parse.Cloud.run('test`injection') | ||
| ).toBeRejectedWith( | ||
| new Parse.Error(Parse.Error.SCRIPT_FAILED, 'Invalid function: "test`injection"') | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('_PushStatus validation', () => { | ||
| it('should reject beforeSave on _PushStatus', () => { | ||
| expect(() => { | ||
| Parse.Cloud.beforeSave('_PushStatus', () => {}); | ||
| }).toThrow('Only afterSave is allowed on _PushStatus'); | ||
| }); | ||
|
|
||
| it('should reject beforeDelete on _PushStatus', () => { | ||
| expect(() => { | ||
| Parse.Cloud.beforeDelete('_PushStatus', () => {}); | ||
| }).toThrow('Only afterSave is allowed on _PushStatus'); | ||
| }); | ||
|
|
||
| it('should reject beforeFind on _PushStatus', () => { | ||
| expect(() => { | ||
| Parse.Cloud.beforeFind('_PushStatus', () => {}); | ||
| }).toThrow('Only afterSave is allowed on _PushStatus'); | ||
| }); | ||
|
|
||
| it('should reject afterDelete on _PushStatus', () => { | ||
| expect(() => { | ||
| Parse.Cloud.afterDelete('_PushStatus', () => {}); | ||
| }).toThrow('Only afterSave is allowed on _PushStatus'); | ||
| }); | ||
|
|
||
| it('should allow afterSave on _PushStatus', () => { | ||
| expect(() => { | ||
| Parse.Cloud.afterSave('_PushStatus', () => {}); | ||
| }).not.toThrow(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Parse.Server setter', () => { | ||
| it('should merge properties without losing existing config', () => { | ||
| const originalKeys = Object.keys(Parse.Server); | ||
| Parse.Server = { customProp: true }; | ||
| const config = Parse.Server; | ||
| expect(config.customProp).toBe(true); | ||
| for (const key of ['appId', 'masterKey', 'serverURL']) { | ||
| expect(config[key]).toBeDefined(); | ||
| } | ||
| expect(Object.keys(config).length).toBeGreaterThanOrEqual(originalKeys.length); | ||
| }); | ||
| }); | ||
|
|
||
| describe('live query event handlers', () => { | ||
| it('should forward events to cloud code handler', async () => { | ||
| let receivedData; | ||
| Parse.Cloud.onLiveQueryEvent(data => { | ||
| receivedData = data; | ||
| }); | ||
| const triggers = require('../lib/triggers'); | ||
| triggers.runLiveQueryEventHandlers({ event: 'test' }); | ||
| expect(receivedData).toEqual({ event: 'test' }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('beforeLogin validator', () => { | ||
| it('should enforce validator on beforeLogin', async () => { | ||
| Parse.Cloud.beforeLogin(() => {}, { requireMaster: true }); | ||
| const user = new Parse.User(); | ||
| user.setUsername('loginval_user'); | ||
| user.setPassword('password'); | ||
| await user.signUp(); | ||
| await Parse.User.logOut(); | ||
| await expectAsync( | ||
| Parse.User.logIn('loginval_user', 'password') | ||
| ).toBeRejectedWith( | ||
| new Parse.Error(Parse.Error.VALIDATION_ERROR, 'Validation failed. Master key is required to complete this request.') | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('useMasterKey deprecation', () => { | ||
| it('should warn on useMasterKey call', () => { | ||
| const spy = spyOn(console, 'warn'); | ||
| Parse.Cloud.useMasterKey(); | ||
| expect(spy).toHaveBeenCalledWith( | ||
| jasmine.stringContaining('useMasterKey is deprecated') | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.