Files
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

163 lines
5.4 KiB
JavaScript

import { expect } from 'chai';
import proxyquire from 'proxyquire';
import { ltrim, rtrim } from '../../../../../lib/utils/stringUtils';
const { _getURL } = proxyquire.noCallThru().load('../../../../../app/utils/lib/getURL', {
'meteor/meteor': {
'Meteor': {
absoluteUrl() {
return 'http://localhost:3000/';
},
},
'@global': true,
},
});
const testPaths = (o, _processPath) => {
let processPath = _processPath;
if (o._root_url_path_prefix !== '') {
processPath = (path) => _processPath(o._root_url_path_prefix + path);
}
const cloudDeepLinkUrl = 'https://go.rocket.chat';
expect(_getURL('', o, cloudDeepLinkUrl)).to.be.equal(processPath(''));
expect(_getURL('/', o, cloudDeepLinkUrl)).to.be.equal(processPath(''));
expect(_getURL('//', o, cloudDeepLinkUrl)).to.be.equal(processPath(''));
expect(_getURL('///', o, cloudDeepLinkUrl)).to.be.equal(processPath(''));
expect(_getURL('/channel', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel'));
expect(_getURL('/channel/', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel'));
expect(_getURL('/channel//', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel'));
expect(_getURL('/channel/123', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel/123'));
expect(_getURL('/channel/123/', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel/123'));
expect(_getURL('/channel/123?id=456&name=test', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel/123?id=456&name=test'));
expect(_getURL('/channel/123/?id=456&name=test', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel/123?id=456&name=test'));
};
const getCloudUrl = (_site_url, path) => {
path = ltrim(path, '/');
const url = `https://go.rocket.chat/?host=${encodeURIComponent(_site_url.replace(/https?:\/\//, ''))}&path=${encodeURIComponent(path)}`;
if (_site_url.includes('http://')) {
return `${url}&secure=no`;
}
return url;
};
const testCases = (options) => {
const _site_url = rtrim(options._site_url, '/');
if (!options.cloud) {
if (options._cdn_prefix === '') {
if (options.full && !options.cdn) {
it('should return with host if full: true', () => {
testPaths(options, (path) => _site_url + path);
});
}
if (!options.full && options.cdn) {
it('should return without cdn prefix if cdn: true', () => {
testPaths(options, (path) => path);
});
}
if (!options.full && !options.cdn) {
it('should return without host by default', () => {
testPaths(options, (path) => path);
});
}
if (options.full && options.cdn) {
it('should return with host if full: true and cdn: true', () => {
testPaths(options, (path) => _site_url + path);
});
}
} else {
if (options.full && !options.cdn) {
it('should return with host if full: true', () => {
testPaths(options, (path) => _site_url + path);
});
}
if (!options.full && options.cdn) {
it('should return with cdn prefix if cdn: true', () => {
testPaths(options, (path) => options._cdn_prefix + path);
});
}
if (!options.full && !options.cdn) {
it('should return without host by default', () => {
testPaths(options, (path) => path);
});
}
if (options.full && options.cdn) {
it('should return with cdn prefix if full: true and cdn: true', () => {
testPaths(options, (path) => options._cdn_prefix + path);
});
}
}
} else if (options._cdn_prefix === '') {
if (!options.full && options.cdn) {
it('should return with cloud host if cdn: true', () => {
testPaths(options, (path) => getCloudUrl(_site_url, path));
});
}
if (!options.full && !options.cdn) {
it('should return with cloud host if full: fase and cdn: false', () => {
testPaths(options, (path) => getCloudUrl(_site_url, path));
});
}
} else if (!options.full && !options.cdn) {
it('should return with cloud host if full: fase and cdn: false', () => {
testPaths(options, (path) => getCloudUrl(_site_url, path));
});
}
};
const testCasesForOptions = (description, options) => {
describe(description, () => {
testCases({ ...options, cdn: false, full: false, cloud: false });
testCases({ ...options, cdn: true, full: false, cloud: false });
testCases({ ...options, cdn: false, full: true, cloud: false });
testCases({ ...options, cdn: false, full: false, cloud: true });
testCases({ ...options, cdn: true, full: true, cloud: false });
testCases({ ...options, cdn: false, full: true, cloud: true });
testCases({ ...options, cdn: true, full: false, cloud: true });
testCases({ ...options, cdn: true, full: true, cloud: true });
});
};
describe('getURL', () => {
testCasesForOptions('getURL with no CDN, no PREFIX for http://localhost:3000/', {
_cdn_prefix: '',
_root_url_path_prefix: '',
_site_url: 'http://localhost:3000/',
});
testCasesForOptions('getURL with no CDN, no PREFIX for http://localhost:3000', {
_cdn_prefix: '',
_root_url_path_prefix: '',
_site_url: 'http://localhost:3000',
});
testCasesForOptions('getURL with CDN, no PREFIX for http://localhost:3000/', {
_cdn_prefix: 'https://cdn.com',
_root_url_path_prefix: '',
_site_url: 'http://localhost:3000/',
});
testCasesForOptions('getURL with CDN, PREFIX for http://localhost:3000/', {
_cdn_prefix: 'https://cdn.com',
_root_url_path_prefix: 'sub',
_site_url: 'http://localhost:3000/',
});
testCasesForOptions('getURL with CDN, PREFIX for https://localhost:3000/', {
_cdn_prefix: 'https://cdn.com',
_root_url_path_prefix: 'sub',
_site_url: 'https://localhost:3000/',
});
});