diff --git a/lib/resources/FileUploads.js b/lib/resources/Files.js similarity index 95% rename from lib/resources/FileUploads.js rename to lib/resources/Files.js index cdb0b77f1d..0e117001a4 100644 --- a/lib/resources/FileUploads.js +++ b/lib/resources/Files.js @@ -71,18 +71,16 @@ module.exports = StripeResource.extend({ headers: { 'Content-Type': 'multipart/form-data', }, - host: 'uploads.stripe.com', + host: 'files.stripe.com', }), list: stripeMethod({ method: 'GET', - host: 'uploads.stripe.com', }), retrieve: stripeMethod({ method: 'GET', path: '/{id}', urlParams: ['id'], - host: 'uploads.stripe.com', }), }); diff --git a/lib/stripe.js b/lib/stripe.js index 4ff5720f31..887c5b9a00 100644 --- a/lib/stripe.js +++ b/lib/stripe.js @@ -44,8 +44,8 @@ var resources = { EphemeralKeys: require('./resources/EphemeralKeys'), Events: require('./resources/Events'), ExchangeRates: require('./resources/ExchangeRates'), + Files: require('./resources/Files'), FileLinks: require('./resources/FileLinks'), - FileUploads: require('./resources/FileUploads'), InvoiceItems: require('./resources/InvoiceItems'), Invoices: require('./resources/Invoices'), IssuerFraudRecords: require('./resources/IssuerFraudRecords'), @@ -94,6 +94,9 @@ var resources = { }), }; +// For backwards compatibility, `Files` is aliased to `FileUploads` +resources.FileUploads = resources.Files; + Stripe.StripeResource = require('./StripeResource'); Stripe.resources = resources; diff --git a/test/resources/FileUploads.spec.js b/test/resources/FileUploads.spec.js index 2191930973..cf839ca5ee 100644 --- a/test/resources/FileUploads.spec.js +++ b/test/resources/FileUploads.spec.js @@ -16,7 +16,6 @@ describe('File Uploads Resource', function() { url: '/v1/files/fil_12345', headers: {}, data: {}, - host: 'uploads.stripe.com', }); }); @@ -28,7 +27,6 @@ describe('File Uploads Resource', function() { headers: {}, data: {}, auth: TEST_AUTH_KEY, - host: 'uploads.stripe.com', }); }); }); @@ -41,7 +39,6 @@ describe('File Uploads Resource', function() { url: '/v1/files', headers: {}, data: {}, - host: 'uploads.stripe.com', }); }); }); @@ -60,7 +57,7 @@ describe('File Uploads Resource', function() { }, }); - expect(stripe.LAST_REQUEST).to.deep.property('host', 'uploads.stripe.com'); + 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'); }); @@ -78,7 +75,7 @@ describe('File Uploads Resource', function() { }, }, TEST_AUTH_KEY); - expect(stripe.LAST_REQUEST).to.deep.property('host', 'uploads.stripe.com'); + 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); @@ -96,7 +93,7 @@ describe('File Uploads Resource', function() { type: 'application/octet-stream', }, }).then(function() { - expect(stripe.LAST_REQUEST).to.deep.property('host', 'uploads.stripe.com'); + 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'); }); @@ -114,7 +111,7 @@ describe('File Uploads Resource', function() { type: 'application/octet-stream', }, }, TEST_AUTH_KEY).then(function() { - expect(stripe.LAST_REQUEST).to.deep.property('host', 'uploads.stripe.com'); + 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); diff --git a/test/resources/Files.spec.js b/test/resources/Files.spec.js new file mode 100644 index 0000000000..01affd912e --- /dev/null +++ b/test/resources/Files.spec.js @@ -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); + }); + }); + }); +});