mirror of
https://github.com/directus/directus.git
synced 2026-02-13 05:45:26 -05:00
* add new sdk * update version * fixes and sdk documentation * typing updates, documentation * added missing endpoints * targeting minified version for unpkg * removed unused types file * fixed non minified versions * fix sdk exports * fix the fix * Remove old sdk * Remove old sdk docs * Install types for Jest, add npm test * Rely on npm exclusively * Remove examples folder * Move typescript down * Update sdk.md * added auto refresh and requested changes added more http test calls fixed typing issue in customized types * remove unused endpoint * updated docs * added singletons, fixed typing issues, added password handlers * rename graphql function and fixed system endpoint * Remove unused imports, fix build Co-authored-by: rijkvanzanten <rijkvanzanten@me.com> Co-authored-by: Ben Haynes <ben@rngr.org>
71 lines
1.5 KiB
TypeScript
71 lines
1.5 KiB
TypeScript
/**
|
|
* @jest-environment node
|
|
*/
|
|
|
|
import { Directus } from '../src';
|
|
import { test } from './utils';
|
|
|
|
type Settings = {
|
|
url: string;
|
|
copyright: string;
|
|
title: string;
|
|
ua_code: string;
|
|
show_menu: boolean;
|
|
};
|
|
|
|
type MyWebsite = {
|
|
settings: Settings;
|
|
};
|
|
|
|
describe('singleton', function () {
|
|
test(`can get an item`, async (url, nock) => {
|
|
nock()
|
|
.get('/items/settings')
|
|
.reply(200, {
|
|
data: {
|
|
url: 'http://website.com',
|
|
copyright: 'MyWebsite',
|
|
title: 'Website Title',
|
|
ua_code: 'UA1234567890',
|
|
show_menu: true,
|
|
},
|
|
});
|
|
|
|
const sdk = new Directus<MyWebsite>(url);
|
|
const settings = await sdk.singleton('settings').read();
|
|
|
|
expect(settings).not.toBeNull();
|
|
expect(settings).not.toBeUndefined();
|
|
expect(settings!.url).toBe('http://website.com');
|
|
expect(settings!.title).toBe(`Website Title`);
|
|
expect(settings!.show_menu).toBe(true);
|
|
});
|
|
|
|
test(`can update an item`, async (url, nock) => {
|
|
nock()
|
|
.patch('/items/settings', {
|
|
title: 'New Website Title',
|
|
})
|
|
.reply(200, {
|
|
data: {
|
|
url: 'http://website.com',
|
|
copyright: 'MyWebsite',
|
|
title: 'New Website Title',
|
|
ua_code: 'UA1234567890',
|
|
show_menu: true,
|
|
},
|
|
});
|
|
|
|
const sdk = new Directus<MyWebsite>(url);
|
|
const settings = await sdk.singleton('settings').update({
|
|
title: 'New Website Title',
|
|
});
|
|
|
|
expect(settings).not.toBeNull();
|
|
expect(settings).not.toBeUndefined();
|
|
expect(settings!.url).toBe('http://website.com');
|
|
expect(settings!.title).toBe(`New Website Title`);
|
|
expect(settings!.show_menu).toBe(true);
|
|
});
|
|
});
|