renovate/lib/modules/datasource/adoptium-java/index.spec.ts
Rhys Arkins dca3418bbd refactor: lib/modules (#14488)
Moves datasource, manager, platform and versioning code from lib/ into new lib/modules/

BREAKING CHANGE: External tools must update paths to datasource, manager, platform and versioning
2022-03-04 09:04:02 +01:00

116 lines
3.2 KiB
TypeScript

import { getPkgReleases } from '..';
import { Fixtures } from '../../../../test/fixtures';
import * as httpMock from '../../../../test/http-mock';
import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages';
import { range } from '../../../util/range';
import { datasource, defaultRegistryUrl, pageSize } from './common';
function getPath(page: number, imageType = 'jdk'): string {
return `/v3/info/release_versions?page_size=${pageSize}&image_type=${imageType}&project=jdk&release_type=ga&sort_method=DATE&sort_order=DESC&vendor=adoptium&page=${page}`;
}
const depName = 'java';
describe('modules/datasource/adoptium-java/index', () => {
describe('getReleases', () => {
it('throws for error', async () => {
httpMock
.scope(defaultRegistryUrl)
.get(getPath(0))
.replyWithError('error');
await expect(
getPkgReleases({
datasource,
depName,
})
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
it('returns null for 404', async () => {
httpMock.scope(defaultRegistryUrl).get(getPath(0)).reply(404);
expect(
await getPkgReleases({
datasource,
depName,
})
).toBeNull();
});
it('returns null for empty result', async () => {
httpMock.scope(defaultRegistryUrl).get(getPath(0)).reply(200, {});
expect(
await getPkgReleases({
datasource,
depName,
})
).toBeNull();
});
it('returns null for empty 200 OK', async () => {
httpMock
.scope(defaultRegistryUrl)
.get(getPath(0))
.reply(200, { versions: [] });
expect(
await getPkgReleases({
datasource,
depName,
})
).toBeNull();
});
it('throws for 5xx', async () => {
httpMock.scope(defaultRegistryUrl).get(getPath(0)).reply(502);
await expect(
getPkgReleases({
datasource,
depName,
})
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
it('processes real data', async () => {
httpMock
.scope(defaultRegistryUrl)
.get(getPath(0))
.reply(200, Fixtures.get('page.json'));
const res = await getPkgReleases({
datasource,
depName,
});
expect(res).toMatchSnapshot();
expect(res?.releases).toHaveLength(3);
});
it('processes real data (jre)', async () => {
httpMock
.scope(defaultRegistryUrl)
.get(getPath(0, 'jre'))
.reply(200, Fixtures.get('jre.json'));
const res = await getPkgReleases({
datasource,
depName: 'java-jre',
});
expect(res).toMatchSnapshot();
expect(res?.releases).toHaveLength(2);
});
it('pages', async () => {
const versions = [...range(1, 50)].map((v: number) => ({
semver: `1.${v}.0`,
}));
httpMock
.scope(defaultRegistryUrl)
.get(getPath(0))
.reply(200, { versions })
.get(getPath(1))
.reply(404);
const res = await getPkgReleases({
datasource,
depName,
});
expect(res).toMatchSnapshot();
expect(res?.releases).toHaveLength(50);
});
});
});