Add input tests
This commit is contained in:
@@ -9,15 +9,35 @@ jest.mock('@actions/core', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Inputs', () => {
|
describe('Inputs', () => {
|
||||||
let context: Context
|
let context: Context;
|
||||||
let inputs: Inputs
|
let inputs: Inputs;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
context = new Context()
|
context = new Context()
|
||||||
inputs = new Inputs(context)
|
inputs = new Inputs(context)
|
||||||
mockGetInput.mockReturnValue("")
|
|
||||||
})
|
})
|
||||||
it('returns token', () => {
|
|
||||||
|
it('token method returns input token', () => {
|
||||||
mockGetInput.mockReturnValue("42")
|
mockGetInput.mockReturnValue("42")
|
||||||
expect(inputs.token).toBe("42")
|
expect(inputs.token).toBe("42")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('tag', () => {
|
||||||
|
it('tag property returns input tag', () => {
|
||||||
|
mockGetInput.mockReturnValue("tag")
|
||||||
|
expect(inputs.tag).toBe("tag")
|
||||||
|
})
|
||||||
|
it('tag property returns context sha when input is empty', () => {
|
||||||
|
mockGetInput.mockReturnValue("")
|
||||||
|
context.ref = "refs/tags/sha-tag"
|
||||||
|
expect(inputs.tag).toBe("sha-tag")
|
||||||
|
})
|
||||||
|
it('tag property returns context sha when input is null', () => {
|
||||||
|
mockGetInput.mockReturnValue(null)
|
||||||
|
context.ref = "refs/tags/sha-tag"
|
||||||
|
expect(inputs.tag).toBe("sha-tag")
|
||||||
|
})
|
||||||
|
it('tag property throws if no tag', () => {
|
||||||
|
expect(() => inputs.tag).toThrow()
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
@@ -5,23 +5,23 @@ export class Inputs {
|
|||||||
private context: Context
|
private context: Context
|
||||||
|
|
||||||
constructor(context: Context) {
|
constructor(context: Context) {
|
||||||
this.context = context;
|
this.context = context
|
||||||
}
|
}
|
||||||
|
|
||||||
get token(): string {
|
get token(): string {
|
||||||
return core.getInput('token', {required: true});
|
return core.getInput('token', {required: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
get tag() : string {
|
get tag() : string {
|
||||||
const tag = core.getInput('tag');
|
const tag = core.getInput('tag')
|
||||||
if(tag != null) {
|
if(tag) {
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ref = this.context.ref;
|
const ref = this.context.ref
|
||||||
const tagPath = "refs/tags/";
|
const tagPath = "refs/tags/"
|
||||||
if(ref.startsWith(tagPath)) {
|
if(ref && ref.startsWith(tagPath)) {
|
||||||
return ref.substr(0, tagPath.length);
|
return ref.substr(tagPath.length, ref.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
throw Error("No tag found in ref or input!")
|
throw Error("No tag found in ref or input!")
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import { GitHub } from "@actions/github";
|
|||||||
import { Response, ReposCreateReleaseResponse } from "@octokit/rest";
|
import { Response, ReposCreateReleaseResponse } from "@octokit/rest";
|
||||||
|
|
||||||
export class Releases {
|
export class Releases {
|
||||||
context: Context;
|
context: Context
|
||||||
git: GitHub;
|
git: GitHub
|
||||||
|
|
||||||
constructor(context: Context, git: GitHub) {
|
constructor(context: Context, git: GitHub) {
|
||||||
this.context = context;
|
this.context = context
|
||||||
this.git = git;
|
this.git = git
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(tag: string, commitHash?: string): Promise<Response<ReposCreateReleaseResponse>> {
|
async create(tag: string, commitHash?: string): Promise<Response<ReposCreateReleaseResponse>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user