2020-06-18 17:03:40 +00:00
|
|
|
import { getPkgReleases } from '..';
|
2022-03-03 09:35:26 +00:00
|
|
|
import { Fixtures } from '../../../../test/fixtures';
|
|
|
|
import * as httpMock from '../../../../test/http-mock';
|
2022-07-22 04:49:05 +00:00
|
|
|
import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages';
|
2021-06-08 15:20:39 +00:00
|
|
|
import { GalaxyDatasource } from '.';
|
2020-02-13 10:50:39 +00:00
|
|
|
|
2023-10-16 16:57:45 +00:00
|
|
|
const baseUrl = 'https://galaxy.ansible.com/';
|
2020-02-13 10:50:39 +00:00
|
|
|
|
2022-03-03 09:35:26 +00:00
|
|
|
describe('modules/datasource/galaxy/index', () => {
|
2020-04-04 06:53:52 +00:00
|
|
|
describe('getReleases', () => {
|
2020-02-13 10:50:39 +00:00
|
|
|
it('returns null for empty result', async () => {
|
2020-06-14 04:50:18 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/api/v1/roles/?owner__username=non_existent_crate&name=undefined')
|
|
|
|
.reply(200);
|
2020-02-13 10:50:39 +00:00
|
|
|
expect(
|
2021-06-08 15:20:39 +00:00
|
|
|
await getPkgReleases({
|
|
|
|
datasource: GalaxyDatasource.id,
|
2023-02-21 05:54:16 +00:00
|
|
|
packageName: 'non_existent_crate',
|
2023-11-07 15:50:29 +00:00
|
|
|
}),
|
2020-02-13 10:50:39 +00:00
|
|
|
).toBeNull();
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-02-13 10:50:39 +00:00
|
|
|
it('returns null for missing fields', async () => {
|
2020-06-14 04:50:18 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/api/v1/roles/?owner__username=non_existent_crate&name=undefined')
|
|
|
|
.reply(200, undefined);
|
2020-02-13 10:50:39 +00:00
|
|
|
expect(
|
2021-06-08 15:20:39 +00:00
|
|
|
await getPkgReleases({
|
|
|
|
datasource: GalaxyDatasource.id,
|
2023-02-21 05:54:16 +00:00
|
|
|
packageName: 'non_existent_crate',
|
2023-11-07 15:50:29 +00:00
|
|
|
}),
|
2020-02-13 10:50:39 +00:00
|
|
|
).toBeNull();
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-03-12 11:48:57 +00:00
|
|
|
it('returns null for empty list', async () => {
|
2020-06-14 04:50:18 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/api/v1/roles/?owner__username=non_existent_crate&name=undefined')
|
|
|
|
.reply(200, '\n');
|
2020-03-12 11:48:57 +00:00
|
|
|
expect(
|
2021-06-08 15:20:39 +00:00
|
|
|
await getPkgReleases({
|
|
|
|
datasource: GalaxyDatasource.id,
|
2023-02-21 05:54:16 +00:00
|
|
|
packageName: 'non_existent_crate',
|
2023-11-07 15:50:29 +00:00
|
|
|
}),
|
2020-03-12 11:48:57 +00:00
|
|
|
).toBeNull();
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-03-12 11:48:57 +00:00
|
|
|
it('returns null for 404', async () => {
|
2020-06-14 04:50:18 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/api/v1/roles/?owner__username=some_crate&name=undefined')
|
|
|
|
.reply(404);
|
2020-06-18 17:03:40 +00:00
|
|
|
expect(
|
2021-06-08 15:20:39 +00:00
|
|
|
await getPkgReleases({
|
|
|
|
datasource: GalaxyDatasource.id,
|
2023-02-21 05:54:16 +00:00
|
|
|
packageName: 'some_crate',
|
2023-11-07 15:50:29 +00:00
|
|
|
}),
|
2020-06-18 17:03:40 +00:00
|
|
|
).toBeNull();
|
2020-03-12 11:48:57 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-03-12 11:48:57 +00:00
|
|
|
it('returns null for unknown error', async () => {
|
2020-06-14 04:50:18 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/api/v1/roles/?owner__username=some_crate&name=undefined')
|
|
|
|
.replyWithError('some unknown error');
|
2020-06-18 17:03:40 +00:00
|
|
|
expect(
|
2021-06-08 15:20:39 +00:00
|
|
|
await getPkgReleases({
|
|
|
|
datasource: GalaxyDatasource.id,
|
2023-02-21 05:54:16 +00:00
|
|
|
packageName: 'some_crate',
|
2023-11-07 15:50:29 +00:00
|
|
|
}),
|
2020-06-18 17:03:40 +00:00
|
|
|
).toBeNull();
|
2020-03-12 11:48:57 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-02-13 10:50:39 +00:00
|
|
|
it('processes real data', async () => {
|
2020-06-14 04:50:18 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/api/v1/roles/?owner__username=yatesr&name=timezone')
|
2023-10-17 13:04:00 +00:00
|
|
|
.reply(200, Fixtures.get('timezone.json'));
|
2020-06-18 17:03:40 +00:00
|
|
|
const res = await getPkgReleases({
|
2021-06-08 15:20:39 +00:00
|
|
|
datasource: GalaxyDatasource.id,
|
2023-02-21 05:54:16 +00:00
|
|
|
packageName: 'yatesr.timezone',
|
2020-06-18 17:03:40 +00:00
|
|
|
});
|
2020-02-13 10:50:39 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
expect(res).not.toBeNull();
|
|
|
|
expect(res).toBeDefined();
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2024-09-23 06:43:56 +00:00
|
|
|
it('handles multiple results when one user matches exactly', async () => {
|
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/api/v1/roles/?owner__username=datadog&name=datadog')
|
|
|
|
.reply(200, Fixtures.get('datadog.json'));
|
|
|
|
const res = await getPkgReleases({
|
|
|
|
datasource: GalaxyDatasource.id,
|
|
|
|
packageName: 'datadog.datadog',
|
|
|
|
});
|
|
|
|
expect(res).not.toBeNull();
|
|
|
|
expect(res?.releases).toHaveLength(11);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('rejects multiple results when no user matches exactly', async () => {
|
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/api/v1/roles/?owner__username=nope&name=nope')
|
|
|
|
.reply(200, Fixtures.get('datadog.json'));
|
|
|
|
const res = await getPkgReleases({
|
|
|
|
datasource: GalaxyDatasource.id,
|
|
|
|
packageName: 'nope.nope',
|
|
|
|
});
|
|
|
|
expect(res).toBeNull();
|
|
|
|
});
|
|
|
|
|
2020-02-13 10:50:39 +00:00
|
|
|
it('return null if searching random username and project name', async () => {
|
2020-06-14 04:50:18 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/api/v1/roles/?owner__username=foo&name=bar')
|
2022-01-23 21:23:54 +00:00
|
|
|
.reply(200, Fixtures.get('empty'));
|
2021-06-08 15:20:39 +00:00
|
|
|
const res = await getPkgReleases({
|
|
|
|
datasource: GalaxyDatasource.id,
|
2023-02-21 05:54:16 +00:00
|
|
|
packageName: 'foo.bar',
|
2021-06-08 15:20:39 +00:00
|
|
|
});
|
2020-02-13 10:50:39 +00:00
|
|
|
expect(res).toBeNull();
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-03-07 13:16:41 +00:00
|
|
|
it('throws for 5xx', async () => {
|
2020-06-14 04:50:18 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/api/v1/roles/?owner__username=some_crate&name=undefined')
|
|
|
|
.reply(502);
|
2022-07-22 04:49:05 +00:00
|
|
|
await expect(
|
|
|
|
getPkgReleases({
|
2021-06-08 15:20:39 +00:00
|
|
|
datasource: GalaxyDatasource.id,
|
2023-02-21 05:54:16 +00:00
|
|
|
packageName: 'some_crate',
|
2023-11-07 15:50:29 +00:00
|
|
|
}),
|
2022-07-22 04:49:05 +00:00
|
|
|
).rejects.toThrow(EXTERNAL_HOST_ERROR);
|
2020-03-07 13:16:41 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-03-07 13:16:41 +00:00
|
|
|
it('throws for 404', async () => {
|
2020-06-14 04:50:18 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/api/v1/roles/?owner__username=foo&name=bar')
|
|
|
|
.reply(404);
|
2021-06-08 15:20:39 +00:00
|
|
|
const res = await getPkgReleases({
|
|
|
|
datasource: GalaxyDatasource.id,
|
2023-02-21 05:54:16 +00:00
|
|
|
packageName: 'foo.bar',
|
2021-06-08 15:20:39 +00:00
|
|
|
});
|
2020-06-14 04:50:18 +00:00
|
|
|
expect(res).toBeNull();
|
2020-03-07 13:16:41 +00:00
|
|
|
});
|
2020-02-13 10:50:39 +00:00
|
|
|
});
|
|
|
|
});
|