/test/resources/Customers.spec.js

https://github.com/stripe/stripe-node · JavaScript · 465 lines · 430 code · 35 blank · 0 comment · 0 complexity · a63f0fed33e27377f6d2a645cbe3a9c9 MD5 · raw file

  1. 'use strict';
  2. const stripe = require('../../testUtils').getSpyableStripe();
  3. const expect = require('chai').expect;
  4. const TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11';
  5. describe('Customers Resource', () => {
  6. describe('retrieve', () => {
  7. it('Sends the correct request', () => {
  8. stripe.customers.retrieve('cus_123');
  9. expect(stripe.LAST_REQUEST).to.deep.equal({
  10. method: 'GET',
  11. url: '/v1/customers/cus_123',
  12. headers: {},
  13. data: {},
  14. settings: {},
  15. });
  16. });
  17. it('Sends the correct request [with specified auth]', () => {
  18. stripe.customers.retrieve('cus_123', TEST_AUTH_KEY);
  19. expect(stripe.LAST_REQUEST).to.deep.equal({
  20. method: 'GET',
  21. url: '/v1/customers/cus_123',
  22. headers: {},
  23. data: {},
  24. auth: TEST_AUTH_KEY,
  25. settings: {},
  26. });
  27. });
  28. });
  29. describe('create', () => {
  30. it('Sends the correct request', () => {
  31. stripe.customers.create({description: 'Some customer'});
  32. expect(stripe.LAST_REQUEST).to.deep.equal({
  33. method: 'POST',
  34. url: '/v1/customers',
  35. headers: {},
  36. data: {description: 'Some customer'},
  37. settings: {},
  38. });
  39. });
  40. it('Sends the correct request [with specified auth]', () => {
  41. stripe.customers.create({description: 'Some customer'}, TEST_AUTH_KEY);
  42. expect(stripe.LAST_REQUEST).to.deep.equal({
  43. method: 'POST',
  44. url: '/v1/customers',
  45. headers: {},
  46. data: {description: 'Some customer'},
  47. auth: TEST_AUTH_KEY,
  48. settings: {},
  49. });
  50. });
  51. it('Sends the correct request [with specified auth and no body]', () => {
  52. stripe.customers.create(TEST_AUTH_KEY);
  53. expect(stripe.LAST_REQUEST).to.deep.equal({
  54. method: 'POST',
  55. url: '/v1/customers',
  56. headers: {},
  57. data: {},
  58. auth: TEST_AUTH_KEY,
  59. settings: {},
  60. });
  61. });
  62. it('Sends the correct request [with specified idempotencyKey in options]', () => {
  63. stripe.customers.create(
  64. {description: 'Some customer'},
  65. {idempotencyKey: 'foo'}
  66. );
  67. expect(stripe.LAST_REQUEST).to.deep.equal({
  68. method: 'POST',
  69. url: '/v1/customers',
  70. headers: {'Idempotency-Key': 'foo'},
  71. data: {description: 'Some customer'},
  72. settings: {},
  73. });
  74. });
  75. it('Sends the correct request [with specified auth in options]', () => {
  76. stripe.customers.create(
  77. {description: 'Some customer'},
  78. {apiKey: TEST_AUTH_KEY}
  79. );
  80. expect(stripe.LAST_REQUEST).to.deep.equal({
  81. method: 'POST',
  82. url: '/v1/customers',
  83. headers: {},
  84. data: {description: 'Some customer'},
  85. auth: TEST_AUTH_KEY,
  86. settings: {},
  87. });
  88. });
  89. it('Sends the correct request [with specified auth and idempotent key in options]', () => {
  90. stripe.customers.create(
  91. {description: 'Some customer'},
  92. {apiKey: TEST_AUTH_KEY, idempotencyKey: 'foo'}
  93. );
  94. expect(stripe.LAST_REQUEST).to.deep.equal({
  95. method: 'POST',
  96. url: '/v1/customers',
  97. headers: {'Idempotency-Key': 'foo'},
  98. data: {description: 'Some customer'},
  99. auth: TEST_AUTH_KEY,
  100. settings: {},
  101. });
  102. });
  103. it('Sends the correct request [with specified auth in options and no body]', () => {
  104. stripe.customers.create({apiKey: TEST_AUTH_KEY});
  105. expect(stripe.LAST_REQUEST).to.deep.equal({
  106. method: 'POST',
  107. url: '/v1/customers',
  108. headers: {},
  109. data: {},
  110. auth: TEST_AUTH_KEY,
  111. settings: {},
  112. });
  113. });
  114. });
  115. describe('update', () => {
  116. it('Sends the correct request', () => {
  117. stripe.customers.update('cus_123', {
  118. description: 'Foo "baz"',
  119. });
  120. expect(stripe.LAST_REQUEST).to.deep.equal({
  121. method: 'POST',
  122. url: '/v1/customers/cus_123',
  123. headers: {},
  124. data: {description: 'Foo "baz"'},
  125. settings: {},
  126. });
  127. });
  128. });
  129. describe('del', () => {
  130. it('Sends the correct request', () => {
  131. stripe.customers.del('cus_123');
  132. expect(stripe.LAST_REQUEST).to.deep.equal({
  133. method: 'DELETE',
  134. url: '/v1/customers/cus_123',
  135. headers: {},
  136. data: {},
  137. settings: {},
  138. });
  139. });
  140. });
  141. describe('list', () => {
  142. it('Sends the correct request', () => {
  143. stripe.customers.list();
  144. expect(stripe.LAST_REQUEST).to.deep.equal({
  145. method: 'GET',
  146. url: '/v1/customers',
  147. headers: {},
  148. data: {},
  149. settings: {},
  150. });
  151. });
  152. it('Sends the correct request [with specified auth]', () => {
  153. stripe.customers.list(TEST_AUTH_KEY);
  154. expect(stripe.LAST_REQUEST).to.deep.equal({
  155. method: 'GET',
  156. url: '/v1/customers',
  157. headers: {},
  158. data: {},
  159. auth: TEST_AUTH_KEY,
  160. settings: {},
  161. });
  162. });
  163. });
  164. describe('Discount methods', () => {
  165. describe('deleteDiscount', () => {
  166. it('Sends the correct request', () => {
  167. stripe.customers.deleteDiscount('cus_123');
  168. expect(stripe.LAST_REQUEST).to.deep.equal({
  169. method: 'DELETE',
  170. url: '/v1/customers/cus_123/discount',
  171. headers: {},
  172. data: {},
  173. settings: {},
  174. });
  175. });
  176. });
  177. });
  178. describe('Source methods', () => {
  179. describe('retrieveSource', () => {
  180. it('Sends the correct request', () => {
  181. stripe.customers.retrieveSource('cus_123', 'card_123');
  182. expect(stripe.LAST_REQUEST).to.deep.equal({
  183. method: 'GET',
  184. url: '/v1/customers/cus_123/sources/card_123',
  185. headers: {},
  186. data: {},
  187. settings: {},
  188. });
  189. });
  190. it('Sends the correct request [with specified auth]', () => {
  191. stripe.customers.retrieveSource('cus_123', 'card_123', TEST_AUTH_KEY);
  192. expect(stripe.LAST_REQUEST).to.deep.equal({
  193. method: 'GET',
  194. url: '/v1/customers/cus_123/sources/card_123',
  195. headers: {},
  196. data: {},
  197. auth: TEST_AUTH_KEY,
  198. settings: {},
  199. });
  200. });
  201. });
  202. describe('createSource', () => {
  203. it('Sends the correct request', () => {
  204. const params = {
  205. source: {
  206. object: 'card',
  207. number: '123456',
  208. exp_month: '12',
  209. exp_year: '30',
  210. },
  211. };
  212. stripe.customers.createSource('cus_123', params);
  213. expect(stripe.LAST_REQUEST).to.deep.equal({
  214. method: 'POST',
  215. url: '/v1/customers/cus_123/sources',
  216. headers: {},
  217. data: params,
  218. settings: {},
  219. });
  220. });
  221. it('Sends the correct request [with specified auth]', () => {
  222. const params = {
  223. source: {
  224. object: 'card',
  225. number: '123456',
  226. exp_month: '12',
  227. exp_year: '30',
  228. },
  229. };
  230. stripe.customers.createSource('cus_123', params, TEST_AUTH_KEY);
  231. expect(stripe.LAST_REQUEST).to.deep.equal({
  232. method: 'POST',
  233. url: '/v1/customers/cus_123/sources',
  234. headers: {},
  235. data: params,
  236. auth: TEST_AUTH_KEY,
  237. settings: {},
  238. });
  239. });
  240. });
  241. describe('updateSource', () => {
  242. it('Sends the correct request', () => {
  243. stripe.customers.updateSource('cus_123', 'card_123', {
  244. name: 'Bob M. Baz',
  245. });
  246. expect(stripe.LAST_REQUEST).to.deep.equal({
  247. method: 'POST',
  248. url: '/v1/customers/cus_123/sources/card_123',
  249. headers: {},
  250. data: {name: 'Bob M. Baz'},
  251. settings: {},
  252. });
  253. });
  254. });
  255. describe('deleteSource', () => {
  256. it('Sends the correct request', () => {
  257. stripe.customers.deleteSource('cus_123', 'card_123');
  258. expect(stripe.LAST_REQUEST).to.deep.equal({
  259. method: 'DELETE',
  260. url: '/v1/customers/cus_123/sources/card_123',
  261. headers: {},
  262. data: {},
  263. settings: {},
  264. });
  265. });
  266. it('Sends the correct request [with specified auth]', () => {
  267. stripe.customers.deleteSource('cus_123', 'card_123', TEST_AUTH_KEY);
  268. expect(stripe.LAST_REQUEST).to.deep.equal({
  269. method: 'DELETE',
  270. url: '/v1/customers/cus_123/sources/card_123',
  271. headers: {},
  272. data: {},
  273. auth: TEST_AUTH_KEY,
  274. settings: {},
  275. });
  276. });
  277. });
  278. describe('listSources', () => {
  279. it('Sends the correct request', () => {
  280. stripe.customers.listSources('cus_123');
  281. expect(stripe.LAST_REQUEST).to.deep.equal({
  282. method: 'GET',
  283. url: '/v1/customers/cus_123/sources',
  284. headers: {},
  285. data: {},
  286. settings: {},
  287. });
  288. });
  289. it('Sends the correct request [with specified auth]', () => {
  290. stripe.customers.listSources('cus_123', TEST_AUTH_KEY);
  291. expect(stripe.LAST_REQUEST).to.deep.equal({
  292. method: 'GET',
  293. url: '/v1/customers/cus_123/sources',
  294. headers: {},
  295. data: {},
  296. auth: TEST_AUTH_KEY,
  297. settings: {},
  298. });
  299. });
  300. });
  301. describe('verifySource', () => {
  302. it('Sends the correct request', () => {
  303. const data = {amounts: [32, 45]};
  304. stripe.customers.verifySource(
  305. 'cus_123',
  306. 'card_123',
  307. data,
  308. TEST_AUTH_KEY
  309. );
  310. expect(stripe.LAST_REQUEST).to.deep.equal({
  311. method: 'POST',
  312. url: '/v1/customers/cus_123/sources/card_123/verify',
  313. headers: {},
  314. data,
  315. auth: TEST_AUTH_KEY,
  316. settings: {},
  317. });
  318. });
  319. });
  320. });
  321. describe('TaxId methods', () => {
  322. describe('retrieveTaxId', () => {
  323. it('Sends the correct request', () => {
  324. stripe.customers.retrieveTaxId('cus_123', 'txi_123');
  325. expect(stripe.LAST_REQUEST).to.deep.equal({
  326. method: 'GET',
  327. url: '/v1/customers/cus_123/tax_ids/txi_123',
  328. headers: {},
  329. data: {},
  330. settings: {},
  331. });
  332. });
  333. });
  334. describe('createTaxId', () => {
  335. it('Sends the correct request', () => {
  336. const data = {
  337. type: 'eu_vat',
  338. value: '11111',
  339. };
  340. stripe.customers.createTaxId('cus_123', data);
  341. expect(stripe.LAST_REQUEST).to.deep.equal({
  342. method: 'POST',
  343. url: '/v1/customers/cus_123/tax_ids',
  344. headers: {},
  345. settings: {},
  346. data,
  347. });
  348. });
  349. });
  350. describe('deleteTaxId', () => {
  351. it('Sends the correct request', () => {
  352. stripe.customers.deleteTaxId('cus_123', 'txi_123');
  353. expect(stripe.LAST_REQUEST).to.deep.equal({
  354. method: 'DELETE',
  355. url: '/v1/customers/cus_123/tax_ids/txi_123',
  356. headers: {},
  357. data: {},
  358. settings: {},
  359. });
  360. });
  361. });
  362. describe('listTaxIds', () => {
  363. it('Sends the correct request', () => {
  364. stripe.customers.listTaxIds('cus_123');
  365. expect(stripe.LAST_REQUEST).to.deep.equal({
  366. method: 'GET',
  367. url: '/v1/customers/cus_123/tax_ids',
  368. headers: {},
  369. data: {},
  370. settings: {},
  371. });
  372. });
  373. });
  374. });
  375. describe('BalanceTransaction methods', () => {
  376. describe('retrieveBalanceTransaction', () => {
  377. it('Sends the correct request', () => {
  378. stripe.customers.retrieveBalanceTransaction('cus_123', 'cbtxn_123');
  379. expect(stripe.LAST_REQUEST).to.deep.equal({
  380. method: 'GET',
  381. url: '/v1/customers/cus_123/balance_transactions/cbtxn_123',
  382. headers: {},
  383. data: {},
  384. settings: {},
  385. });
  386. });
  387. });
  388. describe('createBalanceTransaction', () => {
  389. it('Sends the correct request', () => {
  390. stripe.customers.createBalanceTransaction('cus_123', {
  391. amount: 123,
  392. currency: 'usd',
  393. });
  394. expect(stripe.LAST_REQUEST).to.deep.equal({
  395. method: 'POST',
  396. url: '/v1/customers/cus_123/balance_transactions',
  397. headers: {},
  398. data: {amount: 123, currency: 'usd'},
  399. settings: {},
  400. });
  401. });
  402. });
  403. describe('updateBalanceTransaction', () => {
  404. it('Sends the correct request', () => {
  405. stripe.customers.updateBalanceTransaction('cus_123', 'cbtxn_123', {
  406. description: 'description',
  407. });
  408. expect(stripe.LAST_REQUEST).to.deep.equal({
  409. method: 'POST',
  410. url: '/v1/customers/cus_123/balance_transactions/cbtxn_123',
  411. headers: {},
  412. data: {description: 'description'},
  413. settings: {},
  414. });
  415. });
  416. });
  417. describe('listBalanceTransactions', () => {
  418. it('Sends the correct request', () => {
  419. stripe.customers.listBalanceTransactions('cus_123');
  420. expect(stripe.LAST_REQUEST).to.deep.equal({
  421. method: 'GET',
  422. url: '/v1/customers/cus_123/balance_transactions',
  423. headers: {},
  424. data: {},
  425. settings: {},
  426. });
  427. });
  428. });
  429. });
  430. });