Fix bugs found in E2E testing

This commit is contained in:
Nick Cipollo
2019-08-27 09:50:26 -04:00
parent 0280874154
commit 2b2c872297
10 changed files with 183 additions and 32 deletions

View File

@@ -6,6 +6,8 @@ const createMock = jest.fn()
const uploadMock = jest.fn()
const artifactPath = 'a/path'
const artifactName = 'path'
const artifactData = Buffer.from('blob','utf-8')
const body = 'body'
const commit = 'commit'
const contentType = "raw"
@@ -35,14 +37,14 @@ describe("Action", () => {
const action = createAction(true)
createMock.mockResolvedValue({
data: {
assets_url: url
upload_url: url
}
})
await action.perform()
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(uploadMock).toBeCalledWith(url, contentLength, contentType, artifactPath, 'path')
expect(uploadMock).toBeCalledWith(url, contentLength, contentType, artifactData, 'path')
})
it('throws error when create fails', async () => {
@@ -64,7 +66,7 @@ describe("Action", () => {
const action = createAction(true)
createMock.mockResolvedValue({
data: {
assets_url: url
upload_url: url
}
})
uploadMock.mockRejectedValue("error")
@@ -77,7 +79,7 @@ describe("Action", () => {
}
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(uploadMock).toBeCalledWith(url, contentLength, contentType, artifactPath, 'path')
expect(uploadMock).toBeCalledWith(url, contentLength, contentType, artifactData, 'path')
})
function createAction(hasArtifact: boolean): Action {
@@ -96,6 +98,7 @@ describe("Action", () => {
const MockInputs = jest.fn<Inputs, any>(() => {
return {
artifact: artifact,
artifactName: artifactName,
artifactContentType: contentType,
artifactContentLength: contentLength,
body: body,
@@ -103,7 +106,8 @@ describe("Action", () => {
draft: draft,
name: name,
tag: tag,
token: token
token: token,
readArtifact: () => artifactData
}
})
const inputs = new MockInputs()

View File

@@ -26,6 +26,12 @@ describe('Inputs', () => {
inputs = new CoreInputs(context)
})
it('reads artifact', () => {
mockGetInput.mockReturnValue("a/path")
mockReadFileSync.mockReturnValue('file')
expect(inputs.artifact).toBe("a/path")
})
it('returns artifact', () => {
mockGetInput.mockReturnValue("a/path")
expect(inputs.artifact).toBe("a/path")
@@ -37,6 +43,11 @@ describe('Inputs', () => {
expect(inputs.artifactContentLength).toBe(100)
})
it('returns artifactName', () => {
mockGetInput.mockReturnValue("a/path")
expect(inputs.artifactName).toBe("path")
})
it('returns targetCommit', () => {
mockGetInput.mockReturnValue("42")
expect(inputs.commit).toBe("42")