@@ -3,6 +3,7 @@ const pkg = require("../package.json");
33const expect = chai . expect ;
44const initializationParams = require ( "./data" ) . initializationParams
55import ImageKit from "../index" ;
6+ import { encodeStringIfRequired , getSignature } from "../libs/url/builder" ;
67var imagekit = new ImageKit ( initializationParams ) ;
78
89describe ( "URL generation" , function ( ) {
@@ -59,42 +60,82 @@ describe("URL generation", function () {
5960 expect ( url ) . includes ( `ik-s=` ) ;
6061 } ) ;
6162
62- it ( 'Signed URL with é in filename' , function ( ) {
63- const url = imagekit . url ( {
64- path : "/test_é_path_alt.jpg" ,
65- signed : true ,
66- } ) ;
67- expect ( url ) . equal ( `https://ik.imagekit.io/test_url_endpoint/test_é_path_alt.jpg?ik-s=09a329f06a5106a8b9c43de8fb6a64948fff7c59` ) ;
63+ it ( "Signed URL with é in filename" , function ( ) {
64+ const encodedUrl = encodeStringIfRequired ( "https://ik.imagekit.io/test_url_endpoint/test_é_path_alt.jpg" ) ;
65+ expect ( encodedUrl ) . equal ( "https://ik.imagekit.io/test_url_endpoint/test_%C3%A9_path_alt.jpg" ) ;
66+ const signature = getSignature ( {
67+ privateKey : "test_private_key" ,
68+ url : encodedUrl ,
69+ urlEndpoint : "https://ik.imagekit.io/test_url_endpoint" ,
70+ expiryTimestamp : "9999999999" ,
71+ } ) ;
72+ const url = imagekit . url ( {
73+ path : "/test_é_path_alt.jpg" ,
74+ signed : true ,
75+ } ) ;
76+ expect ( url ) . equal ( `https://ik.imagekit.io/test_url_endpoint/test_é_path_alt.jpg?ik-s=09a329f06a5106a8b9c43de8fb6a64948fff7c59` ) ;
77+ expect ( url ) . includes ( `ik-s=${ signature } ` ) ;
6878 } ) ;
6979
70- it ( 'Signed URL with é in filename and path' , function ( ) {
71- const url = imagekit . url ( {
72- path : "/aéb/test_é_path_alt.jpg" ,
73- signed : true ,
74- } ) ;
75- expect ( url ) . equal ( `https://ik.imagekit.io/test_url_endpoint/aéb/test_é_path_alt.jpg?ik-s=fca91582138ac65694425d52f0710b7ae2c3d7cf` ) ;
80+ it ( "Signed URL with é in filename and path" , function ( ) {
81+ const encodedUrl = encodeStringIfRequired ( "https://ik.imagekit.io/test_url_endpoint/aéb/test_é_path_alt.jpg" ) ;
82+ expect ( encodedUrl ) . equal ( "https://ik.imagekit.io/test_url_endpoint/a%C3%A9b/test_%C3%A9_path_alt.jpg" ) ;
83+ const signature = getSignature ( {
84+ privateKey : "test_private_key" ,
85+ url : encodedUrl ,
86+ urlEndpoint : "https://ik.imagekit.io/test_url_endpoint" ,
87+ expiryTimestamp : "9999999999" ,
88+ } ) ;
89+ const url = imagekit . url ( {
90+ path : "/aéb/test_é_path_alt.jpg" ,
91+ signed : true ,
92+ } ) ;
93+ expect ( url ) . equal ( `https://ik.imagekit.io/test_url_endpoint/aéb/test_é_path_alt.jpg?ik-s=fca91582138ac65694425d52f0710b7ae2c3d7cf` ) ;
94+ expect ( url ) . includes ( `ik-s=${ signature } ` ) ;
7695 } ) ;
7796
78- it ( 'Signed URL with é in filename, path and transformation as path' , function ( ) {
79- const url = imagekit . url ( {
80- path : "/aéb/test_é_path_alt.jpg" ,
81- signed : true ,
82- transformation : [ { raw : "l-text,i-Imagekité,fs-50,l-end" } ] ,
83- transformationPosition : "path"
84- } ) ;
85- console . log ( { url} )
86- expect ( url ) . equal ( `https://ik.imagekit.io/test_url_endpoint/tr:l-text,i-Imagekité,fs-50,l-end/aéb/test_é_path_alt.jpg?ik-s=38539311889a0721b46ebe30b5f297773d01d960` ) ;
97+ it ( "Signed URL with é in filename, path and transformation as path" , function ( ) {
98+ const encodedUrl = encodeStringIfRequired ( "https://ik.imagekit.io/test_url_endpoint/tr:l-text,i-Imagekité,fs-50,l-end/aéb/test_é_path_alt.jpg" ) ;
99+ expect ( encodedUrl ) . equal ( "https://ik.imagekit.io/test_url_endpoint/tr:l-text,i-Imagekit%C3%A9,fs-50,l-end/a%C3%A9b/test_%C3%A9_path_alt.jpg" ) ;
100+ const signature = getSignature ( {
101+ privateKey : "test_private_key" ,
102+ url : encodedUrl ,
103+ urlEndpoint : "https://ik.imagekit.io/test_url_endpoint" ,
104+ expiryTimestamp : "9999999999" ,
105+ } ) ;
106+
107+ const url = imagekit . url ( {
108+ path : "/aéb/test_é_path_alt.jpg" ,
109+ signed : true ,
110+ transformation : [ { raw : "l-text,i-Imagekité,fs-50,l-end" } ] ,
111+ transformationPosition : "path" ,
112+ } ) ;
113+ console . log ( { url, signature } ) ;
114+ expect ( url ) . equal (
115+ `https://ik.imagekit.io/test_url_endpoint/tr:l-text,i-Imagekité,fs-50,l-end/aéb/test_é_path_alt.jpg?ik-s=d7f5aec0b7a766556dfc280bdf2e3466877d025f`
116+ ) ;
117+ expect ( url ) . includes ( `ik-s=${ signature } ` ) ;
87118 } ) ;
88119
89- it ( 'Signed URL with é in filename, path and transformation as query' , function ( ) {
90- const url = imagekit . url ( {
91- path : "/aéb/test_é_path_alt.jpg" ,
92- signed : true ,
93- transformation : [ { raw : "l-text,i-Imagekité,fs-50,l-end" } ] ,
94- transformationPosition : "query"
95- } ) ;
96- console . log ( { url} )
97- expect ( url ) . equal ( `https://ik.imagekit.io/test_url_endpoint/aéb/test_é_path_alt.jpg?tr=l-text%2Ci-Imagekit%C3%A9%2Cfs-50%2Cl-end&ik-s=0b0107144b34e3b33264c0cec1d29ec98d46cbbb` ) ;
120+ it ( "Signed URL with é in filename, path and transformation as query" , function ( ) {
121+ const encodedUrl = encodeStringIfRequired ( "https://ik.imagekit.io/test_url_endpoint/aéb/test_é_path_alt.jpg?tr=l-text%2Ci-Imagekité%2Cfs-50%2Cl-end" ) ;
122+ expect ( encodedUrl ) . equal ( "https://ik.imagekit.io/test_url_endpoint/a%C3%A9b/test_%C3%A9_path_alt.jpg?tr=l-text%2Ci-Imagekit%C3%A9%2Cfs-50%2Cl-end" ) ;
123+ const signature = getSignature ( {
124+ privateKey : "test_private_key" ,
125+ url : encodedUrl ,
126+ urlEndpoint : "https://ik.imagekit.io/test_url_endpoint" ,
127+ expiryTimestamp : "9999999999" ,
128+ } ) ;
129+ const url = imagekit . url ( {
130+ path : "/aéb/test_é_path_alt.jpg" ,
131+ signed : true ,
132+ transformation : [ { raw : "l-text,i-Imagekité,fs-50,l-end" } ] ,
133+ transformationPosition : "query" ,
134+ } ) ;
135+ expect ( url ) . equal (
136+ `https://ik.imagekit.io/test_url_endpoint/aéb/test_é_path_alt.jpg?tr=l-text%2Ci-Imagekit%C3%A9%2Cfs-50%2Cl-end&ik-s=0b0107144b34e3b33264c0cec1d29ec98d46cbbb`
137+ ) ;
138+ expect ( url ) . includes ( `ik-s=${ signature } ` ) ;
98139 } ) ;
99140
100141
0 commit comments