Skip to content

Commit 2d67e95

Browse files
authored
Encode user ids on patch/update/delete (#608)
1 parent cd34fd7 commit 2d67e95

2 files changed

Lines changed: 69 additions & 3 deletions

File tree

src/Auth0RestClient.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,24 @@ Auth0RestClient.prototype.create = function(/* [params], [callback] */) {
6565
return this.wrappedProvider('create', arguments);
6666
};
6767

68-
Auth0RestClient.prototype.patch = function(/* [params], [callback] */) {
68+
Auth0RestClient.prototype.patch = function(params, callback) {
69+
if (typeof params === 'object' && params.id) {
70+
params.id = utils.maybeDecode(`${params.id}`);
71+
}
6972
return this.wrappedProvider('patch', arguments);
7073
};
7174

72-
Auth0RestClient.prototype.update = function(/* [params], [callback] */) {
75+
Auth0RestClient.prototype.update = function(params, callback) {
76+
if (typeof params === 'object' && params.id) {
77+
params.id = utils.maybeDecode(`${params.id}`);
78+
}
7379
return this.wrappedProvider('update', arguments);
7480
};
7581

76-
Auth0RestClient.prototype.delete = function(/* [params], [callback] */) {
82+
Auth0RestClient.prototype.delete = function(params, callback) {
83+
if (typeof params === 'object' && params.id) {
84+
params.id = utils.maybeDecode(`${params.id}`);
85+
}
7786
return this.wrappedProvider('delete', arguments);
7887
};
7988

test/auth0-rest-client.tests.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,63 @@ describe('Auth0RestClient', function() {
9494
});
9595
});
9696

97+
describe('`patch`', () => {
98+
it('should encode params.id on `patch` requests', function(done) {
99+
nock(API_URL)
100+
.patch('/some-resource/auth0%7C1234%2F5678')
101+
.reply(200);
102+
103+
var client = new Auth0RestClient(
104+
API_URL + '/some-resource/:id',
105+
{ headers: {} },
106+
this.providerMock
107+
);
108+
client.patch({ id: 'auth0|1234/5678' }, { data: 'udpate ' }, function(err, data) {
109+
expect(err).to.be.null;
110+
done();
111+
nock.cleanAll();
112+
});
113+
});
114+
});
115+
116+
describe('`update`', () => {
117+
it('should encode params.id on `update` requests', function(done) {
118+
nock(API_URL)
119+
.put('/some-resource/auth0%7C1234%2F5678')
120+
.reply(200);
121+
122+
var client = new Auth0RestClient(
123+
API_URL + '/some-resource/:id',
124+
{ headers: {} },
125+
this.providerMock
126+
);
127+
client.update({ id: 'auth0|1234/5678' }, { data: 'udpate ' }, function(err, data) {
128+
expect(err).to.be.null;
129+
done();
130+
nock.cleanAll();
131+
});
132+
});
133+
});
134+
135+
describe('`delete`', () => {
136+
it('should encode params.id on `delete` requests', function(done) {
137+
nock(API_URL)
138+
.delete('/some-resource/auth0%7C1234%2F5678')
139+
.reply(200);
140+
141+
var client = new Auth0RestClient(
142+
API_URL + '/some-resource/:id',
143+
{ headers: {} },
144+
this.providerMock
145+
);
146+
client.delete({ id: 'auth0|1234/5678' }, function(err, data) {
147+
expect(err).to.be.null;
148+
done();
149+
nock.cleanAll();
150+
});
151+
});
152+
});
153+
97154
it('should return a promise if no callback is given', function(done) {
98155
nock(API_URL)
99156
.get('/some-resource')

0 commit comments

Comments
 (0)