feat: Add context to Cloud Code Triggers beforeLogin and afterLogin (#8724)
This commit is contained in:
@@ -3327,7 +3327,7 @@ describe('beforeLogin hook', () => {
|
||||
expect(req.headers).toBeDefined();
|
||||
expect(req.ip).toBeDefined();
|
||||
expect(req.installationId).toBeDefined();
|
||||
expect(req.context).toBeUndefined();
|
||||
expect(req.context).toBeDefined();
|
||||
});
|
||||
|
||||
await Parse.User.signUp('tupac', 'shakur');
|
||||
@@ -3444,7 +3444,7 @@ describe('afterLogin hook', () => {
|
||||
expect(req.headers).toBeDefined();
|
||||
expect(req.ip).toBeDefined();
|
||||
expect(req.installationId).toBeDefined();
|
||||
expect(req.context).toBeUndefined();
|
||||
expect(req.context).toBeDefined();
|
||||
});
|
||||
|
||||
await Parse.User.signUp('testuser', 'p@ssword');
|
||||
|
||||
@@ -107,6 +107,36 @@ describe('Parse.User testing', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('user login with context', async () => {
|
||||
let hit = 0;
|
||||
const context = { foo: 'bar' };
|
||||
Parse.Cloud.beforeLogin(req => {
|
||||
expect(req.context).toEqual(context);
|
||||
hit++;
|
||||
});
|
||||
Parse.Cloud.afterLogin(req => {
|
||||
expect(req.context).toEqual(context);
|
||||
hit++;
|
||||
});
|
||||
await Parse.User.signUp('asdf', 'zxcv');
|
||||
await request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/login',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'X-Parse-Cloud-Context': JSON.stringify(context),
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: {
|
||||
_method: 'GET',
|
||||
username: 'asdf',
|
||||
password: 'zxcv',
|
||||
},
|
||||
});
|
||||
expect(hit).toBe(2);
|
||||
});
|
||||
|
||||
it('user login with non-string username with REST API', async done => {
|
||||
await Parse.User.signUp('asdf', 'zxcv');
|
||||
request({
|
||||
|
||||
Reference in New Issue
Block a user