Skip to content

Commit 479bc20

Browse files
authored
Add test helper to determine whether to test an addon (#516)
1 parent 31815aa commit 479bc20

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

test/integration/api/admin/api_spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const helper = require("../../../spechelper");
88
const describe = require('../../../testUtils/suite');
99
const wait = require('../../../testUtils/helpers/wait');
1010
const uploadImage = helper.uploadImage;
11+
const shouldTestAddOn = helper.shouldTestAddOn;
12+
const ADDON_OCR = helper.ADDON_OCR;
1113
const callReusableTest = require('../../../testUtils/reusableTests/reusableTests').callReusableTest;
1214
const testConstants = require('../../../testUtils/testConstants');
1315
const API_V2 = cloudinary.v2.api;
@@ -861,6 +863,9 @@ describe("api", function () {
861863
})
862864
});
863865
it("should support requesting ocr when updating", async function () {
866+
if (!shouldTestAddOn(ADDON_OCR)) {
867+
this.skip();
868+
}
864869
// Update an image with ocr parameter
865870
const ocrType = "adv_ocr";
866871
const updateResult = await API_V2.update(PUBLIC_ID_OCR_1, { ocr: ocrType });
@@ -872,6 +877,9 @@ describe("api", function () {
872877
expect(updateResult.info.ocr).to.have.property(ocrType);
873878
});
874879
it("should return 'Illegal value' errors for unknown ocr types", function () {
880+
if (!shouldTestAddOn(ADDON_OCR)) {
881+
this.skip();
882+
}
875883
this.timeout(TIMEOUT.MEDIUM);
876884
return API_V2.update(PUBLIC_ID_OCR_1, {ocr: 'illegal'})
877885
.then(

test/integration/api/uploader/uploader_spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const LARGE_VIDEO = helper.LARGE_VIDEO;
1818
const EMPTY_IMAGE = helper.EMPTY_IMAGE;
1919
const RAW_FILE = helper.RAW_FILE;
2020
const uploadImage = helper.uploadImage;
21+
const shouldTestAddOn = helper.shouldTestAddOn;
22+
const ADDON_OCR = helper.ADDON_OCR;
2123
const TEST_ID = Date.now();
2224

2325
const METADATA_FIELD_UNIQUE_EXTERNAL_ID = 'metadata_field_external_id_' + TEST_ID;
@@ -1120,6 +1122,9 @@ describe("uploader", function () {
11201122
const ocrType = "adv_ocr";
11211123

11221124
it("should support requesting ocr when uploading", async function () {
1125+
if (!shouldTestAddOn(ADDON_OCR)) {
1126+
this.skip();
1127+
}
11231128
// Upload an image and request ocr details in the response
11241129
const result = await UPLOADER_V2.upload(IMAGE_FILE, {ocr: ocrType, tags: [TEST_TAG]});
11251130

@@ -1133,6 +1138,9 @@ describe("uploader", function () {
11331138
});
11341139

11351140
it("should support ocr parameter in explicit", async function () {
1141+
if (!shouldTestAddOn(ADDON_OCR)) {
1142+
this.skip();
1143+
}
11361144
// Upload an image
11371145
const uploadResult = await UPLOADER_V2.upload(IMAGE_FILE, {
11381146
tags: [TEST_TAG]

test/spechelper.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ exports.ICON_FILE = "test/.resources/favicon.ico";
2727
exports.VIDEO_URL = "http://res.cloudinary.com/demo/video/upload/dog.mp4";
2828
exports.IMAGE_URL = "http://res.cloudinary.com/demo/image/upload/sample";
2929

30+
exports.ADDON_ALL = 'all'; // Test all addons.
31+
exports.ADDON_ASPOSE = 'aspose'; // Aspose document conversion.
32+
exports.ADDON_AZURE = 'azure'; // Microsoft azure video indexer.
33+
exports.ADDON_BG_REMOVAL = 'bgremoval'; // Cloudinary AI background removal.
34+
exports.ADDON_FACIAL_ATTRIBUTES_DETECTION = 'facialattributesdetection'; // Advanced facial attributes detection.
35+
exports.ADDON_GOOGLE = 'google'; /* Google AI video moderation, google AI
36+
video transcription, google auto tagging,
37+
google automatic video tagging,
38+
google translation.
39+
*/
40+
exports.ADDON_IMAGGA = 'imagga'; // Imagga auto tagging, crop and scale.
41+
exports.ADDON_JPEGMINI = 'jpegmini'; // JPEGmini image optimization.
42+
exports.ADDON_LIGHTROOM = 'lightroom'; // Adobe photoshop lightroom (BETA).
43+
exports.ADDON_METADEFENDER = 'metadefender'; // MetaDefender anti-malware protection.
44+
exports.ADDON_NEURAL_ARTWORK = 'neuralartwork'; // Neural artwork style transfer.
45+
exports.ADDON_OBJECT_AWARE_CROPPING = 'objectawarecropping'; // Cloudinary object-aware cropping.
46+
exports.ADDON_OCR = 'ocr'; // OCR text detection and extraction.
47+
exports.ADDON_PIXELZ = 'pixelz'; // Remove the background.
48+
exports.ADDON_REKOGNITION = 'rekognition'; /* Amazon rekognition AI moderation,
49+
amazon rekognition auto tagging,
50+
amazon rekognition celebrity detection.
51+
*/
52+
exports.ADDON_URL2PNG = 'url2png'; // URL2PNG website screenshots.
53+
exports.ADDON_VIESUS = 'viesus'; // VIESUS automatic image enhancement.
54+
exports.ADDON_WEBPURIFY = 'webpurify'; // WebPurify image moderation.
55+
3056
const { TEST_TAG } = require('./testUtils/testConstants').TAGS;
3157

3258
exports.SAMPLE_VIDEO_SOURCES = [
@@ -259,4 +285,18 @@ exports.toISO8601DateOnly = function (timestamp) {
259285
return date.toISOString().split('T')[0];
260286
};
261287

288+
/**
289+
* Checks if tests for an addon should be executed.
290+
*
291+
* @param {string} addOn
292+
* @returns {boolean}
293+
*/
294+
exports.shouldTestAddOn = function (addOn) {
295+
const cldTestAddons = (process.env.CLD_TEST_ADDONS || '').toLowerCase();
296+
if (cldTestAddons === this.ADDON_ALL) {
297+
return true;
298+
}
299+
return cldTestAddons.trim().split(',').includes(addOn.toLowerCase())
300+
}
301+
262302

0 commit comments

Comments
 (0)