11const path = require ( 'path' ) ;
22const mock = require ( 'mock-fs' ) ;
3- const getSDKVersions = require ( '../../../lib/utils/analytics/getSDKVersions' ) ;
43const cloudinary = require ( '../../../cloudinary' ) ;
4+ const assert = require ( "assert" ) ;
55const TEST_CLOUD_NAME = require ( '../../testUtils/testConstants' ) . TEST_CLOUD_NAME ;
66
7- describe ( 'Tests for sdk analytics through image tag ' , function ( ) {
7+ describe ( 'SDK url analytics' , ( ) => {
88 let processVersions = { } ;
99
10- beforeEach ( ( ) => {
10+ before ( ( ) => {
1111 cloudinary . config ( true ) ; // reset
1212
1313 processVersions = process . versions ;
1414 delete process . versions ;
1515
16- let file = path . join ( __dirname , '../../../package.json' ) ;
16+ const file = path . join ( __dirname , '../../../package.json' ) ;
1717
1818 mock ( {
1919 [ file ] : '{"version":"1.24.0"}'
2020 } ) ;
2121 } ) ;
2222
23- afterEach ( function ( ) {
23+ after ( ( ) => {
2424 mock . restore ( ) ;
2525 process . versions = processVersions ;
2626 } ) ;
2727
28- it ( 'Can be turned off via options' , ( ) => {
28+ it ( 'can be turned off via options' , ( ) => {
2929 process . versions = {
3030 node : '12.0.0'
3131 } ;
3232
33- let imgStr = cloudinary . image ( "hello" , {
33+ const imgStr = cloudinary . image ( "hello" , {
3434 format : "png" ,
35- urlAnalytics : false
35+ analytics : false
3636 } ) ;
3737
38- expect ( imgStr ) . not . to . contain ( ` MAlhAM0` ) ;
38+ assert . ok ( ! imgStr . includes ( ' MAlhAM0' ) )
3939 } ) ;
4040
41- it ( 'Defaults to true even if analytics is not passed as an option' , ( ) => {
41+ it ( 'defaults to true even if analytics is not passed as an option' , ( ) => {
4242 process . versions = {
4343 node : '12.0.0'
4444 } ;
4545
46- let imgStr = cloudinary . image ( "hello" , {
46+ const imgStr = cloudinary . image ( "hello" , {
4747 format : "png"
4848 } ) ;
4949
50- expect ( imgStr ) . to . contain ( ` MAlhAM0` ) ;
50+ assert . ok ( imgStr . includes ( ' MAlhAM0' ) )
5151 } ) ;
5252
53- it ( 'Reads from process.versions and package.json (Mocked)' , ( ) => {
53+ it ( 'reads from process.versions and package.json (Mocked)' , ( ) => {
5454 process . versions = {
5555 node : '12.0.0'
5656 } ;
5757
58- let imgStr = cloudinary . image ( "hello" , {
58+ const imgStr = cloudinary . image ( "hello" , {
5959 format : "png" ,
60- urlAnalytics : true
60+ analytics : true
6161 } ) ;
6262
63- expect ( imgStr ) . to . contain ( `src='https://res.cloudinary.com/ ${ TEST_CLOUD_NAME } /image/upload/hello.png ?_a=BAMAlhAM0` ) ;
63+ assert . ok ( imgStr . includes ( ' ?_a=BAMAlhAM0' ) ) ;
6464 } ) ;
6565
66- it ( 'Reads from process.versions and package.json (Mocked) - Responsive' , ( ) => {
66+ it ( 'reads from process.versions and package.json (Mocked) - Responsive' , ( ) => {
6767 process . versions = {
6868 node : '12.0.0'
6969 } ;
7070
71- let imgStr = cloudinary . image ( "hello" , {
71+ const imgStr = cloudinary . image ( "hello" , {
7272 format : "png" ,
7373 responsive : true ,
74- urlAnalytics : true
74+ analytics : true
7575 } ) ;
7676
77- expect ( imgStr ) . to . contain ( `src='https://res.cloudinary.com/ ${ TEST_CLOUD_NAME } /image/upload/hello.png ?_a=BAMAlhAMA` ) ;
77+ assert . ok ( imgStr . includes ( ' ?_a=BAMAlhAMA' ) ) ;
7878 } ) ;
7979
80- it ( 'Reads from tracked analytics configuration' , ( ) => {
80+ it ( 'reads from tracked analytics configuration' , ( ) => {
8181 process . versions = {
8282 node : '12.0.0'
8383 } ;
8484
85- let imgStr = cloudinary . image ( "hello" , {
85+ const imgStr = cloudinary . image ( "hello" , {
86+ format : "png" ,
87+ analytics : true ,
88+ sdk_code : "X" ,
89+ sdk_semver : "7.3.0" ,
90+ tech_version : "3.4.7" ,
91+ product : 'B'
92+ } ) ;
93+
94+ assert . ok ( imgStr . includes ( '?_a=BBXAEzGT0' ) ) ;
95+ } ) ;
96+
97+ it ( 'should still accept analytics param passed as camel case' , ( ) => {
98+ process . versions = {
99+ node : '12.0.0'
100+ } ;
101+
102+ const imgStr = cloudinary . image ( "hello" , {
86103 format : "png" ,
87104 urlAnalytics : true ,
88105 sdkCode : "X" ,
@@ -91,6 +108,36 @@ describe('Tests for sdk analytics through image tag', function () {
91108 product : 'B'
92109 } ) ;
93110
94- expect ( imgStr ) . to . contain ( `src='https://res.cloudinary.com/${ TEST_CLOUD_NAME } /image/upload/hello.png?_a=BBXAEzGT0` ) ;
111+ assert . ok ( imgStr . includes ( '?_a=BBXAEzGT0' ) ) ;
112+ } ) ;
113+
114+ describe ( 'with two different casings' , ( ) => {
115+ it ( 'should treat camel case analytics param as more important than snake case' , ( ) => {
116+ process . versions = {
117+ node : '12.0.0'
118+ } ;
119+
120+ const imgStr1 = cloudinary . image ( "hello" , {
121+ format : "png" ,
122+ urlAnalytics : true ,
123+ analytics : false ,
124+ sdkCode : "X" ,
125+ sdkSemver : "7.3.0" ,
126+ techVersion : "3.4.7" ,
127+ product : 'B'
128+ } ) ;
129+ assert . ok ( imgStr1 . includes ( '?_a=BBXAEzGT0' ) ) ;
130+
131+ const imgStr2 = cloudinary . image ( "hello" , {
132+ format : "png" ,
133+ analytics : true ,
134+ sdkCode : "X" ,
135+ sdkSemver : "7.3.0" ,
136+ techVersion : "3.4.7" ,
137+ tech_version : "1.2.3" ,
138+ product : 'B'
139+ } ) ;
140+ assert . ok ( imgStr2 . includes ( '?_a=BBXAEzGT0' ) ) ;
141+ } ) ;
95142 } ) ;
96143} ) ;
0 commit comments