Skip to content

Commit 9ee8b78

Browse files
author
Nir Maoz
authored
Add test for video query params (#490)
1 parent bc991e9 commit 9ee8b78

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

__TESTS__/unit/analytics/analytics.browser.test.ts

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,64 @@
22
* @jest-environment jsdom
33
*/
44

5-
6-
75
import {createNewImageWithAnalytics} from "./testUtils/createNewImageWithAnalytics";
8-
6+
import {createNewVideoWithAnalytics} from "./testUtils/createNewVideoWithAnalytics";
97

108
describe('Add analytics to a URL from the browser', () => {
11-
it('Uses default techVersion 0.0.0 when in browser', () => {
9+
it('Uses default techVersion 0.0.0 when in browser for image', () => {
1210
const cldImage = createNewImageWithAnalytics('sample');
11+
const url = cldImage.toURL({
12+
trackedAnalytics: {
13+
sdkSemver: '1.0.0'
14+
}
15+
});
1316

1417
// ATAAB{NODE_VERSION}0
1518
// ATAAB{AA}0 -> we expect nodeVersion to be 0.0.0 in browser (Since it's missing)
1619
// expect ATAABAA0
17-
expect(cldImage.toURL({
20+
expect(url).toContain('sample?_a=ATAABAA0'); // we shouldn't have a query param at all
21+
});
22+
23+
it('Uses default techVersion 0.0.0 when in browser for image with file extension', () => {
24+
const cldImage = createNewImageWithAnalytics('sample.jpg');
25+
const url = cldImage.toURL({
1826
trackedAnalytics: {
1927
sdkSemver: '1.0.0'
2028
}
21-
})).toContain('ATAABAA0'); // we shouldn't have a query param at all
29+
});
30+
31+
// ATAAB{NODE_VERSION}0
32+
// ATAAB{AA}0 -> we expect nodeVersion to be 0.0.0 in browser (Since it's missing)
33+
// expect ATAABAA0
34+
expect(url).toContain('sample.jpg?_a=ATAABAA0'); // we shouldn't have a query param at all
35+
});
36+
37+
it('Uses default techVersion 0.0.0 when in browser for video', () => {
38+
const cldImage = createNewVideoWithAnalytics('sample');
39+
const url = cldImage.toURL({
40+
trackedAnalytics: {
41+
sdkSemver: '1.0.0'
42+
}
43+
});
44+
45+
// ATAAB{NODE_VERSION}0
46+
// ATAAB{AA}0 -> we expect nodeVersion to be 0.0.0 in browser (Since it's missing)
47+
// expect ATAABAA0
48+
expect(url).toContain('sample?_a=ATAABAA0'); // we shouldn't have a query param at all
49+
});
50+
51+
52+
it('Uses default techVersion 0.0.0 when in browser for video with file extension', () => {
53+
const cldImage = createNewVideoWithAnalytics('sample.webm');
54+
const url = cldImage.toURL({
55+
trackedAnalytics: {
56+
sdkSemver: '1.0.0'
57+
}
58+
});
59+
60+
// ATAAB{NODE_VERSION}0
61+
// ATAAB{AA}0 -> we expect nodeVersion to be 0.0.0 in browser (Since it's missing)
62+
// expect ATAABAA0
63+
expect(url).toContain('sample.webm?_a=ATAABAA0'); // we shouldn't have a query param at all
2264
});
2365
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ICloudConfig from "../../../../src/config/interfaces/Config/ICloudConfig";
2+
import IURLConfig from "../../../../src/config/interfaces/Config/IURLConfig";
3+
import {CloudinaryVideo} from "../../../../src";
4+
import {createNewVideo} from "../../../TestUtils/createCloudinaryVideo";
5+
6+
/**
7+
* Create a new CloudinaryImage with analytics turned on by default
8+
*/
9+
export function createNewVideoWithAnalytics(publicID: string, cloudConfig?: ICloudConfig, urlConfig?: IURLConfig): CloudinaryVideo {
10+
return createNewVideo(publicID, {cloudName: 'demo'}, {analytics: true, ...urlConfig});
11+
}

0 commit comments

Comments
 (0)