tejashah88 / node-meraki-dashboard

A modern node.js client library for using the Meraki Dashboard API.
MIT License
21 stars 4 forks source link

API coverage error? #14

Open bvisan opened 4 years ago

bvisan commented 4 years ago

Was unable to run the API coverage tool, had an unhandled promise error. Followed the setup & testing exactly, but some tests failed.

[bogdanvisan node-meraki-dashboard (master)]$ npm test

> node-meraki-dashboard@3.0.0 test /Users/bogdanvisan/node-meraki-dashboard
> mocha test/**/*.js

  utils/code-analyzer.js
    ✓ should have a defined method and path

  utils/retrieve-api-routes.js
    retrieving API endpoints
      1) should successfully retrieve the official API docs
    testing structure of retrieved resources
      official documentation
        2) should have the following fields: [group, path, has_params, method, description, alt_path, params]

  basic structure of client library
    ✓ should have a constructor that is a normal function
    ✓ should return an object when you initialize it
    ✓ should fail if not given anything (null or undefined) for the api key
    ✓ should fail if not given a string for the api key
    ✓ should fail if given a string with various whitespace

  code structure analysis tests
    ✓ should have valid REST methods implemented
    ✓ should have the path formed properly, with path parameters isolated from normal words

  8 passing (1s)
  2 failing

  1) utils/retrieve-api-routes.js
       retrieving API endpoints
         should successfully retrieve the official API docs:
     AssertionError: expected promise to be fulfilled but it was rejected with 'SyntaxError: Unexpected token \' in JSON at position 1'
      at assertIfNotNegated (node_modules/chai-as-promised/lib/chai-as-promised.js:68:19)
      at /Users/bogdanvisan/node-meraki-dashboard/node_modules/chai-as-promised/lib/chai-as-promised.js:101:17
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at async Promise.all (index 0)

  2) utils/retrieve-api-routes.js
       testing structure of retrieved resources
         official documentation
           should have the following fields: [group, path, has_params, method, description, alt_path, params]:
     AssertionError: expected promise to be fulfilled but it was rejected with 'SyntaxError: Unexpected token \' in JSON at position 1'
      at assertIfNotNegated (node_modules/chai-as-promised/lib/chai-as-promised.js:68:19)
      at /Users/bogdanvisan/node-meraki-dashboard/node_modules/chai-as-promised/lib/chai-as-promised.js:101:17
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at async Promise.all (index 0)

npm ERR! Test failed.  See above for more details.

Tried to run api-coverage:

[bogdanvisan node-meraki-dashboard (master)]$ npm run api-coverage

> node-meraki-dashboard@3.0.0 api-coverage /Users/bogdanvisan/node-meraki-dashboard
> node ./tools/api-coverage.js

Fetching endpoints...
(node:88566) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token ' in JSON at position 1
    at JSON.parse (<anonymous>)
    at /Users/bogdanvisan/node-meraki-dashboard/utils/retrieve-api-routes.js:16:35
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:88566) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:88566) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[bogdanvisan node-meraki-dashboard (master)]$ 

I added this bit to get some more info in the utils/retrieve-api-routes.js

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});

I received this error which had more detail

[bogdanvisan node-meraki-dashboard (master)]$ npm run api-coverage

> node-meraki-dashboard@3.0.0 api-coverage /Users/bogdanvisan/node-meraki-dashboard
> node ./tools/api-coverage.js

Fetching endpoints...
Unhandled Rejection at: Promise Promise {
  <rejected> SyntaxError: Unexpected token ' in JSON at position 1
      at JSON.parse (<anonymous>)
      at /Users/bogdanvisan/node-meraki-dashboard/utils/retrieve-api-routes.js:20:35
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
} reason: SyntaxError: Unexpected token ' in JSON at position 1
    at JSON.parse (<anonymous>)
    at /Users/bogdanvisan/node-meraki-dashboard/utils/retrieve-api-routes.js:20:35
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
[bogdanvisan node-meraki-dashboard (master)]$ 

Tried to troubleshoot, looks like semiOfficial has this result. Unfortunately could not get very far :(

[
  "['PUBHUB_CONTENT_URL']",
  "['PUBHUB_URL_PREFIX']",
  "['PUBHUB_TYPE']",
  "['MetaDataAPI']",
  "['AUTH_URL']"
]
tejashah88 commented 4 years ago

@bvisan Huh, seems like they've completely revamped their website. The API coverage tool used to pull all the available routes from a JSON object embedded in their old website, and since it's disappeared, it's broken as of now. Also, I don't have much time to fix it these days as I'm back in college.

bvisan commented 4 years ago

No worries, that makes sense. Thank you!