2018-06-08 04:15:13 +00:00
|
|
|
const fs = require('fs');
|
2018-06-08 08:49:08 +00:00
|
|
|
const datasource = require('../../lib/datasource');
|
2018-06-08 04:15:13 +00:00
|
|
|
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({});
|
2018-06-08 08:49:08 +00:00
|
|
|
expect(
|
|
|
|
await datasource.getDependency('pkg:packagist/something')
|
|
|
|
).toBeNull();
|
2018-06-08 04:15:13 +00:00
|
|
|
});
|
|
|
|
it('returns null for 404', async () => {
|
|
|
|
got.mockImplementationOnce(() =>
|
|
|
|
Promise.reject({
|
|
|
|
statusCode: 404,
|
|
|
|
})
|
|
|
|
);
|
2018-06-08 08:49:08 +00:00
|
|
|
expect(
|
|
|
|
await datasource.getDependency('pkg:packagist/something')
|
|
|
|
).toBeNull();
|
2018-06-08 04:15:13 +00:00
|
|
|
});
|
|
|
|
it('returns null for unknown error', async () => {
|
|
|
|
got.mockImplementationOnce(() => {
|
|
|
|
throw new Error();
|
|
|
|
});
|
2018-06-08 08:49:08 +00:00
|
|
|
expect(
|
|
|
|
await datasource.getDependency('pkg:packagist/something')
|
|
|
|
).toBeNull();
|
2018-06-08 04:15:13 +00:00
|
|
|
});
|
|
|
|
it('processes real data', async () => {
|
|
|
|
got.mockReturnValueOnce({
|
|
|
|
body: JSON.parse(res1),
|
|
|
|
});
|
|
|
|
expect(
|
2018-06-08 08:49:08 +00:00
|
|
|
await datasource.getDependency('pkg:packagist/cristianvuolo/uploader')
|
2018-06-08 04:15:13 +00:00
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|