Skip to content

Commit

Permalink
Merge pull request #46 from bradgarropy/coverage
Browse files Browse the repository at this point in the history
💯 coverage
  • Loading branch information
bradgarropy authored Jan 5, 2020
2 parents 3059869 + d5b666f commit 270a22f
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
run: npm install
- name: "🧪 test"
run: npm run test
- name: "👖 coveralls"
uses: coverallsapp/[email protected]
env:
github-token: ${{ secrets.COVERALLS_TOKEN }}
- name: "🚀 publish"
run: npm publish
env:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
# dependencies
node_modules

# tests
coverage

# secrets
.env*
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ node_modules
# build
.github

# test
# tests
src/tests
jest.config.js
coverage
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const config = {
collectCoverage: true,
coverageReporters: ["text"],
coverageReporters: ["text", "lcov"],
clearMocks: true,
verbose: true,
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "labman",
"version": "0.8.0",
"version": "0.9.0",
"description": "👨🏼‍🔬 github label manager cli",
"keywords": [
"github",
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<img alt="npm" src="https://img.shields.io/npm/v/labman.svg?color=FB3B49&style=flat-square">
</a>

<a href="https://coveralls.io/github/bradgarropy/labman-cli">
<img alt="coveralls" src="https://img.shields.io/coveralls/github/bradgarropy/labman-cli?style=flat-square">
</a>

_Command line tool for managing issue labels across GitHub repositories._

## 📦 Installation
Expand Down
74 changes: 74 additions & 0 deletions src/tests/github/labels.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const {getOctokit} = require("../../github/octokit")
const {getLabels, deleteLabels, createLabels} = require("../../github/labels")

jest.mock("../../github/octokit")

describe("labels", () => {
test("get", async () => {
const expectedLabels = [
{name: "bug"},
{name: "enhance"},
{name: "todo"},
]

getOctokit.mockImplementation(() => ({
issues: {
listLabelsForRepo: () => {
const labels = {data: expectedLabels}
return labels
},
},
}))

const labels = await getLabels("bradgarropy/label-source")

expect(labels).toEqual(expectedLabels)
})

test("delete", async () => {
getOctokit.mockImplementation(() => ({
issues: {
deleteLabel: jest.fn(),
},
}))

const actual = await deleteLabels(
["bug", "enhance", "todo"],
"bradgarropy/label-destination",
)

expect(actual).toBeUndefined()
})

test("create", async () => {
getOctokit.mockImplementation(() => ({
issues: {
createLabel: jest.fn(),
},
}))

const actual = await createLabels(
["bug", "enhance", "todo"],
"bradgarropy/label-destination",
)

expect(actual).toBeUndefined()
})

test("label exists", async () => {
getOctokit.mockImplementation(() => ({
issues: {
createLabel: () => {
throw "Label exists!"
},
},
}))

const actual = await createLabels(
["bug", "enhance", "todo"],
"bradgarropy/label-destination",
)

expect(actual).toBeUndefined()
})
})
23 changes: 23 additions & 0 deletions src/tests/github/octokit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const {createOctokit, getOctokit} = require("../../github")

describe("octokit", () => {
test("create", () => {
const octokit = createOctokit("123456")

const keys = Object.keys(octokit)

expect(keys).toContainEqual("users")
expect(keys).toContainEqual("repos")
expect(keys).toContainEqual("issues")
})

test("get", () => {
const octokit = getOctokit()

const keys = Object.keys(octokit)

expect(keys).toContainEqual("users")
expect(keys).toContainEqual("repos")
expect(keys).toContainEqual("issues")
})
})
54 changes: 54 additions & 0 deletions src/tests/github/validate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const {validToken, validRepo} = require("../../github/validate")
const {createOctokit, getOctokit} = require("../../github/octokit")

jest.mock("../../github/octokit")

describe("validate", () => {
test("valid token", async () => {
createOctokit.mockImplementation(() => ({
users: {
getAuthenticated: () => true,
},
}))

const isValidToken = await validToken("123456")
expect(isValidToken).toBeTruthy()
})

test("invalid token", async () => {
createOctokit.mockImplementation(() => ({
users: {
getAuthenticated: () => {
throw "Invalid token!"
},
},
}))

const isValidToken = await validToken("123456")
expect(isValidToken).not.toBeTruthy()
})

test("valid repo", async () => {
getOctokit.mockImplementation(() => ({
repos: {
get: () => true,
},
}))

const isValidRepo = await validRepo("bradgarropy/labman-cli")
expect(isValidRepo).toBeTruthy()
})

test("invalid repo", async () => {
getOctokit.mockImplementation(() => ({
repos: {
get: () => {
throw "Invalid token!"
},
},
}))

const isValidRepo = await validRepo("bradgarropy/invalid-repo")
expect(isValidRepo).not.toBeTruthy()
})
})

0 comments on commit 270a22f

Please sign in to comment.