Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanvade committed Dec 11, 2020
0 parents commit 7a3eefa
Show file tree
Hide file tree
Showing 18 changed files with 17,736 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-verison }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)

Copyright (c) 2020 Ryan Owens and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
474 changes: 474 additions & 0 deletions __tests__/event-without-a-body.json

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { getMinimumLength, getPullRequestDescription } from "../src/index";
import * as github from "@actions/github";
import { readFileSync } from "fs";
import { getDefaultSettings } from "http2";

describe("index", () => {
describe("getMinimumIndex", () => {
const name = "minLength";
it("returns the default length if one is not provided", () => {
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = "";
const minLength = getMinimumLength();
expect(minLength).toBe(1);
});

it("returns the provided min length if it is valid", () => {
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = "5";
const minLength = getMinimumLength();
expect(minLength).toBe(5);
});

it("throws an error if the provided min length is not a number", () => {
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = "a";
expect(getMinimumLength).toThrowError("minLength must be a positive number");
});


it("throws an error if the provided min length is negative", () => {
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = "-4";
expect(getMinimumLength).toThrowError("minLength must be a positive number");
});
});

describe("getPullRequestDescription", () => {
it("gets a pull request event description", () => {
process.env["GITHUB_EVENT_PATH"] = __dirname + "/valid-context.json";
github.context.payload = JSON.parse(
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' })
);
const description = getPullRequestDescription();
expect(description).toEqual("Valid Body");
});

it("throws an error if the event is not a pull_request type", () => {
process.env["GITHUB_EVENT_PATH"] = __dirname + "/wrong-event-type-context.json";
github.context.payload = JSON.parse(
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' })
);
expect(getPullRequestDescription).toThrowError("This action should only be run with Pull Request Events");
});

it("throws an error if the description is not provided", () => {
process.env["GITHUB_EVENT_PATH"] = __dirname + "/event-without-a-body.json";
github.context.payload = JSON.parse(
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' })
);
expect(getPullRequestDescription).toThrowError("This action should only be run with Pull Request Events");
});
});
})
Loading

0 comments on commit 7a3eefa

Please sign in to comment.