feat: Add afterFind trigger to authentication adapters (#8444)
This commit is contained in:
@@ -59,6 +59,19 @@ describe('Auth Adapter features', () => {
|
||||
validateLogin: () => Promise.resolve(),
|
||||
};
|
||||
|
||||
const modernAdapter3 = {
|
||||
validateAppId: () => Promise.resolve(),
|
||||
validateSetUp: () => Promise.resolve(),
|
||||
validateUpdate: () => Promise.resolve(),
|
||||
validateLogin: () => Promise.resolve(),
|
||||
validateOptions: () => Promise.resolve(),
|
||||
afterFind() {
|
||||
return {
|
||||
foo: 'bar',
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const wrongAdapter = {
|
||||
validateAppId: () => Promise.resolve(),
|
||||
};
|
||||
@@ -332,6 +345,17 @@ describe('Auth Adapter features', () => {
|
||||
expect(user.getSessionToken()).toBeDefined();
|
||||
});
|
||||
|
||||
it('should strip out authData if required', async () => {
|
||||
const spy = spyOn(modernAdapter3, 'validateOptions').and.callThrough();
|
||||
await reconfigureServer({ auth: { modernAdapter3 }, silent: false });
|
||||
const user = new Parse.User();
|
||||
await user.save({ authData: { modernAdapter3: { id: 'modernAdapter3Data' } } });
|
||||
await user.fetch({ sessionToken: user.getSessionToken() });
|
||||
const authData = user.get('authData').modernAdapter3;
|
||||
expect(authData).toEqual({ foo: 'bar' });
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should throw if no triggers found', async () => {
|
||||
await reconfigureServer({ auth: { wrongAdapter } });
|
||||
const user = new Parse.User();
|
||||
|
||||
@@ -248,7 +248,7 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
|
||||
expect(object.date[0] instanceof Date).toBeTrue();
|
||||
expect(object.bar.date[0] instanceof Date).toBeTrue();
|
||||
expect(object.foo.test.date[0] instanceof Date).toBeTrue();
|
||||
const obj = await new Parse.Query('MyClass').first({useMasterKey: true});
|
||||
const obj = await new Parse.Query('MyClass').first({ useMasterKey: true });
|
||||
expect(obj.get('date')[0] instanceof Date).toBeTrue();
|
||||
expect(obj.get('bar').date[0] instanceof Date).toBeTrue();
|
||||
expect(obj.get('foo').test.date[0] instanceof Date).toBeTrue();
|
||||
|
||||
Reference in New Issue
Block a user