1 import { getUTMTrackersFromURL } from '@proton/shared/lib/mail/trackers';
2 import type { MessageUTMTracker } from '@proton/shared/lib/models/mailUtmTrackers';
4 // Complete to verify that links are cleaned as expected
5 const links: { originalLink: string; cleanedLink: string }[] = [
7 originalLink: 'https://support.apple.com/fr-fr/HTXXXXXX?cid=email_receipt_itunes_article_HTXXXXXX',
8 cleanedLink: 'https://support.apple.com/fr-fr/HTXXXXXX',
12 describe('trackers', () => {
13 describe('getUTMTrackersFromURL', () => {
14 it('should clean utm trackers', () => {
15 const originalURL = 'https://ads.com?utm_source=tracker';
16 const cleanedURL = 'https://ads.com/';
18 const expectedUTMTracker: MessageUTMTracker = {
21 removed: [{ key: 'utm_source', value: 'tracker' }],
24 const result = getUTMTrackersFromURL(originalURL);
26 expect(result!.url).toEqual(cleanedURL);
27 expect(result!.utmTracker).toEqual(expectedUTMTracker);
30 it('should not clean utm trackers', () => {
31 const originalURL = 'https://ads.com?whatever=something';
33 const result = getUTMTrackersFromURL(originalURL);
35 expect(result!.url).toEqual(originalURL);
36 expect(result!.utmTracker).toEqual(undefined);
39 it('should clean all links as expected', () => {
41 const result = getUTMTrackersFromURL(link.originalLink);
42 expect(result!.url).toEqual(link.cleanedLink);
46 it('should return undefined when it throws or URL is not valid', () => {
47 expect(getUTMTrackersFromURL(`<html>dude <a href="dude sd;lkfjads;lkfj !+@#%$^&*()"<html>`)).toBe(
52 it('should not clean amp links', () => {
53 const originalURL = 'https://something.me/L0/https:%2F%2Fsomething-else.amazonaws.com%randomID';
55 const result = getUTMTrackersFromURL(originalURL);
57 expect(result!.url).toEqual(originalURL);
58 expect(result!.utmTracker).toEqual(undefined);