[messaging] fix participant handles with trailing spaces (#4457)
This commit is contained in:
@ -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([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -162,7 +162,7 @@ export class FetchMessagesByBatchesService {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
role,
|
role,
|
||||||
handle: address?.toLowerCase() || '',
|
handle: address ? this.removeSpacesAndLowerCase(address) : '',
|
||||||
displayName: name || '',
|
displayName: name || '',
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -171,6 +171,10 @@ export class FetchMessagesByBatchesService {
|
|||||||
return participants.flat();
|
return participants.flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private removeSpacesAndLowerCase(email: string): string {
|
||||||
|
return email.replace(/\s/g, '').toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
async formatBatchResponsesAsGmailMessages(
|
async formatBatchResponsesAsGmailMessages(
|
||||||
batchResponses: AxiosResponse<any, any>[],
|
batchResponses: AxiosResponse<any, any>[],
|
||||||
): Promise<{ messages: GmailMessage[]; errors: any[] }> {
|
): Promise<{ messages: GmailMessage[]; errors: any[] }> {
|
||||||
|
|||||||
Reference in New Issue
Block a user