kopia lustrzana https://github.com/cloudflare/wildebeest
update e2e about test
rodzic
246edfc789
commit
d15916ddd2
|
@ -7,6 +7,8 @@ import { createReply as createReplyInBackend } from 'wildebeest/backend/test/sha
|
|||
import { createStatus } from 'wildebeest/backend/src/mastodon/status'
|
||||
import type { APObject } from 'wildebeest/backend/src/activitypub/objects'
|
||||
import { type Database } from 'wildebeest/backend/src/database'
|
||||
import { upsertRule } from 'wildebeest/functions/api/wb/settings/server/rules'
|
||||
import { upsertServerSettings } from 'wildebeest/functions/api/wb/settings/server/server'
|
||||
|
||||
/**
|
||||
* Run helper commands to initialize the database with actors, statuses, etc.
|
||||
|
@ -41,6 +43,17 @@ export async function init(domain: string, db: Database) {
|
|||
for (const reply of replies) {
|
||||
await createReply(domain, db, reply, loadedStatuses)
|
||||
}
|
||||
|
||||
await createServerData(db)
|
||||
}
|
||||
|
||||
async function createServerData(db: Database) {
|
||||
await upsertServerSettings(db, {
|
||||
'extended description': 'this is a test wildebeest instance!',
|
||||
})
|
||||
await upsertRule(db, "don't be mean")
|
||||
await upsertRule(db, "don't insult people")
|
||||
await upsertRule(db, 'respect the rules')
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,21 @@ import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
|||
import { parse } from 'cookie'
|
||||
import { isUserAdmin } from 'wildebeest/frontend/src/utils/isUserAdmin'
|
||||
|
||||
export const onRequestGet: PagesFunction<Env, any, ContextData> = async ({ env, request }) => {
|
||||
return handleRequestPost(await getDatabase(env), request)
|
||||
}
|
||||
|
||||
export async function handleRequestGet(db: Database) {
|
||||
const query = `SELECT * from server_rules;`
|
||||
const result = await db.prepare(query).all<{ id: string; text: string }>()
|
||||
|
||||
if (!result.success) {
|
||||
return new Response('SQL error: ' + result.error, { status: 500 })
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(result.results ?? []), { status: 200 })
|
||||
}
|
||||
|
||||
export const onRequestPost: PagesFunction<Env, any, ContextData> = async ({ env, request }) => {
|
||||
return handleRequestPost(await getDatabase(env), request)
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ import type { Env } from 'wildebeest/backend/src/types/env'
|
|||
import type { ContextData } from 'wildebeest/backend/src/types/context'
|
||||
import * as errors from 'wildebeest/backend/src/errors'
|
||||
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||
import { ServerBrandingData } from 'wildebeest/frontend/src/routes/(admin)/settings/server-settings/branding'
|
||||
import { parse } from 'cookie'
|
||||
import { isUserAdmin } from 'wildebeest/frontend/src/utils/isUserAdmin'
|
||||
import { ServerSettingsData } from 'wildebeest/frontend/src/routes/(admin)/settings/server-settings/layout'
|
||||
|
||||
export const onRequestGet: PagesFunction<Env, any, ContextData> = async ({ env, request }) => {
|
||||
return handleRequestPost(await getDatabase(env), request)
|
||||
|
@ -42,23 +42,32 @@ export async function handleRequestPost(db: Database, request: Request) {
|
|||
return errors.notAuthorized('Lacking authorization rights to edit server settings')
|
||||
}
|
||||
|
||||
const data = await request.json<ServerBrandingData>()
|
||||
const data = await request.json<ServerSettingsData>()
|
||||
|
||||
const settingsEntries = Object.entries(data)
|
||||
const result = await upsertServerSettings(db, data)
|
||||
|
||||
if (result && !result.success) {
|
||||
return new Response('SQL error: ' + result.error, { status: 500 })
|
||||
}
|
||||
|
||||
return new Response('', { status: 200 })
|
||||
}
|
||||
|
||||
export async function upsertServerSettings(db: Database, settings: Partial<ServerSettingsData>) {
|
||||
const settingsEntries = Object.entries(settings)
|
||||
|
||||
if (!settingsEntries.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
const query = `
|
||||
INSERT INTO server_settings (setting_name, setting_value)
|
||||
VALUES ${settingsEntries.map(() => `(?, ?)`).join(', ')}
|
||||
ON CONFLICT(setting_name) DO UPDATE SET setting_value=excluded.setting_value
|
||||
`
|
||||
const result = await db
|
||||
|
||||
return await db
|
||||
.prepare(query)
|
||||
.bind(...settingsEntries.flat())
|
||||
.run()
|
||||
|
||||
if (!result.success) {
|
||||
return new Response('SQL error: ' + result.error, { status: 500 })
|
||||
}
|
||||
|
||||
return new Response('', { status: 200 })
|
||||
}
|
||||
|
|
|
@ -11,28 +11,28 @@ test.skip('View of the about page', async ({ page }) => {
|
|||
await expect(page.getByTestId('domain-text')).toHaveText('0.0.0.0')
|
||||
await expect(page.getByTestId('social-text')).toHaveText('Decentralised social media powered by Mastodon')
|
||||
|
||||
await expect(page.getByTestId('contact').getByText('Administered by:George 👍@george')).toBeVisible()
|
||||
await expect(page.getByTestId('contact').getByText('contact:test@test.com')).toBeVisible()
|
||||
// await expect(page.getByTestId('contact').getByText('Administered by: ...')).toBeVisible()
|
||||
// await expect(page.getByTestId('contact').getByText('contact: ...')).toBeVisible()
|
||||
|
||||
await expect(page.getByRole('region').filter({ hasText: 'Please mind that the staff' })).not.toBeVisible()
|
||||
await expect(page.getByRole('region').filter({ hasText: 'this is a test wildebeest instance!' })).not.toBeVisible()
|
||||
await page.getByRole('button', { name: 'About' }).click()
|
||||
await expect(page.getByRole('region').filter({ hasText: 'Please mind that the staff' })).toBeVisible()
|
||||
await expect(page.getByRole('region').filter({ hasText: 'this is a test wildebeest instance!' })).toBeVisible()
|
||||
await page.getByRole('button', { name: 'About' }).click()
|
||||
await expect(page.getByRole('region').filter({ hasText: 'Please mind that the staff' })).not.toBeVisible()
|
||||
await expect(page.getByRole('region').filter({ hasText: 'this is a test wildebeest instance!' })).not.toBeVisible()
|
||||
|
||||
const getRuleLocator = (ruleId: string) =>
|
||||
page.getByRole('listitem').filter({ has: page.getByText(ruleId, { exact: true }) })
|
||||
|
||||
await expect(page.getByRole('listitem')).toHaveCount(0)
|
||||
await expect(getRuleLocator('1')).not.toBeVisible()
|
||||
await expect(getRuleLocator('2')).not.toBeVisible()
|
||||
await expect(getRuleLocator('3')).not.toBeVisible()
|
||||
await page.getByRole('button', { name: 'Server rules' }).click()
|
||||
await expect(page.getByRole('listitem')).toHaveCount(3)
|
||||
await expect(getRuleLocator('1')).toBeVisible()
|
||||
await expect(getRuleLocator('1')).toContainText(
|
||||
'Sexually explicit or violent media must be marked as sensitive when posting'
|
||||
)
|
||||
await expect(getRuleLocator('1')).toContainText("don't be mean")
|
||||
await expect(getRuleLocator('2')).toBeVisible()
|
||||
await expect(getRuleLocator('2')).toContainText('No racism, sexism, homophobia, transphobia, xenophobia, or casteism')
|
||||
await expect(getRuleLocator('2')).toContainText("don't insult people")
|
||||
await expect(getRuleLocator('3')).toBeVisible()
|
||||
await expect(getRuleLocator('3')).toContainText('No incitement of violence or promotion of violent ideologies')
|
||||
await expect(getRuleLocator('3')).toContainText('respect the rules')
|
||||
})
|
||||
|
|
Ładowanie…
Reference in New Issue