-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maya Shavin
committed
Nov 3, 2020
1 parent
e04f03e
commit 03d2889
Showing
71 changed files
with
3,183 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { resize, rotate, roundCorners, quality, format, border } from '../lib/actions' | ||
|
||
describe('Actions', () => { | ||
describe('resize()', () => { | ||
it('should return with all options', () => { | ||
expect(resize({type: 'crop', width: 10, height: 20})).toEqual('c_crop,w_10,h_20') | ||
}) | ||
|
||
it('should return only type and height', () => { | ||
expect(resize({ type: 'crop', height: 20 })).toEqual('c_crop,h_20') | ||
}) | ||
|
||
it('should return only type and width', () => { | ||
expect(resize({ type: 'crop', width: '10' })).toEqual('c_crop,w_10') | ||
}) | ||
|
||
it('should auto-scale when only width and height', () => { | ||
expect(resize({ width:10, height: 10 })).toEqual('c_scale,w_10,h_10') | ||
}) | ||
}) | ||
|
||
describe('rotate', () => { | ||
it('should return rotation with angel', () => { | ||
expect(rotate(10)).toEqual('a_10') | ||
}) | ||
|
||
it('should return empty', () => { | ||
expect(rotate(0)).toEqual('') | ||
}) | ||
}) | ||
|
||
describe('roundCorners()', () => { | ||
it('should return valid option', () => { | ||
expect(roundCorners('max')).toEqual('r_max') | ||
}) | ||
}) | ||
|
||
describe('quality()', () => { | ||
it('should return default', () => { | ||
expect(quality()).toEqual('q_auto') | ||
}); | ||
|
||
it('should return default on undefined', () => { | ||
expect(quality(undefined)).toEqual('q_auto') | ||
}) | ||
|
||
it('should return valid option', () => { | ||
expect(quality(300)).toEqual('q_300') | ||
}); | ||
}); | ||
|
||
describe('format()', () => { | ||
it('should return default', () => { | ||
expect(format()).toEqual('f_auto') | ||
}); | ||
|
||
it('should return default on undefined', () => { | ||
expect(format(undefined)).toEqual('f_auto') | ||
}) | ||
|
||
it('should return valid option', () => { | ||
expect(format('webp')).toEqual('f_webp') | ||
}); | ||
}); | ||
|
||
describe('border', () => { | ||
it('should return a default type and color if only width is passed', () => { | ||
expect(border({ width: 10 })).toEqual('bo_10px_solid_black') | ||
}) | ||
|
||
it('should return options', () => { | ||
expect(border({ type: 'dotted', color: 'blue', width: 10 })).toEqual('bo_10px_dotted_blue') | ||
}) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import CImage from '../lib/cImage' | ||
import { Actions } from '../lib/actions' | ||
|
||
describe('CImage', () => { | ||
it('should contains only the actions passed', () => { | ||
const cimg = new CImage('a', [ Actions.resize ], { | ||
cloud: { | ||
cloudName: 'demo' | ||
}, | ||
url: { | ||
secure: true | ||
} | ||
}) | ||
|
||
expect(cimg.resize).toBeDefined() | ||
expect(cimg.rotate).toBeUndefined() | ||
}); | ||
|
||
it('should contains more than two actions passed', () => { | ||
const cimg = new CImage('a', [ Actions.resize, Actions.rotate ], { | ||
cloud: { | ||
cloudName: 'demo' | ||
}, | ||
url: { | ||
secure: true | ||
} | ||
}) | ||
|
||
expect(cimg.resize).toBeDefined() | ||
expect(cimg.rotate).toBeDefined() | ||
}); | ||
|
||
it('should have action triggerable', () => { | ||
const cimg = new CImage('a', [ Actions.quality ], { | ||
cloud: { | ||
cloudName: 'demo' | ||
}, | ||
url: { | ||
secure: true | ||
} | ||
}) | ||
|
||
cimg.quality() | ||
|
||
expect(cimg.actions).toEqual(['f_auto','q_auto']) | ||
}) | ||
|
||
it('should have valid url', () => { | ||
const cimg = new CImage('a', [ Actions.resize ], { | ||
cloud: { | ||
cloudName: 'demo' | ||
}, | ||
url: { | ||
secure: true | ||
} | ||
}) | ||
|
||
cimg.resize({ width: 100, height: 100 }) | ||
|
||
expect(cimg.url()).toEqual('https://res.cloudinary.com/demo/image/upload/f_auto/q_auto/c_scale,w_100,h_100/a') | ||
}) | ||
|
||
it('should have valid url with basic transformation', () => { | ||
const cimg = new CImage('a', [ Actions.rotate, Actions.resize ], { | ||
cloud: { | ||
cloudName: 'demo' | ||
}, | ||
url: { | ||
secure: true | ||
} | ||
}) | ||
|
||
expect(cimg.url()).toEqual('https://res.cloudinary.com/demo/image/upload/f_auto/q_auto/a') | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import CloudinaryApi from '../lib/cloudinary' | ||
|
||
describe('CloudinaryApi', () => { | ||
const mockReporterError = jest.fn() | ||
jest.mock('../lib/utils/reporter', () => ({ | ||
error: mockReporterError | ||
})) | ||
|
||
it('should throw error when no cloudName defined ', () => { | ||
const options = { | ||
use: { | ||
image: [] | ||
}, | ||
components: {} | ||
} | ||
|
||
new CloudinaryApi(options) | ||
|
||
expect(mockReporterError).toBeCalled() | ||
}) | ||
|
||
it('should throw error when no image or video selected', () => { | ||
const options = { | ||
cloudName: 'demo', | ||
use: {}, | ||
components: {} | ||
} | ||
|
||
const instance = new CloudinaryApi(options) | ||
|
||
expect(mockReporterError).toBeCalledTimes(1) | ||
expect(instance.image).toBeUndefined() | ||
expect(instance.video).toBeUndefined() | ||
}) | ||
|
||
it('should create instance of Cloudinary with options', () => { | ||
const options = { | ||
cloudName: 'demo', | ||
apiKey: '123', | ||
api_Secret: '1234', | ||
private: false, | ||
privateCdn: true, | ||
secure: true, | ||
use: { | ||
image: ['rotate', 'resize'] | ||
} | ||
} | ||
|
||
const instance = new CloudinaryApi(options) | ||
|
||
expect(mockReporterError).not.toBeCalled() | ||
expect(instance.cloudConfig).toEqual({ | ||
cloudName: 'demo', | ||
apiKey: '123' | ||
}) | ||
expect(instance.urlConfig).toEqual({ | ||
secure: true, | ||
privateCdn: true, | ||
}) | ||
expect(instance.image).toBeDefined() | ||
expect(instance.video).toBeUndefined() | ||
}) | ||
|
||
it('should create instance of Cloudinary with only image features', () => { | ||
const options = { | ||
cloudName: 'demo', | ||
apiKey: '123', | ||
api_Secret: '1234', | ||
private: false, | ||
privateCdn: true, | ||
secure: true, | ||
use: { | ||
image: ['rotate', 'resize'] | ||
} | ||
} | ||
|
||
const instance = new CloudinaryApi(options) | ||
|
||
expect(mockReporterError).not.toBeCalled | ||
expect(instance.cloudConfig).toEqual({ | ||
cloudName: 'demo', | ||
apiKey: '123' | ||
}) | ||
expect(instance.urlConfig).toEqual({ | ||
secure: true, | ||
privateCdn: true, | ||
}) | ||
expect(instance.image('sample').rotate).toBeDefined() | ||
expect(instance.image('sample').resize).toBeDefined() | ||
expect(instance.image('sample').quality).toBeUndefined() | ||
}) | ||
|
||
it('should create instance of Cloudinary with only video features', () => { | ||
const options = { | ||
cloudName: 'demo', | ||
apiKey: '123', | ||
api_Secret: '1234', | ||
private: false, | ||
privateCdn: true, | ||
secure: true, | ||
use: { | ||
video: ['rotate', 'resize'] | ||
} | ||
} | ||
|
||
const instance = new CloudinaryApi(options) | ||
|
||
expect(mockReporterError).not.toBeCalled() | ||
expect(instance.cloudConfig).toEqual({ | ||
cloudName: 'demo', | ||
apiKey: '123' | ||
}) | ||
expect(instance.urlConfig).toEqual({ | ||
secure: true, | ||
privateCdn: true, | ||
}) | ||
expect(instance.image).toBeUndefined() | ||
expect(instance.video).toBeDefined() | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Url from '../lib/utils/url' | ||
|
||
describe('Url', () => { | ||
describe('getPrefix()', () => { | ||
it('should return a prefix with image as default', () => { | ||
expect(Url.getPrefix({ | ||
cloudName: 'demo', | ||
resourceType: 'upload' | ||
})).toEqual('https://res.cloudinary.com/demo/image/upload') | ||
}) | ||
|
||
it('should return a prefix', () => { | ||
expect(Url.getPrefix({ | ||
cloudName: 'demo', | ||
resourceType: 'upload', | ||
assetType: 'video' | ||
})).toEqual('https://res.cloudinary.com/demo/video/upload') | ||
}) | ||
}) | ||
|
||
describe('getPathToAsset', () => { | ||
it('should force the default version', () => { | ||
expect(Url.getPathToAsset({ | ||
publicId: 'a', | ||
forceVersion: true | ||
})).toEqual('v1/a') | ||
}); | ||
|
||
it('should force the version when passed', () => { | ||
expect(Url.getPathToAsset({ | ||
publicId: 'a', | ||
forceVersion: true, | ||
version: 2 | ||
})).toEqual('v2/a') | ||
}); | ||
|
||
it('should not force version when not enabled ', () => { | ||
expect(Url.getPathToAsset({ | ||
publicId: 'a', | ||
})).toEqual('a') | ||
}); | ||
|
||
it('should not force a version when it is a url ', () => { | ||
expect(Url.getPathToAsset({ | ||
forceVersion: true, | ||
publicId: 'https://hello' | ||
})).toEqual('https://hello') | ||
}); | ||
|
||
it('should not force a version when it already contains a version ', () => { | ||
expect(Url.getPathToAsset({ | ||
forceVersion: true, | ||
publicId: 'v3/a' | ||
})).toEqual('v3/a') | ||
}); | ||
}) | ||
}) |
Oops, something went wrong.