Skip to content

Commit

Permalink
test: correctly upload asset if file is Buffer/ArrayBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jan 27, 2018
1 parent e242b23 commit e16817d
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/integration/release-assets-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const chai = require('chai')
const fixtures = require('@octokit/fixtures')
const stringToArrayBuffer = require('string-to-arraybuffer')

const GitHub = require('../../')

Expand Down Expand Up @@ -82,4 +83,60 @@ describe('api.github.com', () => {

.catch(GitHubMock.explain)
})

it('github.repos.uploadAsset as Buffer', () => {
fixtures.mock('api.github.com/release-assets')
const githubUserA = new GitHub()

githubUserA.authenticate({
type: 'token',
token: '0000000000000000000000000000000000000001'
})

return githubUserA.repos.getReleaseByTag({
owner: 'octokit-fixture-org',
repo: 'release-assets',
tag: 'v1.0.0'
})

.then(result => {
const content = Buffer.from('Hello, world!\n')
return githubUserA.repos.uploadAsset({
url: result.data.upload_url,
file: content,
contentType: 'text/plain',
contentLength: 14,
name: 'test-upload.txt',
label: 'test'
})
})
})

it('github.repos.uploadAsset as ArrayBuffer', () => {
fixtures.mock('api.github.com/release-assets')
const githubUserA = new GitHub()

githubUserA.authenticate({
type: 'token',
token: '0000000000000000000000000000000000000001'
})

return githubUserA.repos.getReleaseByTag({
owner: 'octokit-fixture-org',
repo: 'release-assets',
tag: 'v1.0.0'
})

.then(result => {
const content = stringToArrayBuffer('Hello, world!\n')
return githubUserA.repos.uploadAsset({
url: result.data.upload_url,
file: content,
contentType: 'text/plain',
contentLength: 14,
name: 'test-upload.txt',
label: 'test'
})
})
})
})

0 comments on commit e16817d

Please sign in to comment.