Skip to content

Commit b9a52ea

Browse files
ANKUR DWIVEDIANKUR DWIVEDI
authored andcommitted
added test cases
1 parent 8b2813a commit b9a52ea

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/url-generation.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,76 @@ describe("URL generation", function () {
334334
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:di-test_path.jpg/test_path1.jpg`);
335335
});
336336

337+
it("Signed URL with ' in filename", function () {
338+
const testURL = "https://ik.imagekit.io/test_url_endpoint/test_'_path_alt.jpg";
339+
const signature = getSignature({
340+
privateKey: "test_private_key",
341+
url: testURL,
342+
urlEndpoint: "https://ik.imagekit.io/test_url_endpoint",
343+
expiryTimestamp: "9999999999",
344+
});
345+
const url = imagekit.url({
346+
path: "/test_'_path_alt.jpg",
347+
signed: true,
348+
});
349+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/test_'_path_alt.jpg?ik-s=${signature}`);
350+
});
351+
352+
it("Signed URL with ' in filename and path", function () {
353+
const testURL = "https://ik.imagekit.io/test_url_endpoint/a'b/test_'_path_alt.jpg";
354+
const signature = getSignature({
355+
privateKey: "test_private_key",
356+
url: testURL,
357+
urlEndpoint: "https://ik.imagekit.io/test_url_endpoint",
358+
expiryTimestamp: "9999999999",
359+
});
360+
const url = imagekit.url({
361+
path: "/a'b/test_'_path_alt.jpg",
362+
signed: true,
363+
});
364+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/a'b/test_'_path_alt.jpg?ik-s=${signature}`);
365+
});
366+
367+
it("Signed URL with ' in filename, path and transformation as path", function () {
368+
const testURL = "https://ik.imagekit.io/test_url_endpoint/tr:l-text,i-Imagekit',fs-50,l-end/a'b/test_'_path_alt.jpg";
369+
const signature = getSignature({
370+
privateKey: "test_private_key",
371+
url: testURL,
372+
urlEndpoint: "https://ik.imagekit.io/test_url_endpoint",
373+
expiryTimestamp: "9999999999",
374+
});
375+
376+
const url = imagekit.url({
377+
path: "/a'b/test_'_path_alt.jpg",
378+
signed: true,
379+
transformation: [{ raw: "l-text,i-Imagekit',fs-50,l-end" }],
380+
transformationPosition: "path",
381+
});
382+
expect(url).equal(
383+
`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}`
384+
);
385+
});
386+
387+
it("Signed URL with ' in filename, path and transformation as query", function () {
388+
const testURL = "https://ik.imagekit.io/test_url_endpoint/a'b/test_'_path_alt.jpg?tr=l-text%2Ci-Imagekit%27%2Cfs-50%2Cl-end";
389+
const signature = getSignature({
390+
privateKey: "test_private_key",
391+
url: testURL,
392+
urlEndpoint: "https://ik.imagekit.io/test_url_endpoint",
393+
expiryTimestamp: "9999999999",
394+
});
395+
const url = imagekit.url({
396+
path: "/a'b/test_'_path_alt.jpg",
397+
signed: true,
398+
transformation: [{ raw: "l-text,i-Imagekit',fs-50,l-end" }],
399+
transformationPosition: "query",
400+
});
401+
expect(url).equal(
402+
`https://ik.imagekit.io/test_url_endpoint/a'b/test_'_path_alt.jpg?tr=l-text%2Ci-Imagekit%27%2Cfs-50%2Cl-end&ik-s=${signature}`
403+
);
404+
});
405+
406+
337407
it('All combined', function () {
338408
const url = imagekit.url({
339409
path: "/test_path.jpg",

0 commit comments

Comments
 (0)