@@ -3,6 +3,7 @@ const pkg = require("../package.json");
3
3
const expect = chai . expect ;
4
4
const initializationParams = require ( "./data" ) . initializationParams
5
5
import ImageKit from "../index" ;
6
+ import { encodeStringIfRequired , getSignature } from "../libs/url/builder" ;
6
7
var imagekit = new ImageKit ( initializationParams ) ;
7
8
8
9
describe ( "URL generation" , function ( ) {
@@ -59,6 +60,84 @@ describe("URL generation", function () {
59
60
expect ( url ) . includes ( `ik-s=` ) ;
60
61
} ) ;
61
62
63
+ it ( "Signed URL with é in filename" , function ( ) {
64
+ const testURL = "https://ik.imagekit.io/test_url_endpoint/test_é_path_alt.jpg" ;
65
+ const encodedUrl = encodeStringIfRequired ( testURL ) ;
66
+ expect ( encodedUrl ) . equal ( "https://ik.imagekit.io/test_url_endpoint/test_%C3%A9_path_alt.jpg" ) ;
67
+ const signature = getSignature ( {
68
+ privateKey : "test_private_key" ,
69
+ url : testURL ,
70
+ urlEndpoint : "https://ik.imagekit.io/test_url_endpoint" ,
71
+ expiryTimestamp : "9999999999" ,
72
+ } ) ;
73
+ const url = imagekit . url ( {
74
+ path : "/test_é_path_alt.jpg" ,
75
+ signed : true ,
76
+ } ) ;
77
+ expect ( url ) . equal ( `https://ik.imagekit.io/test_url_endpoint/test_é_path_alt.jpg?ik-s=${ signature } ` ) ;
78
+ } ) ;
79
+
80
+ it ( "Signed URL with é in filename and path" , function ( ) {
81
+ const testURL = "https://ik.imagekit.io/test_url_endpoint/aéb/test_é_path_alt.jpg" ;
82
+ const encodedUrl = encodeStringIfRequired ( testURL ) ;
83
+ expect ( encodedUrl ) . equal ( "https://ik.imagekit.io/test_url_endpoint/a%C3%A9b/test_%C3%A9_path_alt.jpg" ) ;
84
+ const signature = getSignature ( {
85
+ privateKey : "test_private_key" ,
86
+ url : testURL ,
87
+ urlEndpoint : "https://ik.imagekit.io/test_url_endpoint" ,
88
+ expiryTimestamp : "9999999999" ,
89
+ } ) ;
90
+ const url = imagekit . url ( {
91
+ path : "/aéb/test_é_path_alt.jpg" ,
92
+ signed : true ,
93
+ } ) ;
94
+ expect ( url ) . equal ( `https://ik.imagekit.io/test_url_endpoint/aéb/test_é_path_alt.jpg?ik-s=${ signature } ` ) ;
95
+ } ) ;
96
+
97
+ it ( "Signed URL with é in filename, path and transformation as path" , function ( ) {
98
+ const testURL = "https://ik.imagekit.io/test_url_endpoint/tr:l-text,i-Imagekité,fs-50,l-end/aéb/test_é_path_alt.jpg" ;
99
+ const encodedUrl = encodeStringIfRequired ( testURL ) ;
100
+ 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" ) ;
101
+ const signature = getSignature ( {
102
+ privateKey : "test_private_key" ,
103
+ url : testURL ,
104
+ urlEndpoint : "https://ik.imagekit.io/test_url_endpoint" ,
105
+ expiryTimestamp : "9999999999" ,
106
+ } ) ;
107
+
108
+ const url = imagekit . url ( {
109
+ path : "/aéb/test_é_path_alt.jpg" ,
110
+ signed : true ,
111
+ transformation : [ { raw : "l-text,i-Imagekité,fs-50,l-end" } ] ,
112
+ transformationPosition : "path" ,
113
+ } ) ;
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=${ signature } `
116
+ ) ;
117
+ } ) ;
118
+
119
+ it ( "Signed URL with é in filename, path and transformation as query" , function ( ) {
120
+ const testURL = "https://ik.imagekit.io/test_url_endpoint/aéb/test_é_path_alt.jpg?tr=l-text%2Ci-Imagekit%C3%A9%2Cfs-50%2Cl-end" ;
121
+ const encodedUrl = encodeStringIfRequired ( testURL ) ;
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 : testURL ,
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=${ signature } `
137
+ ) ;
138
+ } ) ;
139
+
140
+
62
141
it ( 'should generate the correct url with path param' , function ( ) {
63
142
const url = imagekit . url ( {
64
143
path : "/test_path.jpg" ,
0 commit comments