Fixes #26 Update dependencies and fix octokit types
Fixes #27 Add inputs for specifying owner and repo
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Action } from "../src/Action";
|
||||
import { Artifact } from "../src/Artifact";
|
||||
import { Inputs } from "../src/Inputs";
|
||||
import { Releases } from "../src/Releases";
|
||||
import { ArtifactUploader } from "../src/ArtifactUploader";
|
||||
import {Action} from "../src/Action";
|
||||
import {Artifact} from "../src/Artifact";
|
||||
import {Inputs} from "../src/Inputs";
|
||||
import {Releases} from "../src/Releases";
|
||||
import {ArtifactUploader} from "../src/ArtifactUploader";
|
||||
|
||||
const createMock = jest.fn()
|
||||
const deleteMock = jest.fn()
|
||||
@@ -51,7 +51,7 @@ describe("Action", () => {
|
||||
|
||||
it('creates release if no release exists to update', async () => {
|
||||
const action = createAction(true, true)
|
||||
const error = { status: 404 }
|
||||
const error = {status: 404}
|
||||
getMock.mockRejectedValue(error)
|
||||
|
||||
await action.perform()
|
||||
@@ -62,11 +62,11 @@ describe("Action", () => {
|
||||
|
||||
it('creates release if no draft releases', async () => {
|
||||
const action = createAction(true, true)
|
||||
const error = { status: 404 }
|
||||
const error = {status: 404}
|
||||
getMock.mockRejectedValue(error)
|
||||
listMock.mockResolvedValue({
|
||||
data: [
|
||||
{ id: id, draft: false, tag_name: tag }
|
||||
{id: id, draft: false, tag_name: tag}
|
||||
]
|
||||
})
|
||||
|
||||
@@ -159,12 +159,12 @@ describe("Action", () => {
|
||||
|
||||
it('updates draft release', async () => {
|
||||
const action = createAction(true, true)
|
||||
const error = { status: 404 }
|
||||
const error = {status: 404}
|
||||
getMock.mockRejectedValue(error)
|
||||
listMock.mockResolvedValue({
|
||||
data: [
|
||||
{ id: 123, draft: false, tag_name: tag },
|
||||
{ id: id, draft: true, tag_name: tag }
|
||||
{id: 123, draft: false, tag_name: tag},
|
||||
{id: id, draft: true, tag_name: tag}
|
||||
]
|
||||
})
|
||||
|
||||
@@ -244,8 +244,10 @@ describe("Action", () => {
|
||||
createdReleaseName: createName,
|
||||
commit: commit,
|
||||
draft: draft,
|
||||
owner: "owner",
|
||||
prerelease: prerelease,
|
||||
replacesArtifacts: replacesArtifacts,
|
||||
repo: "repo",
|
||||
tag: tag,
|
||||
token: token,
|
||||
updatedReleaseBody: updateBody,
|
||||
|
||||
@@ -164,6 +164,18 @@ describe('Inputs', () => {
|
||||
expect(inputs.draft).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('owner', () => {
|
||||
it('returns owner from context', function () {
|
||||
process.env.GITHUB_REPOSITORY = "owner/repo"
|
||||
mockGetInput.mockReturnValue("")
|
||||
expect(inputs.owner).toBe("owner")
|
||||
});
|
||||
it('returns owner from inputs', function () {
|
||||
mockGetInput.mockReturnValue("owner")
|
||||
expect(inputs.owner).toBe("owner")
|
||||
});
|
||||
})
|
||||
|
||||
describe('prerelase', () => {
|
||||
it('returns false', () => {
|
||||
@@ -187,6 +199,18 @@ describe('Inputs', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('repo', () => {
|
||||
it('returns repo from context', function () {
|
||||
process.env.GITHUB_REPOSITORY = "owner/repo"
|
||||
mockGetInput.mockReturnValue("")
|
||||
expect(inputs.repo).toBe("repo")
|
||||
});
|
||||
it('returns repo from inputs', function () {
|
||||
mockGetInput.mockReturnValue("repo")
|
||||
expect(inputs.repo).toBe("repo")
|
||||
});
|
||||
})
|
||||
|
||||
describe('tag', () => {
|
||||
it('returns input tag', () => {
|
||||
mockGetInput.mockReturnValue('tag')
|
||||
|
||||
57
__tests__/Integration.test.ts
Normal file
57
__tests__/Integration.test.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import {Action} from "../src/Action";
|
||||
import * as github from "@actions/github";
|
||||
import {Inputs} from "../src/Inputs";
|
||||
import {GithubReleases} from "../src/Releases";
|
||||
import {GithubArtifactUploader} from "../src/ArtifactUploader";
|
||||
import {Artifact} from "../src/Artifact";
|
||||
import * as path from "path";
|
||||
|
||||
// This test is currently intended to be manually run during development. To run:
|
||||
// - Make sure you have an environment variable named GITHUB_TOKEN assigned to your token
|
||||
// - Remove skip from the test below
|
||||
describe.skip('Integration Test', () => {
|
||||
let action: Action
|
||||
|
||||
beforeEach(() => {
|
||||
const token = getToken()
|
||||
const git = github.getOctokit(token)
|
||||
|
||||
const inputs = getInputs()
|
||||
const releases = new GithubReleases(inputs, git)
|
||||
const uploader = new GithubArtifactUploader(releases, inputs.replacesArtifacts)
|
||||
action = new Action(inputs, releases, uploader)
|
||||
})
|
||||
|
||||
it('Performs action', async () => {
|
||||
await action.perform()
|
||||
})
|
||||
|
||||
function getInputs(): Inputs {
|
||||
const artifactPath = path.join(__dirname, 'Integration.test.ts')
|
||||
// new
|
||||
const MockInputs = jest.fn<Inputs, any>(() => {
|
||||
return {
|
||||
allowUpdates: true,
|
||||
artifacts: [new Artifact(artifactPath)],
|
||||
createdReleaseBody: "release body",
|
||||
createdReleaseName: "release name",
|
||||
commit: "",
|
||||
draft: false,
|
||||
owner: "ncipollo",
|
||||
prerelease: true,
|
||||
replacesArtifacts: true,
|
||||
repo: "actions-playground",
|
||||
tag: "0.0.71",
|
||||
token: getToken(),
|
||||
updatedReleaseBody: "updated body",
|
||||
updatedReleaseName: "updated name"
|
||||
}
|
||||
})
|
||||
return new MockInputs();
|
||||
}
|
||||
|
||||
function getToken(): string {
|
||||
return process.env.GITHUB_TOKEN ?? ""
|
||||
}
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user