TASKS-1823 WebManager module

This commit is contained in:
Igor Martyniuk
2026-08-28 08:35:58 +00:00
parent fdb2cf3837
commit c93d8c025b
654 changed files with 26232 additions and 6075 deletions
+36
View File
@@ -1,4 +1,40 @@
import type { ApiClient } from '@japa/api-client'
import db from '@adonisjs/lucid/services/db'
import Admins from '#base_modules/Admin/model/admin'
import Role from '#base_modules/Role/model/role'
let sequence = 0
/**
* Creates an active admin holding exactly the given permission slugs (via a
* dedicated role) and returns a Bearer token for the access-tokens guard.
*
* DB-backed: call from specs that run inside a migrated test database (see
* `tests/bootstrap.ts`), typically with a global-transaction group hook.
* Pass an empty array for an admin with no permissions at all.
*/
export async function createAdminWithToken(permissions: string[]) {
sequence += 1
const suffix = `${Date.now()}-${sequence}`
const admin = await Admins.create({
email: `spec-admin-${suffix}@test.local`,
password: 'secret-password',
status: 'active',
})
if (permissions.length > 0) {
const role = await Role.create({ name: `spec-role-${suffix}` })
await db.table('admin_roles').insert({ admin_id: admin.id, role_id: role.id })
await db
.table('role_permissions')
.multiInsert(permissions.map((slug) => ({ role_id: role.id, permission_slug: slug })))
}
const accessToken = await Admins.accessTokens.create(admin)
return { admin, token: accessToken.value!.release() }
}
/**
* Logs in as Admin using the test HTTP client.
+50
View File
@@ -0,0 +1,50 @@
import type { PageInput } from '#base_modules/WebManager/types/web_manager'
let sequence = 0
/**
* A minimal valid page input; override per test.
*
* `hero` defaults to a minimal object rather than null: the HTTP validator
* (`hero: jsonObjectSchema`) requires an object, so null only works when
* calling WebManagerService directly.
*/
export function pageInput(overrides: Partial<PageInput> = {}): PageInput {
sequence += 1
return {
locale: 'en',
path: `spec-page-${sequence}`,
groupKey: `spec-page-${sequence}`,
pageType: 'landing',
title: 'Spec page',
hero: { type: 'none', ctaItems: [] },
seoTitle: '',
seoDescription: '',
components: [],
...overrides,
} as PageInput
}
/** A minimal valid `content` component. */
export function contentComponent(text = 'Hello') {
return {
type: 'content',
data: {
// Non-empty on purpose: the JSON bodyparser nulls empty strings, which the
// strict block validator then rejects; only the multipart `payload` JSON
// string transports '' intact. See the "empty strings survive" spec.
title: 'Section',
subtitle: 'Sub',
columns: [{ content: { content: `<p>${text}</p>` }, ctaItems: [] }],
},
}
}
/** A minimal valid `banner` component. */
export function bannerComponent(text = 'Banner') {
return {
type: 'banner',
data: { style: 'info', content: { content: `<p>${text}</p>` }, ctaItems: [] },
}
}