forked from stripe/stripe-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request stripe#500 from stripe/ob-file-resource
Rename `FileUploads` to `Files`
- Loading branch information
Showing
4 changed files
with
130 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
'use strict'; | ||
|
||
var stripe = require('../../testUtils').getSpyableStripe(); | ||
var expect = require('chai').expect; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; | ||
|
||
describe('Files Resource', function() { | ||
describe('retrieve', function() { | ||
it('Sends the correct request', function() { | ||
stripe.files.retrieve('fil_12345'); | ||
expect(stripe.LAST_REQUEST).to.deep.equal({ | ||
method: 'GET', | ||
url: '/v1/files/fil_12345', | ||
headers: {}, | ||
data: {}, | ||
}); | ||
}); | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
stripe.files.retrieve('fil_12345', TEST_AUTH_KEY); | ||
expect(stripe.LAST_REQUEST).to.deep.equal({ | ||
method: 'GET', | ||
url: '/v1/files/fil_12345', | ||
headers: {}, | ||
data: {}, | ||
auth: TEST_AUTH_KEY, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('list', function() { | ||
it('Sends the correct request', function() { | ||
stripe.files.list(); | ||
expect(stripe.LAST_REQUEST).to.deep.equal({ | ||
method: 'GET', | ||
url: '/v1/files', | ||
headers: {}, | ||
data: {}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('create', function() { | ||
it('Sends the correct file upload request', function() { | ||
var testFilename = path.join(__dirname, 'data/minimal.pdf'); | ||
var f = fs.readFileSync(testFilename); | ||
|
||
stripe.files.create({ | ||
purpose: 'dispute_evidence', | ||
file: { | ||
data: f, | ||
name: 'minimal.pdf', | ||
type: 'application/octet-stream', | ||
}, | ||
}); | ||
|
||
expect(stripe.LAST_REQUEST).to.deep.property('host', 'files.stripe.com'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); | ||
}); | ||
|
||
it('Sends the correct file upload request [with specified auth]', function() { | ||
var testFilename = path.join(__dirname, 'data/minimal.pdf'); | ||
var f = fs.readFileSync(testFilename); | ||
|
||
stripe.files.create({ | ||
purpose: 'dispute_evidence', | ||
file: { | ||
data: f, | ||
name: 'minimal.pdf', | ||
type: 'application/octet-stream', | ||
}, | ||
}, TEST_AUTH_KEY); | ||
|
||
expect(stripe.LAST_REQUEST).to.deep.property('host', 'files.stripe.com'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('auth', TEST_AUTH_KEY); | ||
}); | ||
|
||
it('Streams a file and sends the correct file upload request', function() { | ||
var testFilename = path.join(__dirname, 'data/minimal.pdf'); | ||
var f = fs.createReadStream(testFilename); | ||
|
||
return stripe.files.create({ | ||
purpose: 'dispute_evidence', | ||
file: { | ||
data: f, | ||
name: 'minimal.pdf', | ||
type: 'application/octet-stream', | ||
}, | ||
}).then(function() { | ||
expect(stripe.LAST_REQUEST).to.deep.property('host', 'files.stripe.com'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); | ||
}); | ||
}); | ||
|
||
it('Streams a file and sends the correct file upload request [with specified auth]', function() { | ||
var testFilename = path.join(__dirname, 'data/minimal.pdf'); | ||
var f = fs.createReadStream(testFilename); | ||
|
||
return stripe.files.create({ | ||
purpose: 'dispute_evidence', | ||
file: { | ||
data: f, | ||
name: 'minimal.pdf', | ||
type: 'application/octet-stream', | ||
}, | ||
}, TEST_AUTH_KEY).then(function() { | ||
expect(stripe.LAST_REQUEST).to.deep.property('host', 'files.stripe.com'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('auth', TEST_AUTH_KEY); | ||
}); | ||
}); | ||
}); | ||
}); |