Skip to content

Commit b65ed7f

Browse files
committed
custom metadata field API test cases
1 parent 62c0d4d commit b65ed7f

File tree

4 files changed

+384
-8
lines changed

4 files changed

+384
-8
lines changed

index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,13 @@ class ImageKit {
492492
*
493493
* @see {@link https://docs.imagekit.io/api-reference/custom-metadata-fields-api/update-custom-metadata-field}
494494
*
495+
* @param fieldId
495496
* @param updateCustomMetadataFieldOptions
496497
*/
497-
updateCustomMetadataField(updateCustomMetadataFieldOptions: UpdateCustomMetadataFieldOptions): Promise<CustomMetadataField>;
498-
updateCustomMetadataField(updateCustomMetadataFieldOptions: UpdateCustomMetadataFieldOptions, callback: IKCallback<CustomMetadataField>): Promise<CustomMetadataField>;
499-
updateCustomMetadataField(updateCustomMetadataFieldOptions: UpdateCustomMetadataFieldOptions, callback?: IKCallback<CustomMetadataField>): void | Promise<CustomMetadataField> {
500-
return promisify<CustomMetadataField>(this, customMetadataField.update)(updateCustomMetadataFieldOptions, this.options, callback);
498+
updateCustomMetadataField(fieldId: string, updateCustomMetadataFieldOptions: UpdateCustomMetadataFieldOptions): Promise<CustomMetadataField>;
499+
updateCustomMetadataField(fieldId: string, updateCustomMetadataFieldOptions: UpdateCustomMetadataFieldOptions, callback: IKCallback<CustomMetadataField>): Promise<CustomMetadataField>;
500+
updateCustomMetadataField(fieldId: string, updateCustomMetadataFieldOptions: UpdateCustomMetadataFieldOptions, callback?: IKCallback<CustomMetadataField>): void | Promise<CustomMetadataField> {
501+
return promisify<CustomMetadataField>(this, customMetadataField.update)(fieldId, updateCustomMetadataFieldOptions, this.options, callback);
501502
}
502503

503504
/**

libs/constants/errorMessages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ export default {
3737
"CMF_SCHEMA_MISSING": { message: "Missing schema parameter for this request", help: "" },
3838
"CMF_SCHEMA_INVALID": { message: "Invalid value for schema", help: "schema should have a mandatory type field." },
3939
"CMF_LABEL_SCHEMA_MISSING": { message: "Both label and schema is missing", help: "" },
40+
"CMF_FIELD_ID_MISSING": { message: "Missing fieldId parameter for this request", help: "" },
4041
};

libs/manage/custom-metadata-field.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const create = function (createCustomMetadataFieldOptions: CreateCustomMetadataF
3737
return;
3838
}
3939

40-
if (!!schema.type) {
40+
if (!schema.type) {
4141
respond(true, errorMessages.CMF_SCHEMA_INVALID, callback);
4242
return;
4343
}
@@ -67,7 +67,12 @@ const list = function (
6767
request(requestOptions, defaultOptions, callback);
6868
};
6969

70-
const update = function (updateCustomMetadataFieldOptions: UpdateCustomMetadataFieldOptions, defaultOptions: ImageKitOptions, callback?: IKCallback<CustomMetadataField>) {
70+
const update = function (fieldId: string, updateCustomMetadataFieldOptions: UpdateCustomMetadataFieldOptions, defaultOptions: ImageKitOptions, callback?: IKCallback<CustomMetadataField>) {
71+
if (!fieldId || typeof fieldId !== "string" || !fieldId.length) {
72+
respond(true, errorMessages.CMF_FIELD_ID_MISSING, callback);
73+
return;
74+
}
75+
7176
const { label, schema } = updateCustomMetadataFieldOptions;
7277
if (!label && !schema) {
7378
respond(true, errorMessages.CMF_LABEL_SCHEMA_MISSING, callback);
@@ -79,8 +84,8 @@ const update = function (updateCustomMetadataFieldOptions: UpdateCustomMetadataF
7984
if (schema) requestBody.schema = schema;
8085

8186
var requestOptions = {
82-
url: "https://api.imagekit.io/v1/customMetadataFields",
83-
method: "POST",
87+
url: `https://api.imagekit.io/v1/customMetadataFields/${fieldId}`,
88+
method: "PATCH",
8489
json: requestBody
8590
};
8691

@@ -92,6 +97,10 @@ const deleteField = function (
9297
defaultOptions: ImageKitOptions,
9398
callback?: IKCallback<void>,
9499
) {
100+
if (!fieldId || typeof fieldId !== "string" || !fieldId.length) {
101+
respond(true, errorMessages.CMF_FIELD_ID_MISSING, callback);
102+
return;
103+
}
95104
var requestOptions = {
96105
url: `https://api.imagekit.io/v1/customMetadataFields/${fieldId}`,
97106
method: "DELETE",

0 commit comments

Comments
 (0)