From c12a7bea5cd88546e007041b8c151d3057fba8d7 Mon Sep 17 00:00:00 2001 From: maoznir Date: Sun, 26 Dec 2021 13:32:36 +0200 Subject: [PATCH] Add test for video query params --- .../unit/analytics/analytics.browser.test.ts | 54 ++++++++++++++++--- .../testUtils/createNewVideoWithAnalytics.ts | 11 ++++ 2 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 __TESTS__/unit/analytics/testUtils/createNewVideoWithAnalytics.ts diff --git a/__TESTS__/unit/analytics/analytics.browser.test.ts b/__TESTS__/unit/analytics/analytics.browser.test.ts index e6d4105a..291c3742 100644 --- a/__TESTS__/unit/analytics/analytics.browser.test.ts +++ b/__TESTS__/unit/analytics/analytics.browser.test.ts @@ -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 }); }); diff --git a/__TESTS__/unit/analytics/testUtils/createNewVideoWithAnalytics.ts b/__TESTS__/unit/analytics/testUtils/createNewVideoWithAnalytics.ts new file mode 100644 index 00000000..4d9edf62 --- /dev/null +++ b/__TESTS__/unit/analytics/testUtils/createNewVideoWithAnalytics.ts @@ -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}); +}