import { Fixtures } from '~test/fixtures.ts'; import * as httpMock from '~test/http-mock.ts'; import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages.ts'; import { logger } from '../../../logger/index.ts'; import { joinUrlParts } from '../../../util/url.ts'; import { getPkgReleases } from '../index.ts'; import { ArtifactoryDatasource } from './index.ts'; const datasource = ArtifactoryDatasource.id; const testRegistryUrl = 'https://jfrog.company.com/artifactory'; const testLookupName = 'project'; const testConfig = { registryUrls: [testRegistryUrl], packageName: testLookupName, }; const fixtureReleasesAsFolders = Fixtures.get('releases-as-folders.html'); const fixtureReleasesAsFiles = Fixtures.get('releases-as-files.html'); function getPath(folder: string): string { return `/${folder}`; } describe('modules/datasource/artifactory/index', () => { describe('getReleases', () => { it('parses real data (folders): with slash at the end', async () => { httpMock .scope(testRegistryUrl) .get(getPath(testLookupName)) .reply(200, fixtureReleasesAsFolders); const res = await getPkgReleases({ ...testConfig, datasource, packageName: testLookupName, }); expect(res).toEqual({ registryUrl: 'https://jfrog.company.com/artifactory', releases: [ { releaseTimestamp: '2021-07-21T20:08:00.000Z', version: '1.0.0', }, { releaseTimestamp: '2021-08-23T20:03:00.000Z', version: '1.0.1', }, { releaseTimestamp: '2021-07-21T20:09:00.000Z', version: '1.0.2', }, { releaseTimestamp: '2021-02-06T09:54:00.000Z', version: '1.0.3', }, ], }); }); it('parses real data (files): without slash at the end', async () => { httpMock .scope(testRegistryUrl) .get(getPath(testLookupName)) .reply(200, fixtureReleasesAsFiles); const res = await getPkgReleases({ ...testConfig, datasource, packageName: testLookupName, }); expect(res).toEqual({ registryUrl: 'https://jfrog.company.com/artifactory', releases: [ { releaseTimestamp: '2021-07-21T20:08:00.000Z', version: '1.0.0', }, { releaseTimestamp: '2021-08-23T20:03:00.000Z', version: '1.0.1', }, { releaseTimestamp: '2021-07-21T20:09:00.000Z', version: '1.0.2', }, { releaseTimestamp: '2021-02-06T09:54:00.000Z', version: '1.0.3', }, ], }); }); it('parses real data (merge strategy with 2 registries)', async () => { const secondRegistryUrl: string = joinUrlParts( testRegistryUrl, 'production', ); httpMock .scope(testRegistryUrl) .get(getPath(testLookupName)) .reply(200, fixtureReleasesAsFiles); httpMock .scope(secondRegistryUrl) .get(getPath(testLookupName)) .reply(200, '\n