Skip to content

Commit f261504

Browse files
committed
Increased coverage and fixed comment in UrlOptions
1 parent 5675085 commit f261504

File tree

5 files changed

+70
-5
lines changed

5 files changed

+70
-5
lines changed

src/interfaces/UrlOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ export interface UrlOptionsPath extends UrlOptionsBase {
6060
/**
6161
* Options for generating an URL
6262
*
63-
* @link https://github.com/imagekit-developer/imagekit-nodejs#url-generation
63+
* @link https://github.com/imagekit-developer/imagekit-javascript#url-generation
6464
*/
6565
export type UrlOptions = UrlOptionsSrc | UrlOptionsPath;

src/utils/transformation.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ export default {
1818
validParameters: (options: ImageKitOptions) => {
1919
return VALID_TRANSFORMATION_POSITIONS.indexOf(options.transformationPosition) != -1;
2020
},
21-
getSupportedTransforms: function () {
22-
return supportedTransforms;
23-
},
2421
getTransformKey: function (transform: string) {
2522
if (!transform) { return ""; }
2623

test/initialization.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ import ImageKit from "../src/index";
77
describe("Initialization checks", function () {
88
var imagekit = new ImageKit(initializationParams);
99

10-
it('should throw error', function () {
10+
it('should throw error: options - empty object', function () {
1111
try {
1212
new ImageKit({});
1313
} catch(err) {
1414
expect(err.message).to.be.equal('Missing urlEndpoint during SDK initialization');
1515
}
1616
});
1717

18+
it('should throw error: options - undefined', function () {
19+
try {
20+
new ImageKit();
21+
} catch(err) {
22+
expect(err.message).to.be.equal('Missing urlEndpoint during SDK initialization');
23+
}
24+
});
25+
1826
it('Pass private Key', function () {
1927
try {
2028
new ImageKit({
@@ -52,4 +60,12 @@ describe("Initialization checks", function () {
5260
expect(imagekit.upload).to.exist.and.to.be.a('function');
5361

5462
});
63+
64+
it('should throw error: invalid transformationPosition', function () {
65+
try {
66+
new ImageKit({...initializationParams, transformationPosition: "test"});
67+
} catch(err) {
68+
expect(err.message).to.be.equal('Invalid transformationPosition parameter');
69+
}
70+
});
5571
});

test/upload.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ describe("File upload", function () {
9090
server.restore();
9191
});
9292

93+
it('Invalid Options', function () {
94+
95+
var callback = sinon.spy();
96+
97+
imagekit.upload(undefined, callback);
98+
expect(server.requests.length).to.be.equal(0);
99+
expect(callback.calledOnce).to.be.true;
100+
sinon.assert.calledWith(callback, { help: "", message: "Invalid uploadOptions parameter" }, null);
101+
});
102+
93103
it('Missing fileName', function () {
94104
const fileOptions = {
95105
file: "https://ik.imagekit.io/remote-url.jpg"

test/url-generation.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ describe("URL generation", function () {
1515
expect(url).equal("");
1616
});
1717

18+
it('invalid src url', function () {
19+
const url = imagekit.url({ src: "/" });
20+
21+
expect(url).equal("");
22+
});
23+
1824
it('no transformation path', function () {
1925
const url = imagekit.url({
2026
path: "/test_path.jpg"
@@ -214,6 +220,42 @@ describe("URL generation", function () {
214220
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400,b-20_FF0000/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
215221
});
216222

223+
it('transformation with empty key and empty value', function () {
224+
const url = imagekit.url({
225+
path: "/test_path.jpg",
226+
transformation: [{
227+
"": ""
228+
}]
229+
})
230+
231+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:-/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
232+
});
233+
234+
/**
235+
* Provided to provide support to a new transform without sdk update
236+
*/
237+
it('transformation with undefined transform', function () {
238+
const url = imagekit.url({
239+
path: "/test_path.jpg",
240+
transformation: [{
241+
"undefined-transform": "true"
242+
}]
243+
})
244+
245+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:undefined-transform-true/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
246+
});
247+
248+
it('transformation with empty key and value', function () {
249+
const url = imagekit.url({
250+
path: "/test_path.jpg",
251+
transformation: [{
252+
effectContrast: "-"
253+
}]
254+
})
255+
256+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:e-contrast/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
257+
});
258+
217259
it('All combined', function () {
218260
const url = imagekit.url({
219261
path: "/test_path.jpg",

0 commit comments

Comments
 (0)