mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
update tests
This commit is contained in:
parent
a41d1b00d8
commit
ce8208e56b
|
@ -1,5 +1,9 @@
|
||||||
import { createPinia, setActivePinia } from 'pinia';
|
import { createPinia, setActivePinia } from 'pinia';
|
||||||
import { generateUpgradeLinkUrl, useUIStore } from '@/stores/ui.store';
|
import {
|
||||||
|
generateCloudDashboardAutoLoginLink,
|
||||||
|
generateUpgradeLink,
|
||||||
|
useUIStore,
|
||||||
|
} from '@/stores/ui.store';
|
||||||
import { useSettingsStore } from '@/stores/settings.store';
|
import { useSettingsStore } from '@/stores/settings.store';
|
||||||
import { useUsersStore } from '@/stores/users.store';
|
import { useUsersStore } from '@/stores/users.store';
|
||||||
import { merge } from 'lodash-es';
|
import { merge } from 'lodash-es';
|
||||||
|
@ -98,7 +102,7 @@ describe('UI store', () => {
|
||||||
'https://n8n.io/pricing?utm_campaign=utm-test-campaign&source=test_source',
|
'https://n8n.io/pricing?utm_campaign=utm-test-campaign&source=test_source',
|
||||||
],
|
],
|
||||||
])(
|
])(
|
||||||
'"generateUpgradeLinkUrl" should generate the correct URL for "%s" deployment and "%s" license environment and user role "%s"',
|
'"generateUpgradeLink" should generate the correct URL for "%s" deployment and "%s" license environment and user role "%s"',
|
||||||
async (type, environment, role, expectation) => {
|
async (type, environment, role, expectation) => {
|
||||||
setUser(role as IRole);
|
setUser(role as IRole);
|
||||||
|
|
||||||
|
@ -115,7 +119,7 @@ describe('UI store', () => {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const updateLinkUrl = await generateUpgradeLinkUrl('test_source', 'utm-test-campaign', type);
|
const updateLinkUrl = await generateUpgradeLink('test_source', 'utm-test-campaign', type);
|
||||||
|
|
||||||
expect(updateLinkUrl).toBe(expectation);
|
expect(updateLinkUrl).toBe(expectation);
|
||||||
},
|
},
|
||||||
|
|
|
@ -577,15 +577,7 @@ export const useUIStore = defineStore(STORES.UI, () => {
|
||||||
workflowsLeft,
|
workflowsLeft,
|
||||||
});
|
});
|
||||||
|
|
||||||
let upgradeLink = N8N_PRICING_PAGE_URL;
|
const upgradeLink = await generateUpgradeLink(source, utm_campaign, deploymentType);
|
||||||
|
|
||||||
if (deploymentType === 'cloud' && hasPermission(['instanceOwner'])) {
|
|
||||||
upgradeLink = await generateCloudDashboardAutoLoginLink({
|
|
||||||
source,
|
|
||||||
utm_campaign,
|
|
||||||
redirectionPath: '/account/change-plan',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode === 'open') {
|
if (mode === 'open') {
|
||||||
window.open(upgradeLink, '_blank');
|
window.open(upgradeLink, '_blank');
|
||||||
|
@ -773,29 +765,43 @@ export const listenForModalChanges = (opts: {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const generateUpgradeLink = async (
|
||||||
|
source: string,
|
||||||
|
utm_campaign: string,
|
||||||
|
deploymentType: string,
|
||||||
|
) => {
|
||||||
|
let upgradeLink = N8N_PRICING_PAGE_URL;
|
||||||
|
if (deploymentType === 'cloud' && hasPermission(['instanceOwner'])) {
|
||||||
|
upgradeLink = await generateCloudDashboardAutoLoginLink({
|
||||||
|
redirectionPath: '/account/change-plan',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL(upgradeLink);
|
||||||
|
|
||||||
|
if (utm_campaign) {
|
||||||
|
url.searchParams.set('utm_campaign', utm_campaign);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source) {
|
||||||
|
url.searchParams.set('source', source);
|
||||||
|
}
|
||||||
|
|
||||||
|
return url.toString();
|
||||||
|
};
|
||||||
|
|
||||||
const generateCloudDashboardAutoLoginLink = async (data: {
|
const generateCloudDashboardAutoLoginLink = async (data: {
|
||||||
source?: string;
|
|
||||||
utm_campaign?: string;
|
|
||||||
redirectionPath: string;
|
redirectionPath: string;
|
||||||
}) => {
|
}) => {
|
||||||
let linkUrl = '';
|
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
|
|
||||||
const cloudPlanStore = useCloudPlanStore();
|
const cloudPlanStore = useCloudPlanStore();
|
||||||
|
|
||||||
const adminPanelHost = new URL(window.location.href).host.split('.').slice(1).join('.');
|
const adminPanelHost = new URL(window.location.href).host.split('.').slice(1).join('.');
|
||||||
const { code } = await cloudPlanStore.getAutoLoginCode();
|
const { code } = await cloudPlanStore.getAutoLoginCode();
|
||||||
linkUrl = `https://${adminPanelHost}/login`;
|
const linkUrl = `https://${adminPanelHost}/login`;
|
||||||
searchParams.set('code', code);
|
searchParams.set('code', code);
|
||||||
searchParams.set('returnPath', data.redirectionPath);
|
searchParams.set('returnPath', data.redirectionPath);
|
||||||
|
|
||||||
if (data?.utm_campaign) {
|
|
||||||
searchParams.set('utm_campaign', data.utm_campaign);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data?.source) {
|
|
||||||
searchParams.set('source', data.source);
|
|
||||||
}
|
|
||||||
return `${linkUrl}?${searchParams.toString()}`;
|
return `${linkUrl}?${searchParams.toString()}`;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue