forked from peterpme/cloudinary-microurl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudinaryUrl.test.js
76 lines (63 loc) · 1.85 KB
/
cloudinaryUrl.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const cloudinaryUrl = require("./cloudinaryUrl");
const { Cloudinary } = require("cloudinary-core");
const cl = Cloudinary.new();
const CLOUD_NAME = "dance";
it("should default export to be a function", () => {
expect(cloudinaryUrl("cats", { cloud_name: CLOUD_NAME })).toBeDefined();
});
it("should fail when no cloud_name is present", () => {
expect(() => {
cloudinaryUrl();
}).toThrow("options.cloud_name required");
});
it("should render correctly without any additional options", () => {
const result = cloudinaryUrl("cats", { cloud_name: CLOUD_NAME });
const url = cl.url("cats", { cloud_name: CLOUD_NAME });
expect(result).toBe(url);
});
it("should render an https (secure) url", () => {
const options = {
cloud_name: CLOUD_NAME,
secure: true
};
const result = cloudinaryUrl("cats", options);
const url = cl.url("cats", options);
expect(result).toBe(url);
});
it("should render a remote (fetch) url", () => {
const result = cloudinaryUrl("https://www.peterp.me/headshot.png", {
cloud_name: CLOUD_NAME,
source: "fetch"
});
const url = cl.url("https://www.peterp.me/headshot.png", {
cloud_name: CLOUD_NAME,
type: "fetch"
});
expect(result).toBe(url);
});
it("should render correctly with crop and width", () => {
const options = {
cloud_name: CLOUD_NAME,
crop: "fill",
width: 100
};
const result = cloudinaryUrl("dog", options);
const url = cl.url("dog", options);
expect(result).toBe(url);
});
it("should render a bunch of different transformations", () => {
const options = {
crop: "fit",
effect: "blur:200",
fetch_format: "auto",
cloud_name: CLOUD_NAME,
flags: "progressive",
gravity: "face",
height: 300,
quality: 80,
width: 400
};
const result = cloudinaryUrl("dog", options);
const url = cl.url("dog", options);
expect(result).toBe(url);
});