Skip to content
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
9 changes: 6 additions & 3 deletions src/index.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ export const player = (id, playerOptions = {}, ready) =>
export const players = (selector, playerOptions, ready) =>
createMultiplePlayers(selector, playerOptions, ready, player);

const cloudinaryVideoPlayerLegacyConfig = () => {
const cloudinaryVideoPlayerLegacyConfig = (instanceConfig = {}) => {
console.warn(
'Cloudinary.new() is deprecated and will be removed. Please use cloudinary.videoPlayer() instead.'
);
const mergeOpts = (callOpts = {}) => Object.assign({}, instanceConfig, callOpts);
return {
videoPlayer,
videoPlayers
videoPlayer: (id, playerOptions = {}, ready) =>
createVideoPlayer(id, mergeOpts(playerOptions), ready),
videoPlayers: (selector, playerOptions = {}, ready) =>
createMultipleSync(selector, mergeOpts(playerOptions), ready, videoPlayer)
};
};

Expand Down
43 changes: 43 additions & 0 deletions test/unit/legacy-cloudinary-new.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';

vi.mock('~/assets/styles/main.scss', () => ({}));

// Default export is the object returned by setupCloudinaryGlobal({ ... }) in src/index.umd.js
import cloudinary from '../../src/index.umd.js';

describe('Cloudinary.new() legacy instance config', () => {
let warnSpy;

beforeEach(() => {
warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
});

afterEach(() => {
warnSpy.mockRestore();
});

it('merges cloud_name from instance into per-call videoPlayer options', () => {
vi.useFakeTimers();
document.body.innerHTML = '<div><video id="legacy-new-test"/></div>';

const cld = cloudinary.Cloudinary.new({
cloud_name: 'demo',
secure: true,
private_cdn: false
});

const vp = cld.videoPlayer('legacy-new-test', { controls: true });
const conf = vp.videojs.cloudinary.cloudinaryConfig();
expect(conf.cloud_name).toEqual('demo');
});

it('per-call options override instance config', () => {
vi.useFakeTimers();
document.body.innerHTML = '<div><video id="legacy-new-override"/></div>';

const cld = cloudinary.Cloudinary.new({ cloud_name: 'from-instance' });
const vp = cld.videoPlayer('legacy-new-override', { cloud_name: 'from-call' });
const conf = vp.videojs.cloudinary.cloudinaryConfig();
expect(conf.cloud_name).toEqual('from-call');
});
});
Loading