Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running probot.receive in tests throws error #954

Closed
brainchest opened this issue Jun 28, 2019 · 4 comments

Comments

@brainchest
Copy link

commented Jun 28, 2019

Bug Report

Current Behavior
Starting out with testing in probot I tried to use the test according to the documentation to get up and running.

/* eslint-env mocha */
const nock = require('nock');
const fn = require('..');
const { Probot } = require('probot');
const fixtureIssueCreated = require('./fixtures/issues.opened');
const issueCreatedBody = { body: 'Thanks for opening this issue!' };

/**
 * @typedef {import('jest')}
 */
describe('fn-server', () => {
  let probot;

  beforeEach(() => {
    probot = new Probot({});
    const app = probot.load(fn);

    // just return a test token
    app.app = () => 'test';
  });

  test('creates a passing check', async () => {
    // Test that we correctly return a test token
    nock('https://api.github.com')
      .post('/app/installations/2/access_tokens')
      .reply(200, { token: 'test' });

    // Test that a commented is posted
    nock('https://api.github.com')
      .post('/repos/hiimbex/testing-things/issues/1/comments', (body) => {
        expect(body).toMatchObject(issueCreatedBody);
        return true;
      })
      .reply(200);

    // Receive a webhook event
    console.log(probot);
    await probot.receive({ name: 'issues', fixtureIssueCreated });
  });
});

However, the line probot.receive throws

● fn-server › creates a passing check

    TypeError: Cannot read property 'action' of undefined

      47 |     // Receive a webhook event
      48 |     console.log(probot);
    > 49 |     await probot.receive({ name: 'issues', fixtureIssueCreated });
         |                  ^
      50 |   });
      51 | });
      52 |

      at Application.<anonymous> (node_modules/probot/src/application.ts:79:58)
      at step (node_modules/probot/lib/application.js:40:23)
      at Object.next (node_modules/probot/lib/application.js:21:53)
      at node_modules/probot/lib/application.js:15:71
      at Object.<anonymous>.__awaiter (node_modules/probot/lib/application.js:11:12)
      at Application.Object.<anonymous>.Application.receive (node_modules/probot/lib/application.js:95:16)
      at node_modules/probot/src/index.ts:77:49
          at Array.map (<anonymous>)
      at Probot.Object.<anonymous>.Probot.receive (node_modules/probot/src/index.ts:77:34)
      at Object.receive (test/index.test.js:49:18)

The fixture is

{
  "action": "opened",
  "issue": {
    "number": 1,
    "user": {
      "login": "hiimbex"
    }
  },
  "repository": {
    "name": "testing-things",
    "owner": {
      "login": "hiimbex"
    }
  }
}

It's probably something obvious but I can't find the issue. Input for this example is https://probot.github.io/docs/testing/

Expected behavior/code
Test succeeds

Environment

  • Probot version(s): [e.g. v7.2.0]
  • Node/npm version: [e.g. Node 10.16.0/npm 6.9.0]
  • OS: [e.g. OSX 10.14]

Possible Solution
not sure

Additional context/Screenshots

@issue-label-bot issue-label-bot bot added the bug 🐞 label Jun 28, 2019

@welcome

This comment has been minimized.

Copy link

commented Jun 28, 2019

Thanks for opening this issue. A contributor should be by to give feedback soon. In the meantime, please check out the contributing guidelines and explore other ways you can get involved.

@issue-label-bot

This comment was marked as resolved.

Copy link

commented Jun 28, 2019

Issue-Label Bot is automatically applying the label bug 🐞 to this issue, with a confidence of 0.96. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@gr2m

This comment has been minimized.

Copy link
Contributor

commented Jun 28, 2019

can you try

await probot.receive({ name: 'issues', payload: fixtureIssueCreated });

@gr2m gr2m added support and removed bug 🐞 labels Jun 28, 2019

@brainchest

This comment has been minimized.

Copy link
Author

commented Jun 28, 2019

@gr2m Oh no. Such an easy fix. I should have found it by myself. Thank You!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.