Skip to content

Commit d8ebf1d

Browse files
committed
$ResponseMetadata assertions
1 parent c18ed00 commit d8ebf1d

File tree

2 files changed

+76
-7
lines changed

2 files changed

+76
-7
lines changed

src/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ function mandatoryParametersAvailable(options: ImageKitOptions) {
1010
return options.urlEndpoint;
1111
}
1212

13-
function privateKeyPassed(options: ImageKitOptions) {
14-
return typeof (options as any).privateKey != "undefined";
15-
}
16-
1713
const promisify = function <T = void>(thisContext: ImageKit, fn: Function) {
1814
return function (...args: any[]): Promise<T> | void {
1915
if (args.length === fn.length && typeof args[args.length - 1] !== "undefined") {
@@ -51,9 +47,6 @@ class ImageKit {
5147
if (!mandatoryParametersAvailable(this.options)) {
5248
throw errorMessages.MANDATORY_INITIALIZATION_MISSING;
5349
}
54-
if (privateKeyPassed(this.options)) {
55-
throw errorMessages.PRIVATE_KEY_CLIENT_SIDE;
56-
}
5750

5851
if (!transformationUtils.validParameters(this.options)) {
5952
throw errorMessages.INVALID_TRANSFORMATION_POSITION;

test/upload.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,4 +838,80 @@ describe("File upload", function () {
838838
successSignature();
839839
successUploadResponse();
840840
});
841+
842+
it('$ResponseMetadata assertions using promise', function (done) {
843+
var dummyResonseHeaders = {
844+
"Content-Type": "application/json",
845+
"x-request-id": "sdfsdfsdfdsf"
846+
};
847+
const fileOptions = {
848+
fileName: "test_file_name",
849+
file: "test_file",
850+
tags: "test_tag1,test_tag2",
851+
customCoordinates: "10, 10, 100, 100",
852+
responseFields: "tags, customCoordinates, isPrivateFile, metadata",
853+
useUniqueFileName: false,
854+
isPrivateFile: true,
855+
extensions: [
856+
{
857+
name: "aws-auto-tagging",
858+
minConfidence: 80,
859+
maxTags: 10
860+
}
861+
]
862+
};
863+
imagekit.upload(fileOptions).then((response) => {
864+
expect(server.requests.length).to.be.equal(2);
865+
expect(response.$ResponseMetadata.headers).to.be.deep.equal(dummyResonseHeaders);
866+
expect(response.$ResponseMetadata.statusCode).to.be.deep.equal(200);
867+
done();
868+
});
869+
870+
successSignature();
871+
872+
server.respondWith("POST", "https://upload.imagekit.io/api/v1/files/upload",
873+
[
874+
200,
875+
dummyResonseHeaders,
876+
JSON.stringify(uploadSuccessResponseObj)
877+
]
878+
);
879+
server.respond();
880+
});
881+
882+
it('$ResponseMetadata assertions using callback', function () {
883+
var dummyResonseHeaders = {
884+
"Content-Type": "application/json",
885+
"x-request-id": "sdfsdfsdfdsf"
886+
};
887+
const fileOptions = {
888+
fileName: "test_file_name",
889+
file: "test_file"
890+
};
891+
var callback = sinon.spy();
892+
imagekit.upload(fileOptions, callback);
893+
894+
successSignature();
895+
server.respondWith("POST", "https://upload.imagekit.io/api/v1/files/upload",
896+
[
897+
200,
898+
dummyResonseHeaders,
899+
JSON.stringify(uploadSuccessResponseObj)
900+
]
901+
);
902+
903+
expect(server.requests.length).to.be.equal(2);
904+
successSignature();
905+
successUploadResponse();
906+
907+
expect(callback.calledOnce).to.be.true;
908+
909+
var callBackArguments = callback.args[0];
910+
expect(callBackArguments.length).to.be.eq(2);
911+
var callbackResult = callBackArguments[1];
912+
913+
expect(callbackResult).to.be.deep.equal(uploadSuccessResponseObj);
914+
expect(callbackResult.$ResponseMetadata.headers).to.be.deep.equal(dummyResonseHeaders);
915+
expect(callbackResult.$ResponseMetadata.statusCode).to.be.deep.equal(200);
916+
});
841917
});

0 commit comments

Comments
 (0)