diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index e108fe8..9749695 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -9,6 +9,9 @@ jobs: publish: runs-on: ubuntu-latest + env: + EMAIL_VALIDATION_API_KEY: ${{ secrets.API_KEY }} + steps: - uses: actions/checkout@v1 diff --git a/README.md b/README.md index 75b0fe3..7a1cb60 100644 --- a/README.md +++ b/README.md @@ -133,5 +133,7 @@ To build the lib, you need to run `npm run build:lib`. ### Test -To run the test suite, you need to run: `npm run test`. +To run the test suite, you need the API key from the abstract website and you can run: + + EMAIL_VALIDATION_API_KEY=(your key here) npm run test diff --git a/test/index.test.js b/test/index.test.js index 3cbf6b0..1f578cf 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,29 +1,7 @@ import 'regenerator-runtime/runtime'; import {AbstractEmailValidation} from '../src' -const mocks = require('./mocks.js') - -const API_KEY = 'ENTER YOUR KEY'; - -function mockFetch(status, data) { - const xhrMockObj = { - open: jest.fn(), - send: jest.fn(), - setRequestHeader: jest.fn(), - onreadystatechange: jest.fn(), - readyState: 4, - status, - responseText: JSON.stringify(data), - }; - - const xhrMockClass = () => xhrMockObj; - - global.XMLHttpRequest = jest.fn().mockImplementation(xhrMockClass); - - setTimeout(() => { - xhrMockObj.onreadystatechange(); - }, 0); -} +const API_KEY = process.env.EMAIL_VALIDATION_API_KEY; test('Should throw error when no key is configured', () => { let thrownError; @@ -55,8 +33,6 @@ test('Should throw error when email is empty', () => { }); test('Request OK when everything is set up correctly', async () => { - mockFetch(200, mocks); - AbstractEmailValidation.configure(API_KEY); let response = await AbstractEmailValidation.verify('johnsmith@gmail.com') diff --git a/test/mocks.js b/test/mocks.js deleted file mode 100644 index 4123fcc..0000000 --- a/test/mocks.js +++ /dev/null @@ -1,36 +0,0 @@ -module.exports = - { - "email": "johnsmith@gmail.com", - "autocorrect": "", - "deliverability": "DELIVERABLE", - "is_valid_format": { - "value": true, - "text": "TRUE" - }, - "is_free_email": { - "value": true, - "text": "TRUE" - }, - "is_disposable_email": { - "value": false, - "text": "FALSE" - }, - "is_role_email": { - "value": false, - "text": "FALSE" - }, - "is_catchall_email": { - "value": false, - "text": "FALSE" - }, - "is_mx_found": { - "value": true, - "text": "TRUE" - }, - "is_smtp_valid": { - "value": true, - "text": "TRUE" - }, - "quality_score": 0.90, - - }