From d4b99fcda255487a067cc9ff77e87ce6651ddcf1 Mon Sep 17 00:00:00 2001 From: Christopher Rogers Date: Tue, 7 Nov 2023 13:33:03 -0800 Subject: [PATCH] Adds PUT support to Request --- lib/recurly/request.js | 2 +- test/unit/request.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/recurly/request.js b/lib/recurly/request.js index 2730e5a07..a25399463 100644 --- a/lib/recurly/request.js +++ b/lib/recurly/request.js @@ -303,7 +303,7 @@ export class Request { // XDR requests will abort if too many are sent simultaneously setTimeout(() => { - if (method === 'post') { + if (method === 'post' || method === 'put') { // XDR cannot set Content-type if (req.setRequestHeader) { req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); diff --git a/test/unit/request.test.js b/test/unit/request.test.js index 56aef92fa..c5fbd1321 100644 --- a/test/unit/request.test.js +++ b/test/unit/request.test.js @@ -261,6 +261,18 @@ describe('Request', () => { }); }); + describe('when performing a PUT request', () => { + beforeEach(function (done) { + const proceed = () => done(); + this.request.request({ method: 'put', route: '/test', data: this.example }).done(proceed, proceed); + }); + + it('sends properly-encoded data in the request body', function () { + assert(this.XHR.prototype.open.calledWithExactly('put', `${this.recurly.config.api}/test`)); + assert(this.XHR.prototype.send.calledWithExactly(this.exampleEncoded())); + }); + }); + describe('when performing a GET request', () => { beforeEach(function (done) { const proceed = () => done();