|
| 1 | +const cloudinary = require('../../../../cloudinary'); |
| 2 | +const {TIMEOUT} = require('../../../testUtils/testConstants'); |
| 3 | +const describe = require('../../../testUtils/suite'); |
| 4 | +const wait = require('../../../testUtils/helpers/wait'); |
| 5 | + |
| 6 | +const folderNames = ['testFolder1', 'testFolder2']; |
| 7 | + |
| 8 | +describe('search_folders_api', function () { |
| 9 | + describe('unit', function () { |
| 10 | + it('should create empty json', function () { |
| 11 | + const query = cloudinary.v2.search_folders.instance().to_query(); |
| 12 | + expect(query).to.eql({}); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should always return same object in fluent interface', function () { |
| 16 | + const instance = cloudinary.v2.search_folders.instance(); |
| 17 | + const searchOptions = [ |
| 18 | + 'expression', |
| 19 | + 'sort_by', |
| 20 | + 'max_results', |
| 21 | + 'next_cursor', |
| 22 | + 'aggregate', |
| 23 | + 'with_field' |
| 24 | + ]; |
| 25 | + searchOptions.forEach(method => expect(instance).to.eql(instance[method]('emptyarg'))); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should correctly transform whole query into search payload', function () { |
| 29 | + const query = cloudinary.v2.search_folders |
| 30 | + .expression('expression-key:expression-value') |
| 31 | + .sort_by('sort_by_field', 'asc') |
| 32 | + .max_results(1) |
| 33 | + .next_cursor('next_cursor') |
| 34 | + .aggregate('aggregate1').aggregate('aggregate2') |
| 35 | + .with_field('field1').with_field('field2') |
| 36 | + .to_query(); |
| 37 | + |
| 38 | + expect(query).to.eql({ |
| 39 | + expression: 'expression-key:expression-value', |
| 40 | + sort_by: [{sort_by_field: 'asc'}], |
| 41 | + max_results: 1, |
| 42 | + next_cursor: 'next_cursor', |
| 43 | + aggregate: ['aggregate1', 'aggregate2'], |
| 44 | + with_field: ['field1', 'field2'] |
| 45 | + }) |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + describe('integration', function () { |
| 50 | + this.timeout(TIMEOUT.LONG); |
| 51 | + |
| 52 | + before(function () { |
| 53 | + return Promise.all(folderNames.map(folderName => { |
| 54 | + return cloudinary.v2.api.create_folder(folderName); |
| 55 | + })).then(wait(2)); |
| 56 | + }); |
| 57 | + |
| 58 | + after(function () { |
| 59 | + return Promise.all(folderNames.map(folderName => { |
| 60 | + return cloudinary.v2.api.delete_folder(folderName); |
| 61 | + })); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should return a search response with folders', function () { |
| 65 | + return cloudinary.v2.search_folders.expression('name=testFolder*') |
| 66 | + .execute() |
| 67 | + .then(function (results) { |
| 68 | + expect(results).to.have.key('folders'); |
| 69 | + }); |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments