whatsapp-cloud-api icon indicating copy to clipboard operation
whatsapp-cloud-api copied to clipboard

I seem to always get 2 failed tests when running `npm t`

Open alfonsusac opened this issue 2 years ago • 1 comments

Hello, I tried to clone this repository to work on adding the status feature. But i cannot seem to get npm t running.

This is the result

 FAIL  dist/createBot.test.js (37.59 s)
  send functions
    √ sends text (628 ms)
    √ sends message (502 ms)
    √ sends image (580 ms)
    √ sends document (553 ms)
    √ sends audio (610 ms)
    √ sends video (522 ms)
    √ sends sticker (654 ms)
    √ sends location (517 ms)
    √ sends template (589 ms)
    √ sends contacts (508 ms)
    √ sends reply button (612 ms)
    √ sends list (540 ms)
  server functions
    √ invalid webhook token (37 ms)
    × verify webhook token (3 ms)
    √ send invalid body (16 ms)
    × listen for new messages (30014 ms)

  ● server functions › verify webhook token

    connect ECONNREFUSED 127.0.0.1:80



  ● server functions › listen for new messages

    connect ECONNREFUSED 127.0.0.1:80



  ● server functions › listen for new messages

    connect ECONNREFUSED 127.0.0.1:80



  ● server functions › listen for new messages

    connect ECONNREFUSED 127.0.0.1:80



  ● server functions › listen for new messages

    connect ECONNREFUSED 127.0.0.1:80



  ● server functions › listen for new messages

    connect ECONNREFUSED 127.0.0.1:80



  ● server functions › listen for new messages

    connect ECONNREFUSED 127.0.0.1:80



  ● server functions › listen for new messages

    connect ECONNREFUSED 127.0.0.1:80



  ● server functions › listen for new messages

    connect ECONNREFUSED 127.0.0.1:80



  ● server functions › listen for new messages

    connect ECONNREFUSED 127.0.0.1:80



  ● server functions › listen for new messages

    connect ECONNREFUSED 127.0.0.1:80



  ● server functions › listen for new messages

    thrown: "Exceeded timeout of 30000 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

      265 |
      266 |   // eslint-disable-next-line no-async-promise-executor
    > 267 |   test('listen for new messages', (): Promise<void> => new Promise(async (resolve, reject) => {
          |   ^
      268 |     const payloads = [
      269 |       {
      270 |         from: '12345678',

      at src/createBot.test.ts:267:3
      at Object.<anonymous> (src/createBot.test.ts:194:1)

Test Suites: 1 failed, 1 total
Tests:       2 failed, 14 passed, 16 total
Snapshots:   0 total
Time:        37.783 s, estimated 39 s
Ran all test suites matching /dist/i.

I tried using various webhook_path but it seem to keep getting 403 (forbidden) Here is my webhook path

WEBHOOK_PATH="http://localhost:3000/webhook/whatsapp"

I also tried manually using rest api

GET http://localhost:3000/webhook/whatsapp?hub.mode=subscribe&hub.challenge=random&hub.verify_token=41ESBjuy5E

But gets 403 Forbidden instead.

I am running on Windows 10.

I also want to know what WEBHOOK_PATH do you use?

alfonsusac avatar Oct 25 '22 07:10 alfonsusac

Hi @alfonsusac,

It seems that your tests are trying to access the server via port 80 instead of port 3000, ie 127.0.0.1:80, which is why the tests timeout since the server is unreachable. Are you setting the port somewhere?

Also, have you set up the .env file correctly? Please ensure the verify token you're passing in via the url is the same as the one in the .env file, and try seeing if you will still get a 403 error.

GET http://localhost:3000/webhook/whatsapp?hub.mode=subscribe&hub.challenge=random&hub.verify_token=41ESBjuy5E
FROM_PHONE_NUMBER_ID=""
ACCESS_TOKEN=""
VERSION=""
TO=""
WEBHOOK_VERIFY_TOKEN="41ESBjuy5E"
WEBHOOK_PATH="/webhook/whatsapp"

See above also on how I set the webhook path.

tawn33y avatar Oct 25 '22 18:10 tawn33y

@alfonsusac did this work?

tawn33y avatar Nov 29 '22 02:11 tawn33y

Yes it worked, if it had not worked, I would not be able to ask for pull request

alfonsusac avatar Dec 02 '22 07:12 alfonsusac