Skip to content

Add test for video query params #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions __TESTS__/unit/analytics/analytics.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,64 @@
* @jest-environment jsdom
*/



import {createNewImageWithAnalytics} from "./testUtils/createNewImageWithAnalytics";

import {createNewVideoWithAnalytics} from "./testUtils/createNewVideoWithAnalytics";

describe('Add analytics to a URL from the browser', () => {
it('Uses default techVersion 0.0.0 when in browser', () => {
it('Uses default techVersion 0.0.0 when in browser for image', () => {
const cldImage = createNewImageWithAnalytics('sample');
const url = cldImage.toURL({
trackedAnalytics: {
sdkSemver: '1.0.0'
}
});

// ATAAB{NODE_VERSION}0
// ATAAB{AA}0 -> we expect nodeVersion to be 0.0.0 in browser (Since it's missing)
// expect ATAABAA0
expect(cldImage.toURL({
expect(url).toContain('sample?_a=ATAABAA0'); // we shouldn't have a query param at all
});

it('Uses default techVersion 0.0.0 when in browser for image with file extension', () => {
const cldImage = createNewImageWithAnalytics('sample.jpg');
const url = cldImage.toURL({
trackedAnalytics: {
sdkSemver: '1.0.0'
}
})).toContain('ATAABAA0'); // we shouldn't have a query param at all
});

// ATAAB{NODE_VERSION}0
// ATAAB{AA}0 -> we expect nodeVersion to be 0.0.0 in browser (Since it's missing)
// expect ATAABAA0
expect(url).toContain('sample.jpg?_a=ATAABAA0'); // we shouldn't have a query param at all
});

it('Uses default techVersion 0.0.0 when in browser for video', () => {
const cldImage = createNewVideoWithAnalytics('sample');
const url = cldImage.toURL({
trackedAnalytics: {
sdkSemver: '1.0.0'
}
});

// ATAAB{NODE_VERSION}0
// ATAAB{AA}0 -> we expect nodeVersion to be 0.0.0 in browser (Since it's missing)
// expect ATAABAA0
expect(url).toContain('sample?_a=ATAABAA0'); // we shouldn't have a query param at all
});


it('Uses default techVersion 0.0.0 when in browser for video with file extension', () => {
const cldImage = createNewVideoWithAnalytics('sample.webm');
const url = cldImage.toURL({
trackedAnalytics: {
sdkSemver: '1.0.0'
}
});

// ATAAB{NODE_VERSION}0
// ATAAB{AA}0 -> we expect nodeVersion to be 0.0.0 in browser (Since it's missing)
// expect ATAABAA0
expect(url).toContain('sample.webm?_a=ATAABAA0'); // we shouldn't have a query param at all
});
});
11 changes: 11 additions & 0 deletions __TESTS__/unit/analytics/testUtils/createNewVideoWithAnalytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ICloudConfig from "../../../../src/config/interfaces/Config/ICloudConfig";
import IURLConfig from "../../../../src/config/interfaces/Config/IURLConfig";
import {CloudinaryVideo} from "../../../../src";
import {createNewVideo} from "../../../TestUtils/createCloudinaryVideo";

/**
* Create a new CloudinaryImage with analytics turned on by default
*/
export function createNewVideoWithAnalytics(publicID: string, cloudConfig?: ICloudConfig, urlConfig?: IURLConfig): CloudinaryVideo {
return createNewVideo(publicID, {cloudName: 'demo'}, {analytics: true, ...urlConfig});
}