Skip to content

Commit

Permalink
throw FeatureNotLicensedError instead
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Aug 13, 2024
1 parent 4bf040b commit 69ba9f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ describe('CommunityPackagesService', () => {
);
});

test('should call `exec` with the default registry when not licensed', async () => {
test('should throw when not licensed', async () => {
//
// ARRANGE
//
Expand All @@ -422,18 +422,16 @@ describe('CommunityPackagesService', () => {
//
// ACT
//
await communityPackagesService.updatePackage(installedPackage.packageName, installedPackage);
const promise = communityPackagesService.updatePackage(
installedPackage.packageName,
installedPackage,
);

//
// ASSERT
//

expect(exec).toHaveBeenCalledTimes(1);
expect(exec).toHaveBeenNthCalledWith(
1,
`npm install ${installedPackage.packageName}@latest --registry=https://registry.npmjs.org`,
expect.any(Object),
expect.any(Function),
await expect(promise).rejects.toThrow(
'Your license does not allow for feat:communityNodes:customRegistry.',
);
});
});
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/services/communityPackages.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import { toError } from '@/utils';
import { InstalledPackagesRepository } from '@db/repositories/installedPackages.repository';
import type { InstalledPackages } from '@db/entities/InstalledPackages';
import {
LICENSE_FEATURES,
NODE_PACKAGE_PREFIX,
NPM_COMMAND_TOKENS,
NPM_PACKAGE_STATUS_GOOD,
RESPONSE_ERROR_MESSAGES,
UNKNOWN_FAILURE_REASON,
} from '@/constants';
import { FeatureNotLicensedError } from '@/errors/feature-not-licensed.error';
import type { CommunityPackages } from '@/Interfaces';
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
import { Logger } from '@/Logger';
Expand Down Expand Up @@ -325,10 +327,9 @@ export class CommunityPackagesService {
}

private getNpmRegistry() {
let { registry } = this.globalConfig.nodes.communityPackages;
const { registry } = this.globalConfig.nodes.communityPackages;
if (registry !== DEFAULT_REGISTRY && !this.license.isCustomNpmRegistryEnabled()) {
this.logger.warn('Not licensed to use custom NPM registry');
registry = DEFAULT_REGISTRY;
throw new FeatureNotLicensedError(LICENSE_FEATURES.COMMUNITY_NODES_CUSTOM_REGISTRY);
}
return registry;
}
Expand Down

0 comments on commit 69ba9f9

Please sign in to comment.