Coder Social home page Coder Social logo

arbitrary-gh-webhook's Introduction

Arbitrary GitHub Webhooks

arbitrary-gh-webhook on npm CI Results Code Coverage License details

QuickCheck data for GitHub Webhooks.

Status

arbitrary-gh-webhook is partially developed, with each webhook being implemented in two stages.

Stage 1 webhooks are roughly implemented, but may use generic "random strings" in some places instead of properly-formatted URLs, and might have some values that don't match (labels may belong to a different repository than the issue they are attached to).

Stage 2 will attempt to fix some of these issues by doing more post-processing of the generated data to make sure data makes sense.

Status of Each Webhook

  • ArbitraryIssuesEvent
    Stage 1 added in v0.1.0

Example Usage

Raw Webhook Testing

Want semi-random IssuesEvent webhooks to test an issueHasLabels function?

Let's setup a testing environment. You'll need JSVerify, a standard JavaScript QuickCheck library.

We'll also be using ava-verify in these examples to easily use JSVerify with the AVA test runner.

const jsc = require("jsverify");
jsc.ava = require("ava-verify");

Then grab ArbitraryIssuesEvent from this project, as well as the code you want to test (issueHasLabels):

const ArbitraryIssuesEvent = require("arbitrary-gh-webhook/hooks/ArbitraryIssuesEvent");
const issueHasLabels = require("../issueHasLabels");

Now write your tests! Thanks to JSVerify and ava-verify, they will run multiple times (by default, 100 iterations) with different test data.

jsc.ava({
    suite: "issueHasLabels returns a boolean",
  }, [
    ArbitraryIssuesEvent.build(),
  ], (t, issueData) => {
    t.is(typeof issueHasLabels(issueData), "boolean");
  }
);

Additionally, arbitrary-gh-webhook was built using ConfigurableArbitrary, which allows you to tweak how webhooks are built.

For instance, you might want to test specifically what happens if the webhook returns an issue with a specific number of labels.

You can override specific parts of the webhook, while the rest is still randomly created:

const jsc = require("jsverify");
jsc.ava = require("ava-verify");
const arrayRange = require("jsverify-array-range");

const ArbitraryIssuesEvent = require("arbitrary-gh-webhook/hooks/ArbitraryIssuesEvent");
const WebhookIssue = require("arbitrary-gh-webhook/data/WebhookIssue");
const WebhookLabelList = require("arbitrary-gh-webhook/data/WebhookLabelList");

const issueHasLabels = require("../issueHasLabels");


jsc.ava({
    suite: "issueHasLabels returns 'false' if Issue has 0 labels",
  }, [
    ArbitraryIssuesEvent.build({
      issue: WebhookIssue.build({
        labels: WebhookLabelList.build({ max: 0 }),
      }),
    }),
  ], (t, issueData) => {
    t.is(issueHasLabels(issueData), false);
  }
);

jsc.ava({
    suite: "issueHasLabels returns 'true' if Issue has 1+ labels",
  }, [
    ArbitraryIssuesEvent.build({
      issue: WebhookIssue.build({
        labels: WebhookLabelList.build({ min: 1 }),
      }),
    }),
  ], (t, issueData) => {
    t.is(issueHasLabels(issueData), true);
  }
);

Usage with SuperAgent

Requests include a built-in SuperAgent module, so you can easily send requests to a webserver.

Let's say you've got a standard Express server that should handle the IssuesEvent.

const jsc = require("jsverify");
jsc.ava = require("ava-verify");
const ArbitraryIssuesEvent = require("arbitrary-gh-webhook/hooks/ArbitraryIssuesEvent");
const request = require("supertest");

const Server = require("../index.js");

jsc.ava({
    suite: "server stores new issues",
  }, [
    ArbitraryIssuesEvent.build(),
  ], async (t, webhook) => {
    t.plan(2);
    const server = new Server();
    await request(server.app)
      .post("/hook/gh/issues")
      .use(webhook.superagent)
      .then(res => t.is(res.status, 200));
    t.true(server.hasIssue(webhook.body.issue.id));
  }
);

arbitrary-gh-webhook's People

Contributors

codelenny avatar

Watchers

 avatar  avatar

arbitrary-gh-webhook's Issues

Match users in ArbitraryIssuesEvent

Optionally make the users match in ArbitraryIssuesEvent:

  • sender
  • repository.owner (if no org provided, see #21)
  • issue.user
  • issue.assignee

(see if there's any others)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.