mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix: Fix ordering issue when checking if staging environment (#17385)
This commit is contained in:
@@ -0,0 +1,72 @@
|
|||||||
|
import { inProduction } from '@n8n/backend-common';
|
||||||
|
|
||||||
|
import { getCommunityNodeTypes } from '../../utils/community-node-types-utils';
|
||||||
|
import { CommunityNodeTypesService } from '../community-node-types.service';
|
||||||
|
|
||||||
|
jest.mock('@n8n/backend-common', () => ({
|
||||||
|
inProduction: jest.fn().mockReturnValue(false),
|
||||||
|
logger: jest.fn().mockImplementation(() => ({
|
||||||
|
error: jest.fn(),
|
||||||
|
})),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock('../../utils/community-node-types-utils', () => ({
|
||||||
|
getCommunityNodeTypes: jest.fn().mockResolvedValue([]),
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('CommunityNodeTypesService', () => {
|
||||||
|
let service: CommunityNodeTypesService;
|
||||||
|
let globalConfigMock: any;
|
||||||
|
let communityPackagesServiceMock: any;
|
||||||
|
let loggerMock: any;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
|
||||||
|
delete process.env.ENVIRONMENT;
|
||||||
|
|
||||||
|
loggerMock = { error: jest.fn() };
|
||||||
|
globalConfigMock = {
|
||||||
|
nodes: {
|
||||||
|
communityPackages: {
|
||||||
|
enabled: true,
|
||||||
|
verifiedEnabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
communityPackagesServiceMock = {};
|
||||||
|
|
||||||
|
service = new CommunityNodeTypesService(
|
||||||
|
loggerMock,
|
||||||
|
globalConfigMock,
|
||||||
|
communityPackagesServiceMock,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('fetchNodeTypes', () => {
|
||||||
|
it('should use staging environment when ENVIRONMENT=staging', async () => {
|
||||||
|
process.env.ENVIRONMENT = 'staging';
|
||||||
|
await (service as any).fetchNodeTypes();
|
||||||
|
expect(getCommunityNodeTypes).toHaveBeenCalledWith('staging');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use production environment when inProduction=true', async () => {
|
||||||
|
(inProduction as unknown as jest.Mock).mockReturnValue(true);
|
||||||
|
await (service as any).fetchNodeTypes();
|
||||||
|
expect(getCommunityNodeTypes).toHaveBeenCalledWith('production');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use production environment when ENVIRONMENT=production', async () => {
|
||||||
|
process.env.ENVIRONMENT = 'production';
|
||||||
|
await (service as any).fetchNodeTypes();
|
||||||
|
expect(getCommunityNodeTypes).toHaveBeenCalledWith('production');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should prioritize ENVIRONMENT=staging over inProduction=true', async () => {
|
||||||
|
process.env.ENVIRONMENT = 'staging';
|
||||||
|
(inProduction as unknown as jest.Mock).mockReturnValue(true);
|
||||||
|
await (service as any).fetchNodeTypes();
|
||||||
|
expect(getCommunityNodeTypes).toHaveBeenCalledWith('staging');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -32,8 +32,7 @@ export class CommunityNodeTypesService {
|
|||||||
this.globalConfig.nodes.communityPackages.verifiedEnabled
|
this.globalConfig.nodes.communityPackages.verifiedEnabled
|
||||||
) {
|
) {
|
||||||
// Cloud sets ENVIRONMENT to 'production' or 'staging' depending on the environment
|
// Cloud sets ENVIRONMENT to 'production' or 'staging' depending on the environment
|
||||||
const environment =
|
const environment = this.detectEnvironment();
|
||||||
inProduction || process.env.ENVIRONMENT === 'production' ? 'production' : 'staging';
|
|
||||||
data = await getCommunityNodeTypes(environment);
|
data = await getCommunityNodeTypes(environment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +42,14 @@ export class CommunityNodeTypesService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private detectEnvironment() {
|
||||||
|
const environment = process.env.ENVIRONMENT;
|
||||||
|
if (environment === 'staging') return 'staging';
|
||||||
|
if (inProduction) return 'production';
|
||||||
|
if (environment === 'production') return 'production';
|
||||||
|
return 'staging';
|
||||||
|
}
|
||||||
|
|
||||||
private updateCommunityNodeTypes(nodeTypes: StrapiCommunityNodeType[]) {
|
private updateCommunityNodeTypes(nodeTypes: StrapiCommunityNodeType[]) {
|
||||||
if (!nodeTypes?.length) return;
|
if (!nodeTypes?.length) return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user