Skip to content

Commit

Permalink
feat(package-information): add package information methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jaebradley committed Apr 24, 2018
1 parent b66a750 commit b103814
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const search = ({
from,
size,
},
})
}).then(response => response.data)
);

const getSuggestions = ({
Expand All @@ -61,11 +61,20 @@ const getSuggestions = ({
q: terms.join('+'),
size,
},
})
}).then(response => response.data)
);

const getPackageInformation = packageName => axios.get(`${NPMS_API_BASE_URL}/package/${packageName}`).then(response => response.data);

const getPackagesInformation = packageNames => axios.post(
`${NPMS_API_BASE_URL}/package/mget`,
packageNames,
).then(response => response.data);

export {
search,
getSuggestions,
getPackageInformation,
getPackagesInformation,
PACKAGE_TYPES,
};
24 changes: 22 additions & 2 deletions src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
import {
search,
getSuggestions,
getPackageInformation,
getPackagesInformation,
} from './';

describe('integration test', () => {
describe('#search', () => {
it('should search with term "fruit"', async () => {
const response = await search({ terms: ['fruit'] });
console.log(response);
expect(response).toBeDefined();
});
});

describe('#getSuggestions', () => {
it('should get suggestions for term "fruit"', async () => {
const response = await getSuggestions({ terms: ['fruit'] });
console.log(response);
expect(response).toBeDefined();
});
});

describe('#getPackageInformation', () => {
it('should get package information for fruit', async () => {
const response = await getPackageInformation('fruit');
expect(response).toBeDefined();
});
});

describe('#getPackagseInformation', () => {
it('should get package information for react, react-dom, and prop-types', async () => {
try {
const response = await getPackagesInformation(['react', 'react-dom', 'prop-types']);
console.log(response);
} catch (e) {
console.log(e);
}
});
});
});

0 comments on commit b103814

Please sign in to comment.