Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / shared / test / mail / trackers.spec.ts
blobc4aaf886b7805f6f6fcd03531bd409e95968c4a4
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 }[] = [
6     {
7         originalLink: 'https://support.apple.com/fr-fr/HTXXXXXX?cid=email_receipt_itunes_article_HTXXXXXX',
8         cleanedLink: 'https://support.apple.com/fr-fr/HTXXXXXX',
9     },
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 = {
19                 originalURL,
20                 cleanedURL,
21                 removed: [{ key: 'utm_source', value: 'tracker' }],
22             };
24             const result = getUTMTrackersFromURL(originalURL);
26             expect(result!.url).toEqual(cleanedURL);
27             expect(result!.utmTracker).toEqual(expectedUTMTracker);
28         });
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);
37         });
39         it('should clean all links as expected', () => {
40             links.map((link) => {
41                 const result = getUTMTrackersFromURL(link.originalLink);
42                 expect(result!.url).toEqual(link.cleanedLink);
43             });
44         });
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(
48                 undefined
49             );
50         });
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);
59         });
60     });
61 });