@@ -10,6 +10,7 @@ describe('EmailLinkBuilder', () => {
1010 initiatePasswordResetUrl : 'http://localhost:3030/reset_password' ,
1111 privacyUrl : 'http://localhost:3030/privacy' ,
1212 supportUrl : 'http://localhost:3030/support' ,
13+ accountSettingsUrl : 'http://localhost:3030/settings' ,
1314 } ;
1415
1516 let linkBuilder : EmailLinkBuilder ;
@@ -18,108 +19,11 @@ describe('EmailLinkBuilder', () => {
1819 linkBuilder = new EmailLinkBuilder ( mockConfig ) ;
1920 } ) ;
2021
21- describe ( 'urls getter' , ( ) => {
22- it ( 'should return configured URLs' , ( ) => {
23- const urls = linkBuilder . urls ;
24-
25- expect ( urls . initiatePasswordReset ) . toBe (
26- 'http://localhost:3030/reset_password'
27- ) ;
28- expect ( urls . privacy ) . toBe ( 'http://localhost:3030/privacy' ) ;
29- expect ( urls . support ) . toBe ( 'http://localhost:3030/support' ) ;
30- } ) ;
31- } ) ;
32-
33- describe ( 'getCampaign' , ( ) => {
34- it ( 'should return campaign with prefix for valid template' , ( ) => {
35- const templateName = 'recovery' ;
36-
37- const campaign = linkBuilder . getCampaign ( templateName ) ;
38-
39- expect ( campaign ) . toBe ( 'fx-forgot-password' ) ;
40- } ) ;
41-
42- it ( 'should return empty string for unknown template' , ( ) => {
43- const templateName = 'unknownTemplate' ;
44-
45- const campaign = linkBuilder . getCampaign ( templateName ) ;
46-
47- expect ( campaign ) . toBe ( '' ) ;
48- } ) ;
49- } ) ;
50-
51- describe ( 'getContent' , ( ) => {
52- it ( 'should return content for valid template' , ( ) => {
53- const templateName = 'recovery' ;
54-
55- const content = linkBuilder . getContent ( templateName ) ;
56-
57- expect ( content ) . toBe ( 'reset-password' ) ;
58- } ) ;
59-
60- it ( 'should return empty string for unknown template' , ( ) => {
61- const templateName = 'unknownTemplate' ;
62-
63- const content = linkBuilder . getContent ( templateName ) ;
64-
65- expect ( content ) . toBe ( '' ) ;
66- } ) ;
67- } ) ;
68-
69- describe ( 'addUTMParams' , ( ) => {
70- it ( 'should add UTM parameters when metrics enabled' , ( ) => {
71- const link = new URL ( 'http://localhost:3030/some-page' ) ;
72- const templateName = 'recovery' ;
73-
74- linkBuilder . addUTMParams ( link , templateName ) ;
75-
76- expect ( link . searchParams . get ( 'utm_medium' ) ) . toBe ( 'email' ) ;
77- expect ( link . searchParams . get ( 'utm_campaign' ) ) . toBe ( 'fx-forgot-password' ) ;
78- expect ( link . searchParams . get ( 'utm_content' ) ) . toBe ( 'fx-reset-password' ) ;
79- } ) ;
80-
81- it ( 'should use custom content when provided' , ( ) => {
82- const link = new URL ( 'http://localhost:3030/some-page' ) ;
83- const templateName = 'recovery' ;
84- const customContent = 'custom-content' ;
85-
86- linkBuilder . addUTMParams ( link , templateName , customContent ) ;
87-
88- expect ( link . searchParams . get ( 'utm_content' ) ) . toBe ( 'fx-custom-content' ) ;
89- } ) ;
90-
91- it ( 'should not add UTM parameters when metrics disabled' , ( ) => {
92- const disabledLinkBuilder = new EmailLinkBuilder ( {
93- ...mockConfig ,
94- metricsEnabled : false ,
95- } ) ;
96- const link = new URL ( 'http://localhost:3030/some-page' ) ;
97- const templateName = 'recovery' ;
98-
99- disabledLinkBuilder . addUTMParams ( link , templateName ) ;
100-
101- expect ( link . searchParams . get ( 'utm_medium' ) ) . toBeNull ( ) ;
102- expect ( link . searchParams . get ( 'utm_campaign' ) ) . toBeNull ( ) ;
103- expect ( link . searchParams . get ( 'utm_content' ) ) . toBeNull ( ) ;
104- } ) ;
105-
106- it ( 'should not override existing utm_campaign' , ( ) => {
107- const link = new URL (
108- 'http://localhost:3030/some-page?utm_campaign=existing'
109- ) ;
110- const templateName = 'recovery' ;
111-
112- linkBuilder . addUTMParams ( link , templateName ) ;
113-
114- expect ( link . searchParams . get ( 'utm_campaign' ) ) . toBe ( 'existing' ) ;
115- } ) ;
116- } ) ;
117-
11822 describe ( 'buildCommonLinks' , ( ) => {
11923 it ( 'should build privacy and support links with UTM params' , ( ) => {
12024 const templateName = 'recovery' ;
12125
122- const links = linkBuilder . buildCommonLinks ( templateName ) ;
26+ const links = linkBuilder . buildCommonLinks ( templateName , true ) ;
12327
12428 expect ( links . privacyUrl ) . toContain ( 'http://localhost:3030/privacy' ) ;
12529 expect ( links . privacyUrl ) . toContain ( 'utm_medium=email' ) ;
@@ -135,40 +39,52 @@ describe('EmailLinkBuilder', () => {
13539
13640 describe ( 'buildLinkWithQueryParamsAndUTM' , ( ) => {
13741 it ( 'should add query params and UTM params to link' , ( ) => {
138- const link = new URL ( 'http://localhost:3030/some-page' ) ;
139- const templateName = 'recovery' ;
140- const queryParams = {
141- uid : '12345' ,
142- token : 'abc123' ,
143- 144- } ;
145-
146- linkBuilder . buildLinkWithQueryParamsAndUTM (
147- link ,
148- templateName ,
149- queryParams
42+ const link = linkBuilder . buildLinkWithQueryParamsAndUTM (
43+ 'http://localhost:3030/some-page' ,
44+ 'recovery' ,
45+ {
46+ uid : '12345' ,
47+ token : 'abc123' ,
48+ 49+ } ,
50+ true
15051 ) ;
15152
152- expect ( link . searchParams . get ( 'uid' ) ) . toBe ( '12345' ) ;
153- expect ( link . searchParams . get ( 'token' ) ) . toBe ( 'abc123' ) ;
154- expect ( link . searchParams . get ( 'email' ) ) . toBe ( '[email protected] ' ) ; 155- expect ( link . searchParams . get ( 'utm_medium' ) ) . toBe ( 'email' ) ;
156- expect ( link . searchParams . get ( 'utm_campaign' ) ) . toBe ( 'fx-forgot-password' ) ;
53+ const url = new URL ( link ) ;
54+ expect ( url . searchParams . get ( 'uid' ) ) . toBe ( '12345' ) ;
55+ expect ( url . searchParams . get ( 'token' ) ) . toBe ( 'abc123' ) ;
56+ expect ( url . searchParams . get ( 'email' ) ) . toBe ( '[email protected] ' ) ; 57+ expect ( url . searchParams . get ( 'utm_medium' ) ) . toBe ( 'email' ) ;
58+ expect ( url . searchParams . get ( 'utm_campaign' ) ) . toBe ( 'fx-forgot-password' ) ;
15759 } ) ;
15860
15961 it ( 'should handle empty query params' , ( ) => {
160- const link = new URL ( 'http://localhost:3030/some-page' ) ;
16162 const templateName = 'recovery' ;
16263 const queryParams = { } ;
16364
164- linkBuilder . buildLinkWithQueryParamsAndUTM (
165- link ,
65+ const link = linkBuilder . buildLinkWithQueryParamsAndUTM (
66+ 'http://localhost:3030/some-page' ,
16667 templateName ,
167- queryParams
68+ queryParams ,
69+ true
16870 ) ;
16971
170- expect ( link . searchParams . get ( 'utm_medium' ) ) . toBe ( 'email' ) ;
171- expect ( link . searchParams . get ( 'utm_campaign' ) ) . toBe ( 'fx-forgot-password' ) ;
72+ const url = new URL ( link ) ;
73+ expect ( url . searchParams . get ( 'utm_medium' ) ) . toBe ( 'email' ) ;
74+ expect ( url . searchParams . get ( 'utm_campaign' ) ) . toBe ( 'fx-forgot-password' ) ;
75+ } ) ;
76+
77+ it ( 'should respect metricsEnabled flag' , ( ) => {
78+ const link = linkBuilder . buildLinkWithQueryParamsAndUTM (
79+ 'http://localhost:3030/some-page' ,
80+ 'recovery' ,
81+ { } ,
82+ false
83+ ) ;
84+
85+ const url = new URL ( link ) ;
86+ expect ( url . searchParams . get ( 'utm_medium' ) ) . toBeNull ( ) ;
87+ expect ( url . searchParams . get ( 'utm_campaign' ) ) . toBeNull ( ) ;
17288 } ) ;
17389 } ) ;
17490
@@ -179,7 +95,11 @@ describe('EmailLinkBuilder', () => {
1799518096 } ;
18197
182- const link = linkBuilder . buildPasswordChangeRequiredLink ( opts ) ;
98+ const link = linkBuilder . buildPasswordChangeRequiredLink (
99+ opts . url ,
100+ opts . email ,
101+ true
102+ ) ;
183103
184104 expect ( link ) . toContain ( 'http://localhost:3030/reset_password' ) ;
185105 expect ( link ) . toContain ( 'email=test%40example.com' ) ;
0 commit comments