2023-08-06 10:42:20 -05:00
|
|
|
import nock from 'nock';
|
2022-03-05 12:44:10 -05:00
|
|
|
|
2022-08-19 13:25:20 -05:00
|
|
|
import { Config, getDefaultConfig } from '@verdaccio/config';
|
2024-03-10 11:58:39 -05:00
|
|
|
import { fileUtils, searchUtils } from '@verdaccio/core';
|
2020-03-03 17:59:19 -05:00
|
|
|
import { setup } from '@verdaccio/logger';
|
2024-03-10 11:58:39 -05:00
|
|
|
import { removeDuplicates } from '@verdaccio/search';
|
|
|
|
import { generatePackageMetadata } from '@verdaccio/test-helper';
|
2020-03-03 17:59:19 -05:00
|
|
|
|
2024-03-10 11:58:39 -05:00
|
|
|
import { Storage } from '../src';
|
2020-03-03 17:59:19 -05:00
|
|
|
|
2023-08-06 10:42:20 -05:00
|
|
|
setup({});
|
2020-03-03 17:59:19 -05:00
|
|
|
|
2021-09-12 09:21:19 -05:00
|
|
|
describe('search', () => {
|
|
|
|
describe('search manager utils', () => {
|
|
|
|
test('remove duplicates', () => {
|
|
|
|
const item: searchUtils.SearchPackageItem = {
|
|
|
|
// @ts-expect-error
|
|
|
|
package: {
|
|
|
|
name: 'foo',
|
|
|
|
},
|
2021-12-12 12:00:19 -05:00
|
|
|
['dist-tags']: {
|
|
|
|
latest: '1.0.0',
|
|
|
|
},
|
2021-09-12 09:21:19 -05:00
|
|
|
// @ts-expect-error
|
|
|
|
score: {},
|
|
|
|
searchScore: 0.4,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(removeDuplicates([item, item])).toEqual([item]);
|
2020-03-03 17:59:19 -05:00
|
|
|
});
|
2024-03-10 11:58:39 -05:00
|
|
|
});
|
|
|
|
describe('search manager', () => {
|
2021-09-12 09:21:19 -05:00
|
|
|
test('search items', async () => {
|
2022-08-19 13:25:20 -05:00
|
|
|
const domain = 'https://registry.npmjs.org';
|
2021-09-12 09:21:19 -05:00
|
|
|
const url = '/-/v1/search?maintenance=1&popularity=1&quality=1&size=10&text=verdaccio';
|
|
|
|
const response = require('./fixtures/search.json');
|
2023-08-06 10:42:20 -05:00
|
|
|
nock(domain).get(url).reply(200, response);
|
2024-03-10 11:58:39 -05:00
|
|
|
const config = new Config({
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: await fileUtils.createTempStorageFolder('fix-1'),
|
|
|
|
});
|
2021-09-12 09:21:19 -05:00
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
2023-08-06 10:42:20 -05:00
|
|
|
const abort = new AbortController();
|
2024-03-10 11:58:39 -05:00
|
|
|
const pkgName = 'verdaccio';
|
|
|
|
const requestOptions = {
|
|
|
|
host: 'localhost',
|
|
|
|
protocol: 'http',
|
|
|
|
headers: {},
|
|
|
|
};
|
|
|
|
// create private packages
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '5.1.2');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions,
|
|
|
|
});
|
2021-09-12 09:21:19 -05:00
|
|
|
|
2024-03-10 11:58:39 -05:00
|
|
|
// @ts-expect-error
|
2023-08-06 10:42:20 -05:00
|
|
|
const results = await storage.search({ url, query: { text: 'verdaccio' }, abort });
|
2021-09-12 09:21:19 -05:00
|
|
|
expect(results).toHaveLength(4);
|
|
|
|
});
|
2020-03-03 17:59:19 -05:00
|
|
|
});
|
|
|
|
});
|