зеркало из https://github.com/mozilla/fxa.git
Merge pull request #16247 from mozilla/fxa-8842
feat(delete): Delete user firestore record on delete event
This commit is contained in:
Коммит
a54cbea5a7
|
@ -185,4 +185,18 @@ describe('#integration - FirestoreService', () => {
|
||||||
},
|
},
|
||||||
TEST_TIMEOUT
|
TEST_TIMEOUT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it(
|
||||||
|
'deletes a user record',
|
||||||
|
async () => {
|
||||||
|
await service.storeLogin(uid1, 'fx_send');
|
||||||
|
let result = await service.fetchClientIds(uid1);
|
||||||
|
expect(result).toStrictEqual(['fx_send']);
|
||||||
|
|
||||||
|
await service.deleteUser(uid1);
|
||||||
|
result = await service.fetchClientIds(uid1);
|
||||||
|
expect(result).toStrictEqual([]);
|
||||||
|
},
|
||||||
|
TEST_TIMEOUT
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -87,6 +87,19 @@ export class FirestoreService {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a user record in firebase.
|
||||||
|
*
|
||||||
|
* @param uid
|
||||||
|
*/
|
||||||
|
public async deleteUser(uid: string): Promise<void> {
|
||||||
|
const document = this.db.doc(
|
||||||
|
`${this.prefix}users/${uid}`
|
||||||
|
) as TypedDocumentReference<UserDocument>;
|
||||||
|
|
||||||
|
await document.delete();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the OAuth Client Ids that a user has directly logged in to
|
* Fetches the OAuth Client Ids that a user has directly logged in to
|
||||||
* via a Relying Party flow.
|
* via a Relying Party flow.
|
||||||
|
|
|
@ -105,6 +105,7 @@ describe('QueueworkerService', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
firestore = {
|
firestore = {
|
||||||
storeLogin: jest.fn().mockResolvedValue({}),
|
storeLogin: jest.fn().mockResolvedValue({}),
|
||||||
|
deleteUser: jest.fn().mockResolvedValue({}),
|
||||||
fetchClientIds: jest
|
fetchClientIds: jest
|
||||||
.fn()
|
.fn()
|
||||||
.mockResolvedValue(['444c5d137fc34d82ae65441d7f26a504']),
|
.mockResolvedValue(['444c5d137fc34d82ae65441d7f26a504']),
|
||||||
|
|
|
@ -191,6 +191,18 @@ export class QueueworkerService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send delete event to RPs and delete user record from datastore.
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private async handleDeleteEvent(message: dto.deleteSchema) {
|
||||||
|
await this.handleMessageFanout(message, 'delete');
|
||||||
|
|
||||||
|
await this.firestore.deleteUser(message.uid);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save login to RP to datastore.
|
* Save login to RP to datastore.
|
||||||
*
|
*
|
||||||
|
@ -320,7 +332,7 @@ export class QueueworkerService
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case dto.DELETE_EVENT: {
|
case dto.DELETE_EVENT: {
|
||||||
await this.handleMessageFanout(message, 'delete');
|
await this.handleDeleteEvent(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case dto.PRIMARY_EMAIL_EVENT:
|
case dto.PRIMARY_EMAIL_EVENT:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче