@@ -3,6 +3,7 @@ import IURLConfig from "../../src/config/interfaces/Config/IURLConfig";
3
3
import { CloudinaryImage } from "../../src/assets/CloudinaryImage" ;
4
4
import { Resize } from "../../src/actions/resize" ;
5
5
import { createNewImage } from "../TestUtils/createCloudinaryImage" ;
6
+ import URLConfig from "../../src/config/URLConfig" ;
6
7
7
8
8
9
/**
@@ -17,20 +18,20 @@ function createURLFromConfig(urlConfig: IURLConfig) {
17
18
18
19
19
20
describe ( 'It tests a combination of Cloudinary URL and Configuration' , ( ) => {
20
- it ( 'Generates a URL' , ( ) => {
21
+ it ( 'Generates a URL' , ( ) => {
21
22
const url = createNewImage ( 'my_image' )
22
23
. toURL ( ) ;
23
24
24
25
expect ( url ) . toBe ( 'https://res.cloudinary.com/demo/image/upload/my_image' ) ;
25
26
} ) ;
26
27
27
- it ( 'Throw error when config is invalid' , ( ) => {
28
+ it ( 'Throw error when config is invalid' , ( ) => {
28
29
expect ( ( ) => {
29
30
new CloudinaryImage ( 'my_image' ) . toURL ( ) ; // missing cloudName should throw error
30
31
} ) . toThrow ( ) ;
31
32
} ) ;
32
33
33
- it ( 'Generates a URL with transforamtions' , ( ) => {
34
+ it ( 'Generates a URL with transforamtions' , ( ) => {
34
35
const url = createNewImage ( )
35
36
. resize ( Resize . fill ( 100 , 100 ) )
36
37
. setPublicID ( 'sample' )
@@ -39,13 +40,14 @@ describe('It tests a combination of Cloudinary URL and Configuration', () => {
39
40
expect ( url ) . toBe ( 'https://res.cloudinary.com/demo/image/upload/c_fill,h_100,w_100/sample' ) ;
40
41
} ) ;
41
42
42
- it ( 'Shows a use-case for global configuration' , ( ) => {
43
+ it ( 'Shows a use-case for global configuration' , ( ) => {
43
44
//
44
45
/**
45
46
* We can implement this "wrapper", or instruct our customers how to implement it.
46
47
*/
47
48
class MyGlobalCloudinary {
48
49
public cloudinaryConfig : ICloudinaryConfigurations ;
50
+
49
51
// Constructor accepts a cloudinary configuration
50
52
constructor ( cloudinaryConfig : ICloudinaryConfigurations ) {
51
53
this . cloudinaryConfig = cloudinaryConfig ;
@@ -80,37 +82,36 @@ describe('It tests a combination of Cloudinary URL and Configuration', () => {
80
82
} ) ;
81
83
82
84
83
-
84
85
it ( 'Secure by default' , ( ) => {
85
86
const url = createURLFromConfig ( { } ) ;
86
87
expect ( url ) . toContain ( 'https://res.cloudinary.com/demo' ) ;
87
88
} ) ;
88
89
89
90
it ( 'Supports secure:false' , ( ) => {
90
91
const url = createURLFromConfig ( {
91
- secure :false
92
+ secure : false
92
93
} ) ;
93
94
expect ( url ) . toContain ( 'http://res.cloudinary.com/demo' ) ;
94
95
} ) ;
95
96
96
97
it ( 'Support cname with secure false' , ( ) => {
97
98
const url = createURLFromConfig ( {
98
- cname :'hello.com' ,
99
+ cname : 'hello.com' ,
99
100
secure : false
100
101
} ) ;
101
102
expect ( url ) . toContain ( 'http://hello.com/demo' ) ;
102
103
} ) ;
103
104
104
105
it ( 'Support secureDistribution with secure true' , ( ) => {
105
106
const url = createURLFromConfig ( {
106
- secureDistribution :'foobar.com'
107
+ secureDistribution : 'foobar.com'
107
108
} ) ;
108
109
expect ( url ) . toContain ( 'https://foobar.com/demo' ) ;
109
110
} ) ;
110
111
111
112
it ( 'Support private CDN with secure true' , ( ) => {
112
113
const url = createURLFromConfig ( {
113
- privateCdn :true
114
+ privateCdn : true
114
115
} ) ;
115
116
expect ( url ) . toContain ( `https://demo-res.cloudinary.com/image/upload` ) ;
116
117
} ) ;
@@ -125,20 +126,43 @@ describe('It tests a combination of Cloudinary URL and Configuration', () => {
125
126
} ) ;
126
127
127
128
it ( 'Generates a URL with version in the public ID' , ( ) => {
128
- const img = createNewImage ( 'v1234/foo/sample' , { cloudName : 'demo' } , { forceVersion : true } ) ;
129
+ const img = createNewImage ( 'v1234/foo/sample' , { cloudName : 'demo' } , { forceVersion : true } ) ;
129
130
130
131
expect ( img . toURL ( ) ) . toContain ( 'https://res.cloudinary.com/demo/image/upload/v1234/foo/sample' ) ;
131
132
} ) ;
132
133
133
134
it ( 'Generates a URL with V1' , ( ) => {
134
- const img = createNewImage ( 'foo/sample' , { cloudName : 'demo' } , { forceVersion : true } ) ;
135
+ const img = createNewImage ( 'foo/sample' , { cloudName : 'demo' } , { forceVersion : true } ) ;
135
136
136
137
expect ( img . toURL ( ) ) . toContain ( 'https://res.cloudinary.com/demo/image/upload/v1/foo/sample' ) ;
137
138
} ) ;
138
139
139
140
it ( 'Generates a URL without V1' , ( ) => {
140
- const img = createNewImage ( 'foo/sample' , { cloudName : 'demo' } , { forceVersion : false } ) ;
141
+ const img = createNewImage ( 'foo/sample' , { cloudName : 'demo' } , { forceVersion : false } ) ;
141
142
142
143
expect ( img . toURL ( ) ) . toContain ( 'https://res.cloudinary.com/demo/image/upload/foo/sample' ) ;
143
144
} ) ;
145
+
146
+ it ( 'Sets attributes using setters' , ( ) => {
147
+ const conf = new URLConfig ( { } ) ;
148
+
149
+ conf
150
+ . setCname ( 'foo' )
151
+ . setForceVersion ( true )
152
+ . setLongUrlSignature ( true )
153
+ . setPrivateCdn ( true )
154
+ . setSecure ( true )
155
+ . setShorten ( true )
156
+ . setSignUrl ( true )
157
+ . setUseRootPath ( true ) ;
158
+
159
+ expect ( conf . cname ) . toBe ( 'foo' ) ;
160
+ expect ( conf . forceVersion ) . toBe ( true ) ;
161
+ expect ( conf . longUrlSignature ) . toBe ( true ) ;
162
+ expect ( conf . privateCdn ) . toBe ( true ) ;
163
+ expect ( conf . secure ) . toBe ( true ) ;
164
+ expect ( conf . shorten ) . toBe ( true ) ;
165
+ expect ( conf . signUrl ) . toBe ( true ) ;
166
+ expect ( conf . useRootPath ) . toBe ( true ) ;
167
+ } ) ;
144
168
} ) ;
0 commit comments