Skip to content

Commit

Permalink
Add Mocha Testing and Github Testing + Publish Actions (#12)
Browse files Browse the repository at this point in the history
* tests done

* more files

* add action for testing

* add on commands

* add publish

* run test on pull request

* update version for release

* publish on main branch, manually

* remove branch in publish

* run publish on release

* add to tests

* add testing package

* revert badge
  • Loading branch information
vvillait88 authored Mar 16, 2022
1 parent 7b7d5b3 commit e6bdb13
Show file tree
Hide file tree
Showing 9 changed files with 674 additions and 24 deletions.
File renamed without changes.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
env: {
browser: true,
es6: true,
jest: true,
},
extends: [
'airbnb'
Expand All @@ -17,6 +18,7 @@ module.exports = {
sourceType: 'module'
},
rules: {
'import/extensions': ['off', 'never', {ignorePackages: true} ],
'react/prop-types': 0,
'prefer-regex-literals': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Publish Package

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: yarn
- run: yarn run test
env:
PDL_API_KEY: ${{secrets.PDL_API_KEY}}

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: yarn
- run: yarn run pub
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
16 changes: 16 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test Package

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: yarn
- run: yarn run test
env:
PDL_API_KEY: ${{secrets.PDL_API_KEY}}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A tiny, universal JS client for the People Data Labs API.
<a href="https://unpkg.com/peopledatalabs"><img src="https://img.badgesize.io/https://unpkg.com/peopledatalabs/dist/index.cjs?compression=brotli" alt="brotli size"></a>
</div>

#
#
This is a simple JavaScript client library to access the various API endpoints provided by [People Data Labs](https://www.peopledatalabs.com/).

This library bundles up PDL API requests into simple function calls, making it easy to integrate into your projects. You can use the various [API endpoints](#endpoints) to access up-to-date, real-world data from our massive [Person](https://docs.peopledatalabs.com/docs/stats) and [Company](https://docs.peopledatalabs.com/docs/company-stats) Datasets.
Expand Down
2 changes: 1 addition & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dotenv from 'dotenv';

import PDLJS from 'peopledatalabs';

dotenv.config({ path: './.env.local' });
dotenv.config({ path: '../.env.local' });

const PDLJSClient = new PDLJS({ apiKey: process.env.PDL_API_KEY });

Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "peopledatalabs",
"version": "1.1.13",
"version": "1.1.14",
"description": "An universal client for the People Data Labs API",
"type": "module",
"main": "dist/index.cjs",
Expand All @@ -10,6 +10,8 @@
"scripts": {
"build": "rm -rf dist && microbundle",
"dev": "microbundle watch",
"test": "yarn run build && yarn run mocha",
"mocha": "mocha --recursive './tests/**/*.js'",
"pub": "yarn run build && yarn publish"
},
"repository": {
Expand All @@ -36,14 +38,18 @@
},
"homepage": "https://github.com/peopledatalabs/peopledatalabs-js#readme",
"devDependencies": {
"chai": "^4.3.6",
"dotenv": "^16.0.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^1.7.0",
"eslint-plugin-unused-imports": "^2.0.0",
"microbundle": "^0.14.2"
"esm": "^3.2.25",
"microbundle": "^0.14.2",
"mocha": "^9.2.2"
},
"dependencies": {
"axios": "^0.24.0"
Expand Down
226 changes: 226 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import { expect } from 'chai';
import dotenv from 'dotenv';
import PDLJS from '../dist/index.m.js';

dotenv.config({ path: './.env.local' });

const PDLJSClient = new PDLJS({ apiKey: process.env.PDL_API_KEY });

const phone = '4155688415';

const records = {
requests: [
{
params: {
profile: ['linkedin.com/in/seanthorne'],
},
},
{
params: {
profile: ['linkedin.com/in/randrewn'],
},
},
],
};

const personSQL = "SELECT * FROM person WHERE location_country='mexico' AND job_title_role='health'AND phone_numbers IS NOT NULL;";

const personElastic = {
query: {
bool: {
must: [
{ term: { location_country: 'mexico' } },
{ term: { job_title_role: 'health' } },
{ exists: { field: 'phone_numbers' } },
],
},
},
};

const personID = 'qEnOZ5Oh0poWnQ1luFBfVw_0000';

const website = 'peopledatalabs.com';

const companySQL = "SELECT * FROM company WHERE tags='big data' AND industry='financial services' AND location.country='united states';";

const companyElastic = {
query: {
bool: {
must: [
{ term: { website: 'peopledatalabs.com' } },
],
},
},
};

const autocomplete = {
field: 'skill',
text: 'c++',
size: 10,
};

const company = { name: 'peopledatalabs' };

const location = { location: '455 Market Street, San Francisco, California 94105, US' };

const school = { name: 'university of oregon' };

describe('Person Enrichment', () => {
it(`Should Return Person Record for ${phone}`, (done) => {
PDLJSClient.person.enrichment({ phone }).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});
});

describe('Person Identify', () => {
it(`Should Return Person Record for ${phone}`, (done) => {
PDLJSClient.person.identify({ phone: '4155688415' }).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
});
});
});

describe('Person Bulk', () => {
it(`Should Return Person Records for ${JSON.stringify(records)}`, (done) => {
PDLJSClient.person.bulk(records).then((data) => {
expect(data.length).to.equal(2);
expect(data).to.be.a('array');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});
});

describe('Person Search', () => {
it(`Should Return Person Records for ${personSQL}`, (done) => {
PDLJSClient.person.search.sql({ searchQuery: personSQL, size: 10 }).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});

it(`Should Return Person Records for ${JSON.stringify(personElastic)}`, (done) => {
PDLJSClient.person.search.elastic({ searchQuery: personElastic, size: 10 }).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});
});

describe('Person Retrieve', () => {
it(`Should Return Person Record for ${personID}`, (done) => {
PDLJSClient.person.retrieve(personID).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});
});

describe('Company Enrichment', () => {
it(`Should Return Company Record for ${website}`, (done) => {
PDLJSClient.company.enrichment({ website }).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});
});

describe('Company Search', () => {
it(`Should Return Company Records for ${companySQL}`, (done) => {
PDLJSClient.company.search.sql({ searchQuery: companySQL, size: 10 }).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});

it(`Should Return Company Records for ${JSON.stringify(companyElastic)}`, (done) => {
PDLJSClient.company.search.elastic({ searchQuery: companyElastic, size: 10 }).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});
});

describe('Autocomplete', () => {
it(`Should Return Autocomplete Records for ${JSON.stringify(autocomplete)}`, (done) => {
PDLJSClient.autocomplete(autocomplete).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});
});

describe('Cleaner APIs', () => {
it(`Should Return Company Cleaner Records for ${JSON.stringify(company)}`, (done) => {
PDLJSClient.company.cleaner(company).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});

it(`Should Return Location Cleaner Records for ${JSON.stringify(location)}`, (done) => {
PDLJSClient.location.cleaner(location).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});

it(`Should Return School Cleaner Records for ${JSON.stringify(school)}`, (done) => {
PDLJSClient.school.cleaner(school).then((data) => {
expect(data.status).to.equal(200);
expect(data).to.be.a('object');
done();
}).catch((error) => {
expect(error).to.be.a('string');
done();
});
});
});
Loading

0 comments on commit e6bdb13

Please sign in to comment.