Skip to content

Commit

Permalink
Adds PUT support to Request
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissrogers committed Nov 7, 2023
1 parent a88e7c8 commit f938026
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/recurly/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
12 changes: 12 additions & 0 deletions test/unit/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('post', `${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();
Expand Down

0 comments on commit f938026

Please sign in to comment.