mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-26 05:24:04 +03:00
[messaging] fix participant handles with trailing spaces (#4457)
This commit is contained in:
parent
42e86c7c82
commit
991bb09622
@ -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 {
|
||||
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[] }> {
|
||||
|
Loading…
Reference in New Issue
Block a user