Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Allow overriding npm registry for community packages #10325

Merged
merged 6 commits into from
Aug 14, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add test for when instance is not licensed to use a custom repo
  • Loading branch information
netroy committed Aug 13, 2024
commit 4bf040b92c159ce225d964b47f6ae6665d8cd93c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ describe('CommunityPackagesService', () => {
});
const loadNodesAndCredentials = mock<LoadNodesAndCredentials>();

const nodeName = randomName();
const installedNodesRepository = mockInstance(InstalledNodesRepository);
installedNodesRepository.create.mockImplementation(() => {
const nodeName = randomName();

return Object.assign(new InstalledNodes(), {
name: nodeName,
type: nodeName,
Expand Down Expand Up @@ -378,25 +377,22 @@ describe('CommunityPackagesService', () => {
};

describe('updateNpmModule', () => {
const packageDirectoryLoader = mock<PackageDirectoryLoader>();
const installedPackage = mock<InstalledPackages>({ packageName: mockPackageName() });
const packageDirectoryLoader = mock<PackageDirectoryLoader>({
loadedNodes: [{ name: nodeName, version: 1 }],
});

beforeEach(async () => {
jest.clearAllMocks();

loadNodesAndCredentials.loadPackage.mockResolvedValue(packageDirectoryLoader);
mocked(exec).mockImplementation(execMock);
});

test('should call `exec` with the correct command ', async () => {
test('should call `exec` with the correct command and registry', async () => {
//
// ARRANGE
//
const nodeName = randomName();
packageDirectoryLoader.loadedNodes = [{ name: nodeName, version: 1 }];

const installedPackage = new InstalledPackages();
installedPackage.packageName = mockPackageName();

mocked(exec).mockImplementation(execMock);
license.isCustomNpmRegistryEnabled.mockReturnValue(true);
netroy marked this conversation as resolved.
Show resolved Hide resolved

//
Expand All @@ -416,5 +412,29 @@ describe('CommunityPackagesService', () => {
expect.any(Function),
);
});

test('should call `exec` with the default registry when not licensed', async () => {
//
// ARRANGE
//
license.isCustomNpmRegistryEnabled.mockReturnValue(false);

//
// ACT
//
await 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),
);
});
});
});