@@ -3,6 +3,7 @@ import IURLConfig from "../../src/config/interfaces/Config/IURLConfig";
33import { CloudinaryImage } from "../../src/assets/CloudinaryImage" ;
44import { Resize } from "../../src/actions/resize" ;
55import { createNewImage } from "../TestUtils/createCloudinaryImage" ;
6+ import URLConfig from "../../src/config/URLConfig" ;
67
78
89/**
@@ -17,20 +18,20 @@ function createURLFromConfig(urlConfig: IURLConfig) {
1718
1819
1920describe ( 'It tests a combination of Cloudinary URL and Configuration' , ( ) => {
20- it ( 'Generates a URL' , ( ) => {
21+ it ( 'Generates a URL' , ( ) => {
2122 const url = createNewImage ( 'my_image' )
2223 . toURL ( ) ;
2324
2425 expect ( url ) . toBe ( 'https://res.cloudinary.com/demo/image/upload/my_image' ) ;
2526 } ) ;
2627
27- it ( 'Throw error when config is invalid' , ( ) => {
28+ it ( 'Throw error when config is invalid' , ( ) => {
2829 expect ( ( ) => {
2930 new CloudinaryImage ( 'my_image' ) . toURL ( ) ; // missing cloudName should throw error
3031 } ) . toThrow ( ) ;
3132 } ) ;
3233
33- it ( 'Generates a URL with transforamtions' , ( ) => {
34+ it ( 'Generates a URL with transforamtions' , ( ) => {
3435 const url = createNewImage ( )
3536 . resize ( Resize . fill ( 100 , 100 ) )
3637 . setPublicID ( 'sample' )
@@ -39,13 +40,14 @@ describe('It tests a combination of Cloudinary URL and Configuration', () => {
3940 expect ( url ) . toBe ( 'https://res.cloudinary.com/demo/image/upload/c_fill,h_100,w_100/sample' ) ;
4041 } ) ;
4142
42- it ( 'Shows a use-case for global configuration' , ( ) => {
43+ it ( 'Shows a use-case for global configuration' , ( ) => {
4344 //
4445 /**
4546 * We can implement this "wrapper", or instruct our customers how to implement it.
4647 */
4748 class MyGlobalCloudinary {
4849 public cloudinaryConfig : ICloudinaryConfigurations ;
50+
4951 // Constructor accepts a cloudinary configuration
5052 constructor ( cloudinaryConfig : ICloudinaryConfigurations ) {
5153 this . cloudinaryConfig = cloudinaryConfig ;
@@ -80,37 +82,36 @@ describe('It tests a combination of Cloudinary URL and Configuration', () => {
8082 } ) ;
8183
8284
83-
8485 it ( 'Secure by default' , ( ) => {
8586 const url = createURLFromConfig ( { } ) ;
8687 expect ( url ) . toContain ( 'https://res.cloudinary.com/demo' ) ;
8788 } ) ;
8889
8990 it ( 'Supports secure:false' , ( ) => {
9091 const url = createURLFromConfig ( {
91- secure :false
92+ secure : false
9293 } ) ;
9394 expect ( url ) . toContain ( 'http://res.cloudinary.com/demo' ) ;
9495 } ) ;
9596
9697 it ( 'Support cname with secure false' , ( ) => {
9798 const url = createURLFromConfig ( {
98- cname :'hello.com' ,
99+ cname : 'hello.com' ,
99100 secure : false
100101 } ) ;
101102 expect ( url ) . toContain ( 'http://hello.com/demo' ) ;
102103 } ) ;
103104
104105 it ( 'Support secureDistribution with secure true' , ( ) => {
105106 const url = createURLFromConfig ( {
106- secureDistribution :'foobar.com'
107+ secureDistribution : 'foobar.com'
107108 } ) ;
108109 expect ( url ) . toContain ( 'https://foobar.com/demo' ) ;
109110 } ) ;
110111
111112 it ( 'Support private CDN with secure true' , ( ) => {
112113 const url = createURLFromConfig ( {
113- privateCdn :true
114+ privateCdn : true
114115 } ) ;
115116 expect ( url ) . toContain ( `https://demo-res.cloudinary.com/image/upload` ) ;
116117 } ) ;
@@ -125,20 +126,43 @@ describe('It tests a combination of Cloudinary URL and Configuration', () => {
125126 } ) ;
126127
127128 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 } ) ;
129130
130131 expect ( img . toURL ( ) ) . toContain ( 'https://res.cloudinary.com/demo/image/upload/v1234/foo/sample' ) ;
131132 } ) ;
132133
133134 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 } ) ;
135136
136137 expect ( img . toURL ( ) ) . toContain ( 'https://res.cloudinary.com/demo/image/upload/v1/foo/sample' ) ;
137138 } ) ;
138139
139140 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 } ) ;
141142
142143 expect ( img . toURL ( ) ) . toContain ( 'https://res.cloudinary.com/demo/image/upload/foo/sample' ) ;
143144 } ) ;
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+ } ) ;
144168} ) ;
0 commit comments