Add initial project files

This commit is contained in:
Igor Martyniuk
2026-09-01 13:03:41 +03:00
parent 22e111bb44
commit 74cb5b6176
1841 changed files with 242819 additions and 30 deletions
+62
View File
@@ -0,0 +1,62 @@
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.
* Returns a Bearer token string.
*/
export async function loginAsAdmin(client: ApiClient): Promise<string> {
const email = process.env.ADMIN_EMAIL || 'admin@admin.com'
const password = process.env.ADMIN_PASSWORD || '1234qqqq'
const res = await client.post('/auth/login').json({ email, password })
res.assertStatus(200)
const body = res.body()
// returns: { type, token, user }
const token = body?.token?.release?.() || body?.token || body?.access_token
if (!token) {
console.error('Login response body:', body)
throw new Error('Could not acquire admin token from /auth/login response')
}
return token
}
+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: [] },
}
}