Skip to content

Commit fd37619

Browse files
authored
Merge pull request #56 from imagekit-developer/sdk-v2-upgrade
Add missing URL endpoint check
2 parents 25e5818 + fbc476a commit fd37619

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

sdk/lib/src/imagekitio-angular/ik-image/ik-image.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ export class IkImageComponent implements AfterViewInit, OnInit, OnChanges {
111111

112112
if (options.urlEndpoint) {
113113
config['urlEndpoint'] = options.urlEndpoint;
114+
}else{
115+
throw new Error('Missing urlEndpoint initialization!');
114116
}
117+
115118
if (options.queryParameters) {
116119
config['queryParameters'] = options.queryParameters;
117120
}

sdk/lib/src/imagekitio-angular/ik-video/ik-video.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ export class IkVideoComponent implements OnInit {
6363
};
6464
if (options.urlEndpoint) {
6565
config['urlEndpoint'] = options.urlEndpoint;
66+
} else{
67+
throw new Error('Missing urlEndpoint initialization!');
6668
}
69+
6770
if (options.queryParameters) {
6871
config['queryParameters'] = options.queryParameters;
6972
}

sdk/tests/sdk-tests/ik-image.component.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe("IkImageComponent", () => {
4747
let elRef: ElementRef;
4848
comp = new IkImageComponent(elRef, iKService);
4949
let options: IkImageComponentOptions = {
50+
urlEndpoint: "https://ik.imagekit.io/company",
5051
path: "/abc.png"
5152
};
5253
comp.setUrl(options);
@@ -71,6 +72,7 @@ describe("IkImageComponent", () => {
7172
let elRef: ElementRef;
7273
comp = new IkImageComponent(elRef, iKService);
7374
let options: IkImageComponentOptions = {
75+
urlEndpoint: "https://ik.imagekit.io/company/",
7476
path: "/abc.png"
7577
};
7678
comp.setUrl(options);
@@ -86,6 +88,7 @@ describe("IkImageComponent", () => {
8688
it("new unsupported transformation parameter is passed then it should come in URL as it is", () => {
8789
const transformation = [{ foo: "200", bar: "200" }];
8890
let options: IkImageComponentOptions = {
91+
urlEndpoint: "https://ik.imagekit.io/company/",
8992
src: "https://abc.com/def",
9093
transformation: transformation
9194
};
@@ -96,6 +99,7 @@ describe("IkImageComponent", () => {
9699
it("supported transformation parameter is passed then it should come in query parameters after transformation", () => {
97100
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
98101
let options: IkImageComponentOptions = {
102+
urlEndpoint: "https://ik.imagekit.io/company/",
99103
src: "https://abc.com/def",
100104
transformation: transformation
101105
}
@@ -106,6 +110,7 @@ describe("IkImageComponent", () => {
106110
it("if SRC is used to create URL, transformartionPosition should be query", () => {
107111
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
108112
let options: IkImageComponentOptions = {
113+
urlEndpoint: "https://ik.imagekit.io/company/",
109114
src: "https://abc.com/def",
110115
transformation: transformation
111116
};
@@ -116,6 +121,7 @@ describe("IkImageComponent", () => {
116121
it("if SRC is used to create URL, transformartionPosition should be query even if anything else is passed", () => {
117122
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
118123
let options: IkImageComponentOptions = {
124+
urlEndpoint: "https://ik.imagekit.io/company/",
119125
src: "https://example.com/ab.png",
120126
transformation: transformation,
121127
transformationPosition: "path"
@@ -129,6 +135,7 @@ describe("IkImageComponent", () => {
129135
it("if PATH is used to create URL, transformartionPosition should be kept as is", () => {
130136
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
131137
let options: IkImageComponentOptions = {
138+
urlEndpoint: "https://ik.imagekit.io/company/",
132139
path: "ab.png",
133140
transformation: transformation,
134141
transformationPosition: "query"
@@ -141,6 +148,7 @@ describe("IkImageComponent", () => {
141148

142149
it("Parameters passed to queryParameters should be present in URL if src is used", () => {
143150
let options: IkImageComponentOptions = {
151+
urlEndpoint: "https://ik.imagekit.io/company/",
144152
src: "https://example.com/ab.png",
145153
queryParameters: {version:5, name: "check"}
146154
};
@@ -150,6 +158,7 @@ describe("IkImageComponent", () => {
150158

151159
it("Parameters passed to queryParameters should be present in URL if src with existing query is used", () => {
152160
let options: IkImageComponentOptions = {
161+
urlEndpoint: "https://ik.imagekit.io/company/",
153162
src: "https://example.com/ab.png?foo=bar&baz=nax",
154163
queryParameters: {version:5, name: "check"}
155164
};
@@ -160,6 +169,7 @@ describe("IkImageComponent", () => {
160169

161170
it("Parameters passed to queryParameters should be present in URL if path is used", () => {
162171
let options: IkImageComponentOptions = {
172+
urlEndpoint: "https://ik.imagekit.io/company/",
163173
path: "/default.png",
164174
queryParameters: {version:6, name: "bar"}
165175
};
@@ -169,6 +179,7 @@ describe("IkImageComponent", () => {
169179

170180
it("setUrl should create correct URL when src is provided", () => {
171181
let options: IkImageComponentOptions = {
182+
urlEndpoint: "https://ik.imagekit.io/company/",
172183
src: "https://test-absolute-path.com/image.jpg"
173184
};
174185
component.setUrl(options);
@@ -177,6 +188,7 @@ describe("IkImageComponent", () => {
177188

178189
it("setUrl should create correct URL when path is provided", () => {
179190
let options: IkImageComponentOptions = {
191+
urlEndpoint: "https://ik.imagekit.io/company/",
180192
path: "def"
181193
};
182194
component.setUrl(options);
@@ -185,6 +197,7 @@ describe("IkImageComponent", () => {
185197

186198
it("setUrl should create correct lqipURL in addition to URL when lqip is provided", () => {
187199
let options: IkImageComponentOptions = {
200+
urlEndpoint: "https://ik.imagekit.io/company/",
188201
src: "https://example.com/abc",
189202
lqip: { active: true, quality: 1 }
190203
};
@@ -247,10 +260,20 @@ describe("IkImageComponent", () => {
247260
);
248261
expect(lqipURl2).toContain("tr=n-lqip");
249262
});
263+
264+
it("if urlEndpoint not set, expect errors to be thrown", () => {
265+
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
266+
let options: IkImageComponentOptions = {
267+
transformation: transformation,
268+
transformationPosition: "query"
269+
};
270+
expect(()=>component.getConfigObject(options)).toThrow(new Error('Missing urlEndpoint initialization!'));
271+
});
250272

251273
it("if SRC and PATH not set, expect errors to be thrown", () => {
252274
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
253275
let options: IkImageComponentOptions = {
276+
urlEndpoint: 'https://ik.imagekit.io/example',
254277
transformation: transformation,
255278
transformationPosition: "query"
256279
};

sdk/tests/sdk-tests/ik-video.component.spec.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ describe("IkVideoComponent", () => {
3131

3232
it("urlEndpoint passed to component should be used over initialized value", () => {
3333
let options: IkVideoComponentOptions = {
34-
path: "def",
35-
urlEndpoint: "https://example.com"
34+
urlEndpoint: "https://example.com",
35+
path: "def"
3636
};
3737
component.setUrl(options);
3838
expect(component.url).toBe(`https://example.com/def`);
@@ -49,6 +49,7 @@ describe("IkVideoComponent", () => {
4949
let elRef: ElementRef;
5050
comp = new IkVideoComponent(elRef, iKService);
5151
let options: IkVideoComponentOptions = {
52+
urlEndpoint: "https://ik.imagekit.io/company/",
5253
path: "/sample-video.mp4"
5354
};
5455
comp.setUrl(options);
@@ -65,6 +66,7 @@ describe("IkVideoComponent", () => {
6566
it("new unsupported transformation parameter is passed then it should come in URL as it is", () => {
6667
const transformation = [{ foo: "200", bar: "200" }];
6768
let options: IkVideoComponentOptions = {
69+
urlEndpoint: "https://ik.imagekit.io/company/",
6870
src: "https://abc.com/def",
6971
transformation: transformation
7072
};
@@ -75,6 +77,7 @@ describe("IkVideoComponent", () => {
7577
it("supported transformation parameter is passed then it should come in query parameters after transformation", () => {
7678
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
7779
let options: IkVideoComponentOptions = {
80+
urlEndpoint: "https://ik.imagekit.io/company/",
7881
src: "https://abc.com/def",
7982
transformation: transformation
8083
};
@@ -85,6 +88,7 @@ describe("IkVideoComponent", () => {
8588
it("if SRC is used to create URL, transformartioPosition should be query", () => {
8689
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
8790
let options: IkVideoComponentOptions = {
91+
urlEndpoint: "https://ik.imagekit.io/company/",
8892
src: "https://abc.com/def",
8993
transformation: transformation
9094
};
@@ -95,6 +99,7 @@ describe("IkVideoComponent", () => {
9599
it("if SRC is used to create URL, transformationPosition should be query even if anything else is passed", () => {
96100
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
97101
let options: IkVideoComponentOptions = {
102+
urlEndpoint: "https://ik.imagekit.io/company/",
98103
src: "https://example.com/sample-video.mp4",
99104
transformation: transformation,
100105
transformationPosition: "path"
@@ -109,6 +114,7 @@ describe("IkVideoComponent", () => {
109114
it("if PATH is used to create URL, transformartionPosition should be kept as is", () => {
110115
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
111116
let options: IkVideoComponentOptions = {
117+
urlEndpoint: "https://ik.imagekit.io/company/",
112118
path: "sample-video.mp4",
113119
transformation: transformation,
114120
transformationPosition: "query"
@@ -122,6 +128,7 @@ describe("IkVideoComponent", () => {
122128

123129
it("Parameters passed to queryParameters should be present in URL if src is used", () => {
124130
let options: IkVideoComponentOptions = {
131+
urlEndpoint: "https://ik.imagekit.io/company/",
125132
src: "https://example.com/sample-video.mp4",
126133
queryParameters: {version:5, name: 'check'}
127134
};
@@ -131,6 +138,7 @@ describe("IkVideoComponent", () => {
131138

132139
it("Parameters passed to queryParameters should be present in URL if src with existing query is used", () => {
133140
let options: IkVideoComponentOptions = {
141+
urlEndpoint: "https://ik.imagekit.io/company/",
134142
src: "https://example.com/sample-video.mp4?foo=bar&baz=nax",
135143
queryParameters: {version:5, name: 'check'}
136144
};
@@ -141,6 +149,7 @@ describe("IkVideoComponent", () => {
141149

142150
it("Parameters passed to queryParameters should be present in URL if path is used", () => {
143151
let options: IkVideoComponentOptions = {
152+
urlEndpoint: "https://ik.imagekit.io/company/",
144153
path: "/default.png",
145154
queryParameters: {version:6, name: 'bar'}
146155
};
@@ -150,6 +159,7 @@ describe("IkVideoComponent", () => {
150159

151160
it("setUrl should create correct URL when src is provided", () => {
152161
let options: IkVideoComponentOptions = {
162+
urlEndpoint: "https://ik.imagekit.io/company/",
153163
src: "https://test-absolute-path.com/sample-video.mp4"
154164
};
155165
component.setUrl(options);
@@ -158,22 +168,34 @@ describe("IkVideoComponent", () => {
158168

159169
it("setUrl should create correct URL when path is provided", () => {
160170
let options: IkVideoComponentOptions = {
171+
urlEndpoint: "https://ik.imagekit.io/company/",
161172
path: "def"
162173
};
163174
component.setUrl(options);
164175
expect(component.url).toContain(`https://ik.imagekit.io/company/def`);
165176
});
166177

178+
it("if urlEndpoint not set, expect errors to be thrown", () => {
179+
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
180+
let options: IkVideoComponentOptions = {
181+
transformation: transformation,
182+
transformationPosition: "query"
183+
};
184+
expect(()=>component.getConfigObject(options)).toThrow(new Error('Missing urlEndpoint initialization!'));
185+
});
186+
167187
it("if SRC and PATH not set, expect errors to be thrown", () => {
168188
const transformation = [{ height: "200", width: "200" }, { rotation: "90"}];
169189
let options: IkVideoComponentOptions = {
190+
urlEndpoint: 'https://ik.imagekit.io/example',
170191
transformation: transformation,
171192
transformationPosition: "query"
172193
};
173194
expect(()=>component.getConfigObject(options)).toThrow(new Error('Missing src / path during initialization!'));
174195
});
175196

176197
it("video DOM src should be set initially", () => {
198+
component.urlEndpoint = "https://ik.imagekit.io/example";
177199
component.src = "https://ik.imagekit.io/demo/sample-video.mp4";
178200
fixture.detectChanges();
179201
const ikImageElement: HTMLElement = fixture.nativeElement;

0 commit comments

Comments
 (0)