0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/modules/datasource/datasource.spec.ts
2023-11-07 15:50:29 +00:00

47 lines
1.3 KiB
TypeScript

import * as httpMock from '../../../test/http-mock';
import { partial } from '../../../test/util';
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
import { Datasource } from './datasource';
import type { GetReleasesConfig, ReleaseResult } from './types';
const exampleUrl = 'https://example.com/';
class TestDatasource extends Datasource {
constructor() {
super('test');
}
async getReleases(
getReleasesConfig: GetReleasesConfig,
): Promise<ReleaseResult | null> {
try {
await this.http.get(exampleUrl);
} catch (err) {
this.handleGenericErrors(err);
}
return Promise.resolve(null);
}
}
describe('modules/datasource/datasource', () => {
it('should throw on 429', async () => {
const testDatasource = new TestDatasource();
httpMock.scope(exampleUrl).get('/').reply(429);
await expect(
testDatasource.getReleases(partial<GetReleasesConfig>()),
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
it('should throw on statusCode >=500 && <600', async () => {
const testDatasource = new TestDatasource();
httpMock.scope(exampleUrl).get('/').reply(504);
await expect(
testDatasource.getReleases(partial<GetReleasesConfig>()),
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
});