[messaging] fix participant handles with trailing spaces (#4457)

This commit is contained in:
Weiko 2024-03-14 13:46:38 +01:00 committed by GitHub
parent 42e86c7c82
commit 991bb09622
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 58 additions and 1 deletions

View File

@ -0,0 +1,53 @@
import { AddressObject } from 'mailparser';
import { FetchMessagesByBatchesService } from './fetch-messages-by-batches.service';
describe('FetchMessagesByBatchesService', () => {
let service: FetchMessagesByBatchesService;
beforeEach(() => {
service = new FetchMessagesByBatchesService();
});
describe('formatAddressObjectAsParticipants', () => {
it('should format address object as participants', () => {
const addressObject: AddressObject = {
value: [
{ name: 'John Doe', address: 'john.doe @example.com' },
{ name: 'Jane Smith', address: 'jane.smith@example.com ' },
],
html: '',
text: '',
};
const result = service.formatAddressObjectAsParticipants(
addressObject,
'from',
);
expect(result).toEqual([
{
role: 'from',
handle: 'john.doe@example.com',
displayName: 'John Doe',
},
{
role: 'from',
handle: 'jane.smith@example.com',
displayName: 'Jane Smith',
},
]);
});
it('should return an empty array if address object is undefined', () => {
const addressObject = undefined;
const result = service.formatAddressObjectAsParticipants(
addressObject,
'to',
);
expect(result).toEqual([]);
});
});
});

View File

@ -162,7 +162,7 @@ export class FetchMessagesByBatchesService {
return {
role,
handle: address?.toLowerCase() || '',
handle: address ? this.removeSpacesAndLowerCase(address) : '',
displayName: name || '',
};
});
@ -171,6 +171,10 @@ export class FetchMessagesByBatchesService {
return participants.flat();
}
private removeSpacesAndLowerCase(email: string): string {
return email.replace(/\s/g, '').toLowerCase();
}
async formatBatchResponsesAsGmailMessages(
batchResponses: AxiosResponse<any, any>[],
): Promise<{ messages: GmailMessage[]; errors: any[] }> {