renovate/test/datasource/packagist.spec.js
Rhys Arkins 01d2fb3bca
feat: datasource wrapper (#2100)
Adds a wrapper to all datasources to provide a generic purl-based interface.
2018-06-08 10:49:08 +02:00

44 lines
1.2 KiB
JavaScript

const fs = require('fs');
const datasource = require('../../lib/datasource');
const got = require('got');
jest.mock('got');
const res1 = fs.readFileSync('test/_fixtures/packagist/uploader.json');
describe('datasource/packagist', () => {
describe('getDependency', () => {
it('returns null for empty result', async () => {
got.mockReturnValueOnce({});
expect(
await datasource.getDependency('pkg:packagist/something')
).toBeNull();
});
it('returns null for 404', async () => {
got.mockImplementationOnce(() =>
Promise.reject({
statusCode: 404,
})
);
expect(
await datasource.getDependency('pkg:packagist/something')
).toBeNull();
});
it('returns null for unknown error', async () => {
got.mockImplementationOnce(() => {
throw new Error();
});
expect(
await datasource.getDependency('pkg:packagist/something')
).toBeNull();
});
it('processes real data', async () => {
got.mockReturnValueOnce({
body: JSON.parse(res1),
});
expect(
await datasource.getDependency('pkg:packagist/cristianvuolo/uploader')
).toMatchSnapshot();
});
});
});