Add me.read / me.update

This commit is contained in:
rijkvanzanten
2020-10-27 17:05:18 +01:00
parent acfe1c7fb5
commit cac49c711a
3 changed files with 49 additions and 1 deletions

View File

@@ -92,7 +92,7 @@ Research private class property used in extended class.
- [x] Accept Invite
- [x] Enable TFA
- [x] Disable TFA
- [ ] Me
- [x] Me
- [x] Utils
- [x] Get random string
- [x] Hash a value

View File

@@ -1,5 +1,6 @@
import { AxiosInstance } from 'axios';
import { ItemsHandler } from './items';
import { Query, Payload } from '../types';
export class UsersHandler extends ItemsHandler {
constructor(axios: AxiosInstance) {
@@ -22,4 +23,15 @@ export class UsersHandler extends ItemsHandler {
await this.axios.post('/users/tfa/disable', { otp });
},
};
me = {
read: async (query?: Query) => {
const response = await this.axios.get('/users/me', { params: query });
return response.data;
},
update: async (payload: Payload, query?: Query) => {
const response = await this.axios.patch('/users/me', payload, { params: query });
return response.data;
},
};
}

View File

@@ -79,4 +79,40 @@ describe('UsersHandler', () => {
});
});
});
describe('me.read', () => {
it('Calls the /users/me endpoint', async () => {
const stub = sandbox.stub(handler.axios, 'get').resolves(Promise.resolve({ data: {} }));
await handler.me.read();
expect(stub).to.have.been.calledWith('/users/me');
await handler.me.read({ fields: ['first_name'] });
expect(stub).to.have.been.calledWith('/users/me', {
params: { fields: ['first_name'] },
});
});
});
describe('me.update', () => {
it('Calls the /users/me endpoint', async () => {
const stub = sandbox
.stub(handler.axios, 'patch')
.resolves(Promise.resolve({ data: {} }));
await handler.me.update({ first_name: 'Rijk' });
expect(stub).to.have.been.calledWith(
'/users/me',
{ first_name: 'Rijk' },
{ params: undefined }
);
await handler.me.update({ first_name: 'Rijk' }, { fields: ['first_name'] });
expect(stub).to.have.been.calledWith(
'/users/me',
{ first_name: 'Rijk' },
{ params: { fields: ['first_name'] } }
);
});
});
});