Skip to content

Commit f2e4df9

Browse files
committed
threshold test coverage 95%
1 parent 4a69f20 commit f2e4df9

File tree

7 files changed

+53
-28
lines changed

7 files changed

+53
-28
lines changed

.nycrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"check-coverage": true,
3+
"lines": 95
4+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ The `.url()` method accepts the following parameters
9797
| path | Conditional. This is the path at which the image exists. For example, `/path/to/image.jpg`. Either the `path` or `src` parameter need to be specified for URL generation. |
9898
| src | Conditional. This is the complete URL of an image already mapped to ImageKit. For example, `https://ik.imagekit.io/your_imagekit_id/endpoint/path/to/image.jpg`. Either the `path` or `src` parameter need to be specified for URL generation. |
9999
| transformation | Optional. An array of objects specifying the transformation to be applied in the URL. The transformation name and the value should be specified as a key-value pair in the object. Different steps of a [chained transformation](https://docs.imagekit.io/features/image-transformations/chained-transformations) can be specified as different objects of the array. The complete list of supported transformations in the SDK and some examples of using them are given later. If you use a transformation name that is not specified in the SDK, it gets applied as it is in the URL. |
100-
| transformationPostion | Optional. Default value is `path` that places the transformation string as a path parameter in the URL. Can also be specified as `query` which adds the transformation string as the query parameter `tr` in the URL. If you use `src` parameter to create the URL, then the transformation string is always added as a query parameter. |
100+
| transformationPosition | Optional. Default value is `path` that places the transformation string as a path parameter in the URL. Can also be specified as `query` which adds the transformation string as the query parameter `tr` in the URL. If you use `src` parameter to create the URL, then the transformation string is always added as a query parameter. |
101101
| queryParameters | Optional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and not necessarily related to ImageKit. Especially useful, if you want to add some versioning parameter to your URLs. |
102102
| signed | Optional. Boolean. Default is `false`. If set to `true`, the SDK generates a signed image URL adding the image signature to the image URL. If you are creating URL using `src` parameter instead of `path` then do correct `urlEndpoint` for this to work. Otherwise returned URL will have wrong signature |
103103
| expireSeconds | Optional. Integer. Meant to be used along with the `signed` parameter to specify the time in seconds from now when the URL should expire. If specified, the URL contains the expiry timestamp in the URL and the image signature is modified accordingly. |

libs/url/builder.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function constructTransformationString(transformation) {
132132
} else {
133133
var value = transformation[i][key];
134134
if(transformKey === "oi" || transformKey === "di") {
135-
value = removeTrailingSlash(removeLeadingSlash(value));
135+
value = urlFormatter.removeTrailingSlash(urlFormatter.removeLeadingSlash(value));
136136
value = value.replace(/\//g,"@@");
137137
}
138138
parsedTransformStep.push([transformKey, value].join(transformationUtils.getTransformKeyValueDelimiter()));
@@ -145,20 +145,6 @@ function constructTransformationString(transformation) {
145145
return parsedTransforms.join(transformationUtils.getChainTransformDelimiter());
146146
}
147147

148-
function removeTrailingSlash(str) {
149-
if (typeof str == "string" && str[str.length - 1] == "/") {
150-
str = str.substring(0, str.length - 1);
151-
}
152-
return str;
153-
}
154-
155-
function removeLeadingSlash(str) {
156-
if (typeof str == "string" && str[0] == "/") {
157-
str = str.slice(1);
158-
}
159-
return str;
160-
}
161-
162148
function getSignatureTimestamp(seconds) {
163149
if(!seconds) return DEFAULT_TIMESTAMP;
164150

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "imagekit",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"description": "Offical NodeJS SDK for ImageKit.io integration",
55
"main": "index.js",
66
"scripts": {
77
"lint": "./node_modules/eslint/bin/eslint.js tests/ utils/phash.js",
88
"lint:fix": "./node_modules/eslint/bin/eslint.js --fix tests/ utils/phash.js",
9-
"test": "export NODE_ENV=test; nyc ./node_modules/mocha/bin/mocha --coverage --exit -t 40000 tests/*.js;ex=$?;unset NODE_ENV; exit $ex;",
9+
"test": "export NODE_ENV=test; nyc ./node_modules/mocha/bin/mocha --exit -t 40000 tests/*.js;ex=$?;unset NODE_ENV; exit $ex;",
1010
"report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
1111
},
1212
"author": "ImageKit Developer <[email protected]>",

tests/upload.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,24 @@ describe("File upload", function () {
189189
},10);
190190
});
191191

192+
it('Success using promise', function (done) {
193+
const fileOptions = {
194+
fileName: "test_file_name",
195+
file: "test_file_content"
196+
};
197+
198+
const scope = nock('https://api.imagekit.io')
199+
.post('/v1/files/upload')
200+
.basicAuth({ user: initializationParams.privateKey, pass: '' })
201+
.reply(200, uploadSuccessResponseObj)
202+
203+
imagekit.upload(fileOptions)
204+
.then((response, error) => {
205+
expect(response).to.been.deep.equal(uploadSuccessResponseObj)
206+
done();
207+
});
208+
});
209+
192210
it('Network error', function (done) {
193211
const fileOptions = {
194212
fileName: "test_file_name",
@@ -237,4 +255,29 @@ describe("File upload", function () {
237255
done();
238256
},10);
239257
});
258+
259+
it('Server side error promise', function (done) {
260+
const fileOptions = {
261+
fileName: "test_file_name",
262+
file: "test_file_content"
263+
};
264+
265+
var error = {
266+
help: "For support kindly contact us at [email protected] .",
267+
message: "Your account cannot be authenticated."
268+
};
269+
270+
const scope = nock('https://api.imagekit.io')
271+
.post('/v1/files/upload')
272+
.basicAuth({ user: initializationParams.privateKey, pass: '' })
273+
.reply(403, error)
274+
275+
imagekit.upload(fileOptions)
276+
.then((response, error) => {
277+
})
278+
.catch(error => {
279+
expect(error).to.been.deep.equal(error)
280+
done();
281+
})
282+
});
240283
});

tests/url-generation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe("URL generation", function () {
8787

8888
});
8989

90-
it('should generate the correct url with path param with transformationPostion as query', function () {
90+
it('should generate the correct url with path param with transformationPosition as query', function () {
9191
const url = imagekit.url({
9292
path: "/test_path.jpg",
9393
transformationPosition: "query",
@@ -112,7 +112,7 @@ describe("URL generation", function () {
112112
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg?tr=h-300%2Cw-400`);
113113
});
114114

115-
it('should generate the correct url with transformationPostion as query', function () {
115+
it('should generate the correct url with transformationPosition as query', function () {
116116
const url = imagekit.url({
117117
src: "https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg",
118118
transformationPosition: "query",

utils/urlFormatter.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
module.exports.addLeadingQuestionMark = function(str) {
2-
if(typeof str == "string" && str[0] != "?") {
3-
str = "?" + str;
4-
}
5-
6-
return str;
7-
}
8-
91
module.exports.addLeadingSlash = function(str) {
102
if(typeof str == "string" && str[0] != "/") {
113
str = "/" + str;

0 commit comments

Comments
 (0)