added afterLogout trigger (#6217)
* added afterLogout trigger * added verification of session object in tests * removed obsolete code * removed unsued code * improved tests to verify user ID
This commit is contained in:
committed by
Diamond Lewis
parent
5cfaaf059a
commit
5ed0885440
@@ -2219,10 +2219,14 @@ describe('afterFind hooks', () => {
|
||||
it('should validate triggers correctly', () => {
|
||||
expect(() => {
|
||||
Parse.Cloud.beforeSave('_Session', () => {});
|
||||
}).toThrow('Triggers are not supported for _Session class.');
|
||||
}).toThrow(
|
||||
'Only the afterLogout trigger is allowed for the _Session class.'
|
||||
);
|
||||
expect(() => {
|
||||
Parse.Cloud.afterSave('_Session', () => {});
|
||||
}).toThrow('Triggers are not supported for _Session class.');
|
||||
}).toThrow(
|
||||
'Only the afterLogout trigger is allowed for the _Session class.'
|
||||
);
|
||||
expect(() => {
|
||||
Parse.Cloud.beforeSave('_PushStatus', () => {});
|
||||
}).toThrow('Only afterSave is allowed on _PushStatus');
|
||||
@@ -2247,6 +2251,22 @@ describe('afterFind hooks', () => {
|
||||
expect(() => {
|
||||
Parse.Cloud.beforeLogin('SomeClass', () => {});
|
||||
}).toThrow('Only the _User class is allowed for the beforeLogin trigger');
|
||||
expect(() => {
|
||||
Parse.Cloud.afterLogout(() => {});
|
||||
}).not.toThrow();
|
||||
expect(() => {
|
||||
Parse.Cloud.afterLogout('_Session', () => {});
|
||||
}).not.toThrow();
|
||||
expect(() => {
|
||||
Parse.Cloud.afterLogout('_User', () => {});
|
||||
}).toThrow(
|
||||
'Only the _Session class is allowed for the afterLogout trigger.'
|
||||
);
|
||||
expect(() => {
|
||||
Parse.Cloud.afterLogout('SomeClass', () => {});
|
||||
}).toThrow(
|
||||
'Only the _Session class is allowed for the afterLogout trigger.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should skip afterFind hooks for aggregate', done => {
|
||||
@@ -2436,6 +2456,22 @@ describe('beforeLogin hook', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
it('should trigger afterLogout hook on logout', async done => {
|
||||
let userId;
|
||||
Parse.Cloud.afterLogout(req => {
|
||||
expect(req.object.className).toEqual('_Session');
|
||||
expect(req.object.id).toBeDefined();
|
||||
const user = req.object.get('user');
|
||||
expect(user).toBeDefined();
|
||||
userId = user.id;
|
||||
});
|
||||
|
||||
const user = await Parse.User.signUp('user', 'pass');
|
||||
await Parse.User.logOut();
|
||||
expect(user.id).toBe(userId);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should have expected data in request', async done => {
|
||||
Parse.Cloud.beforeLogin(req => {
|
||||
expect(req.object).toBeDefined();
|
||||
|
||||
Reference in New Issue
Block a user