Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename FileUploads to Files #500

Merged
merged 1 commit into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/resources/FileUploads.js → lib/resources/Files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
});
5 changes: 4 additions & 1 deletion lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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;

Expand Down
11 changes: 4 additions & 7 deletions test/resources/FileUploads.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe('File Uploads Resource', function() {
url: '/v1/files/fil_12345',
headers: {},
data: {},
host: 'uploads.stripe.com',
});
});

Expand All @@ -28,7 +27,6 @@ describe('File Uploads Resource', function() {
headers: {},
data: {},
auth: TEST_AUTH_KEY,
host: 'uploads.stripe.com',
});
});
});
Expand All @@ -41,7 +39,6 @@ describe('File Uploads Resource', function() {
url: '/v1/files',
headers: {},
data: {},
host: 'uploads.stripe.com',
});
});
});
Expand All @@ -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');
});
Expand All @@ -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);
Expand All @@ -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');
});
Expand All @@ -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);
Expand Down
121 changes: 121 additions & 0 deletions test/resources/Files.spec.js
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);
});
});
});
});