|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var stripe = require('../../testUtils').getSpyableStripe(); |
| 4 | +var expect = require('chai').expect; |
| 5 | +var fs = require('fs'); |
| 6 | +var path = require('path'); |
| 7 | + |
| 8 | +var TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; |
| 9 | + |
| 10 | +describe('Files Resource', function() { |
| 11 | + describe('retrieve', function() { |
| 12 | + it('Sends the correct request', function() { |
| 13 | + stripe.files.retrieve('fil_12345'); |
| 14 | + expect(stripe.LAST_REQUEST).to.deep.equal({ |
| 15 | + method: 'GET', |
| 16 | + url: '/v1/files/fil_12345', |
| 17 | + headers: {}, |
| 18 | + data: {}, |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + it('Sends the correct request [with specified auth]', function() { |
| 23 | + stripe.files.retrieve('fil_12345', TEST_AUTH_KEY); |
| 24 | + expect(stripe.LAST_REQUEST).to.deep.equal({ |
| 25 | + method: 'GET', |
| 26 | + url: '/v1/files/fil_12345', |
| 27 | + headers: {}, |
| 28 | + data: {}, |
| 29 | + auth: TEST_AUTH_KEY, |
| 30 | + }); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + describe('list', function() { |
| 35 | + it('Sends the correct request', function() { |
| 36 | + stripe.files.list(); |
| 37 | + expect(stripe.LAST_REQUEST).to.deep.equal({ |
| 38 | + method: 'GET', |
| 39 | + url: '/v1/files', |
| 40 | + headers: {}, |
| 41 | + data: {}, |
| 42 | + }); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('create', function() { |
| 47 | + it('Sends the correct file upload request', function() { |
| 48 | + var testFilename = path.join(__dirname, 'data/minimal.pdf'); |
| 49 | + var f = fs.readFileSync(testFilename); |
| 50 | + |
| 51 | + stripe.files.create({ |
| 52 | + purpose: 'dispute_evidence', |
| 53 | + file: { |
| 54 | + data: f, |
| 55 | + name: 'minimal.pdf', |
| 56 | + type: 'application/octet-stream', |
| 57 | + }, |
| 58 | + }); |
| 59 | + |
| 60 | + expect(stripe.LAST_REQUEST).to.deep.property('host', 'files.stripe.com'); |
| 61 | + expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); |
| 62 | + expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('Sends the correct file upload request [with specified auth]', function() { |
| 66 | + var testFilename = path.join(__dirname, 'data/minimal.pdf'); |
| 67 | + var f = fs.readFileSync(testFilename); |
| 68 | + |
| 69 | + stripe.files.create({ |
| 70 | + purpose: 'dispute_evidence', |
| 71 | + file: { |
| 72 | + data: f, |
| 73 | + name: 'minimal.pdf', |
| 74 | + type: 'application/octet-stream', |
| 75 | + }, |
| 76 | + }, TEST_AUTH_KEY); |
| 77 | + |
| 78 | + expect(stripe.LAST_REQUEST).to.deep.property('host', 'files.stripe.com'); |
| 79 | + expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); |
| 80 | + expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); |
| 81 | + expect(stripe.LAST_REQUEST).to.deep.property('auth', TEST_AUTH_KEY); |
| 82 | + }); |
| 83 | + |
| 84 | + it('Streams a file and sends the correct file upload request', function() { |
| 85 | + var testFilename = path.join(__dirname, 'data/minimal.pdf'); |
| 86 | + var f = fs.createReadStream(testFilename); |
| 87 | + |
| 88 | + return stripe.files.create({ |
| 89 | + purpose: 'dispute_evidence', |
| 90 | + file: { |
| 91 | + data: f, |
| 92 | + name: 'minimal.pdf', |
| 93 | + type: 'application/octet-stream', |
| 94 | + }, |
| 95 | + }).then(function() { |
| 96 | + expect(stripe.LAST_REQUEST).to.deep.property('host', 'files.stripe.com'); |
| 97 | + expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); |
| 98 | + expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + it('Streams a file and sends the correct file upload request [with specified auth]', function() { |
| 103 | + var testFilename = path.join(__dirname, 'data/minimal.pdf'); |
| 104 | + var f = fs.createReadStream(testFilename); |
| 105 | + |
| 106 | + return stripe.files.create({ |
| 107 | + purpose: 'dispute_evidence', |
| 108 | + file: { |
| 109 | + data: f, |
| 110 | + name: 'minimal.pdf', |
| 111 | + type: 'application/octet-stream', |
| 112 | + }, |
| 113 | + }, TEST_AUTH_KEY).then(function() { |
| 114 | + expect(stripe.LAST_REQUEST).to.deep.property('host', 'files.stripe.com'); |
| 115 | + expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); |
| 116 | + expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); |
| 117 | + expect(stripe.LAST_REQUEST).to.deep.property('auth', TEST_AUTH_KEY); |
| 118 | + }); |
| 119 | + }); |
| 120 | + }); |
| 121 | +}); |
0 commit comments