mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add collections/fields handlers
This commit is contained in:
8
packages/sdk-js/src/handlers/collections.ts
Normal file
8
packages/sdk-js/src/handlers/collections.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { AxiosInstance } from 'axios';
|
||||
import { ItemsHandler } from './items';
|
||||
|
||||
export class CollectionsHandler extends ItemsHandler {
|
||||
constructor(axios: AxiosInstance) {
|
||||
super('directus_collections', axios);
|
||||
}
|
||||
}
|
||||
8
packages/sdk-js/src/handlers/fields.ts
Normal file
8
packages/sdk-js/src/handlers/fields.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { AxiosInstance } from 'axios';
|
||||
import { ItemsHandler } from './items';
|
||||
|
||||
export class FieldsHandler extends ItemsHandler {
|
||||
constructor(axios: AxiosInstance) {
|
||||
super('directus_fields', axios);
|
||||
}
|
||||
}
|
||||
@@ -11,3 +11,5 @@ export * from './roles';
|
||||
export * from './users';
|
||||
export * from './settings';
|
||||
export * from './files';
|
||||
export * from './collections';
|
||||
export * from './fields';
|
||||
|
||||
@@ -11,6 +11,8 @@ import {
|
||||
UsersHandler,
|
||||
SettingsHandler,
|
||||
FilesHandler,
|
||||
CollectionsHandler,
|
||||
FieldsHandler,
|
||||
} from './handlers';
|
||||
|
||||
export default class DirectusSDK {
|
||||
@@ -77,4 +79,12 @@ export default class DirectusSDK {
|
||||
get files() {
|
||||
return new FilesHandler(this.axios);
|
||||
}
|
||||
|
||||
get collections() {
|
||||
return new CollectionsHandler(this.axios);
|
||||
}
|
||||
|
||||
get fields() {
|
||||
return new FieldsHandler(this.axios);
|
||||
}
|
||||
}
|
||||
|
||||
27
packages/sdk-js/tests/handlers/collections.ts
Normal file
27
packages/sdk-js/tests/handlers/collections.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { CollectionsHandler, ItemsHandler } from '../../src/handlers';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import sinon, { SinonSandbox } from 'sinon';
|
||||
import chai, { expect } from 'chai';
|
||||
import sinonChai from 'sinon-chai';
|
||||
|
||||
chai.use(sinonChai);
|
||||
|
||||
describe('CollectionsHandler', () => {
|
||||
let sandbox: SinonSandbox;
|
||||
let axiosInstance: AxiosInstance;
|
||||
let handler: CollectionsHandler;
|
||||
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox();
|
||||
axiosInstance = axios.create();
|
||||
handler = new CollectionsHandler(axiosInstance);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
it('Extends ItemsHandler', () => {
|
||||
expect(handler).to.be.instanceOf(ItemsHandler);
|
||||
});
|
||||
});
|
||||
27
packages/sdk-js/tests/handlers/fields.ts
Normal file
27
packages/sdk-js/tests/handlers/fields.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { FieldsHandler, ItemsHandler } from '../../src/handlers';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import sinon, { SinonSandbox } from 'sinon';
|
||||
import chai, { expect } from 'chai';
|
||||
import sinonChai from 'sinon-chai';
|
||||
|
||||
chai.use(sinonChai);
|
||||
|
||||
describe('FieldsHandler', () => {
|
||||
let sandbox: SinonSandbox;
|
||||
let axiosInstance: AxiosInstance;
|
||||
let handler: FieldsHandler;
|
||||
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox();
|
||||
axiosInstance = axios.create();
|
||||
handler = new FieldsHandler(axiosInstance);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
it('Extends ItemsHandler', () => {
|
||||
expect(handler).to.be.instanceOf(ItemsHandler);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user