Add user invite

This commit is contained in:
rijkvanzanten
2020-10-27 16:53:10 +01:00
parent 663abd1e0d
commit 93bdd50892
4 changed files with 38 additions and 16 deletions

View File

@@ -4,6 +4,10 @@
## To-Do
Research private class property used in extended class.
`ItemsService.axios` is privé, maar moet publiek om 't te kunnen gebruiken in andere classes met extend, zoals users
- [x] Items
- [x] Create
- [x] Read
@@ -14,8 +18,6 @@
- [x] Create Comment
- [x] Update Comment
- [x] Delete Comment
- [ ] Assets??? (not sure if needed)
- [ ] Read
- [ ] Auth
- [ ] Login
- [ ] Refresh
@@ -25,18 +27,16 @@
- [ ] oAuth
- [ ] Get available providers
- [ ] Login with provider
- [ ] Collections
- [ ] Create
- [ ] Read
- [ ] Update
- [ ] Delete
- [ ] Extensions??? (not sure if needed)
- [ ] Read
- [ ] Fields
- [ ] Create
- [ ] Read
- [ ] Update
- [ ] Delete
- [x] Collections
- [x] Create
- [x] Read
- [x] Update
- [x] Delete
- [x] Fields
- [x] Create
- [x] Read
- [x] Update
- [x] Delete
- [x] Files
- [x] Create
- [x] Read
@@ -88,7 +88,7 @@
- [x] Read
- [x] Update
- [x] Delete
- [ ] Invite
- [x] Invite
- [ ] Accept Invite
- [ ] Enable TFA
- [ ] Disable TFA

View File

@@ -2,7 +2,7 @@ import { Query, Item, Payload, Response, PrimaryKey } from '../types';
import { AxiosInstance } from 'axios';
export class ItemsHandler {
private axios: AxiosInstance;
axios: AxiosInstance;
private endpoint: string;
constructor(collection: string, axios: AxiosInstance) {

View File

@@ -5,4 +5,8 @@ export class UsersHandler extends ItemsHandler {
constructor(axios: AxiosInstance) {
super('directus_users', axios);
}
async invite(email: string | string[], role: string) {
await this.axios.post('/users/invite', { email, role });
}
}

View File

@@ -24,4 +24,22 @@ describe('UsersHandler', () => {
it('Extends ItemsHandler', () => {
expect(handler).to.be.instanceOf(ItemsHandler);
});
describe('invite', () => {
it('Calls the /users/invite endpoint', async () => {
const stub = sandbox.stub(handler.axios, 'post').resolves(Promise.resolve());
await handler.invite('admin@example.com', 'abc');
expect(stub).to.have.been.calledWith('/users/invite', {
email: 'admin@example.com',
role: 'abc',
});
await handler.invite(['admin@example.com', 'user@example.com'], 'abc');
expect(stub).to.have.been.calledWith('/users/invite', {
email: ['admin@example.com', 'user@example.com'],
role: 'abc',
});
});
});
});