diff --git a/src/cms/api/forms.test.ts b/src/cms/api/forms.test.ts new file mode 100644 index 000000000..ac28eb5f7 --- /dev/null +++ b/src/cms/api/forms.test.ts @@ -0,0 +1,11 @@ +import { getTestingContext } from '../util/testing'; +import { getForm } from './forms'; + +const ctx = getTestingContext(); + +it('form tests', () => { + // describe('form should render test boxes', async () => { + // const form = await getForm(ctx, 'posts'); + // expect(form).toBeNull(); + // }); +}); diff --git a/src/cms/api/forms.ts b/src/cms/api/forms.ts index 2e60e1908..ed5acb77c 100644 --- a/src/cms/api/forms.ts +++ b/src/cms/api/forms.ts @@ -41,6 +41,31 @@ export function getForm(ctx: AppContext, table) { } ] }; + } else if (formField.metaType == 'ckeditor') { + const c = formField; + formField = { + label: c.label || c.key, + editor: 'ckeditor', + customClass: 'pl-4 pr-4', + tableView: true, + key: c.key, + type: 'textarea', + input: true, + isUploadEnabled: false + }; + } else if (formField.metaType == 'quill') { + const c = formField; + formField = { + label: c.label || c.key, + editor: 'quill', + customClass: 'pl-4 pr-4', + tableView: true, + key: c.key, + type: 'textarea', + rows: 3, + input: true, + isUploadEnabled: false + }; } formFields.push(formField); } diff --git a/src/cms/util/testing.ts b/src/cms/util/testing.ts index 237fbbcea..5c9a598f4 100644 --- a/src/cms/util/testing.ts +++ b/src/cms/util/testing.ts @@ -3,7 +3,30 @@ import { drizzle } from 'drizzle-orm/d1'; import { createUser } from '../auth/lucia'; import { getD1DataByTable } from '../data/d1-data'; -export async function createUserAndGetToken(app, ctx, email= 'a@a.com', password = 'password123', role = 'admin') { +export async function getTestingContext() { + const { __D1_BETA__D1DATA, KVDATA } = getMiniflareBindings(); + + const toJson = function (json) { + return json; + }; + + const ctx = { + env: { KVDATA: KVDATA, D1DATA: __D1_BETA__D1DATA }, + json: toJson, + user: { id: 'fromtest' }, + _var: { user: { userId: 'abc123' } } + }; + + return ctx; +} + +export async function createUserAndGetToken( + app, + ctx, + email = 'a@a.com', + password = 'password123', + role = 'admin' +) { await createUserTestTables(ctx); //TODO: create user properly using the lucia api so that the user keys data in populated @@ -42,7 +65,7 @@ export async function createUserAndGetToken(app, ctx, email= 'a@a.com', password expect(res.status).toBe(200); let body = await res.json(); expect(body.bearer.length).toBeGreaterThan(10); - return {id: result.user.userId, token:body.bearer}; + return { id: result.user.userId, token: body.bearer }; } export async function createUserTestTables(ctx) { diff --git a/src/db/routes.ts b/src/db/routes.ts index 92cf3f897..1a2872951 100644 --- a/src/db/routes.ts +++ b/src/db/routes.ts @@ -176,6 +176,15 @@ export interface ApiConfig { type: 'file' | 'file[]'; bucket: (ctx: AppContext) => R2Bucket; path?: string | ((ctx: AppContext) => string); + } + | { + type: 'password'; + } + | { + type: 'ckeditor'; + } + | { + type: 'quill'; }; }; } diff --git a/src/db/schema/posts.ts b/src/db/schema/posts.ts index 6183f5451..5dd86320e 100644 --- a/src/db/schema/posts.ts +++ b/src/db/schema/posts.ts @@ -117,5 +117,8 @@ export const fields: ApiConfig['fields'] = { }, tags: { type: 'string[]' + }, + body: { + type: 'ckeditor' } };