fix: stabilize MindSpace local workflows
Signed-off-by: john <cynell@139.com>
This commit is contained in:
@@ -30,6 +30,7 @@ const portal = spawn(process.execPath, ['server.mjs'], {
|
||||
env: {
|
||||
...process.env,
|
||||
H5_PORT: String(portalPort),
|
||||
H5_PUBLIC_BASE_URL: baseUrl,
|
||||
TKMIND_API_TARGET: 'http://127.0.0.1:9',
|
||||
MINDSPACE_STORAGE_ROOT: storageRoot,
|
||||
MINDSPACE_FREE_PUBLIC_PAGE_LIMIT: '1',
|
||||
@@ -59,7 +60,8 @@ async function waitForPortal() {
|
||||
}
|
||||
|
||||
async function request(pathname, options = {}) {
|
||||
const response = await fetch(`${baseUrl}${pathname}`, options);
|
||||
const url = /^https?:\/\//i.test(pathname) ? pathname : `${baseUrl}${pathname}`;
|
||||
const response = await fetch(url, options);
|
||||
const contentType = response.headers.get('content-type') ?? '';
|
||||
const body = contentType.includes('application/json')
|
||||
? await response.json()
|
||||
@@ -91,9 +93,35 @@ function authHeaders(cookie) {
|
||||
}
|
||||
|
||||
const pool = createDbPool();
|
||||
let originalPublicPageLimit = null;
|
||||
|
||||
async function setPublicPageLimitForTest() {
|
||||
const [rows] = await pool.query(
|
||||
"SELECT value FROM mindspace_config WHERE `key` = 'public_page_limit' LIMIT 1",
|
||||
);
|
||||
originalPublicPageLimit = rows[0]?.value ?? null;
|
||||
await pool.query(
|
||||
`INSERT INTO mindspace_config (\`key\`, value, description, updated_at)
|
||||
VALUES ('public_page_limit', '1', '公开页面数量上限', ?)
|
||||
ON DUPLICATE KEY UPDATE value = VALUES(value), updated_at = VALUES(updated_at)`,
|
||||
[Date.now()],
|
||||
);
|
||||
}
|
||||
|
||||
async function restorePublicPageLimit() {
|
||||
if (originalPublicPageLimit == null) {
|
||||
await pool.query("DELETE FROM mindspace_config WHERE `key` = 'public_page_limit'");
|
||||
return;
|
||||
}
|
||||
await pool.query(
|
||||
"UPDATE mindspace_config SET value = ?, updated_at = ? WHERE `key` = 'public_page_limit'",
|
||||
[originalPublicPageLimit, Date.now()],
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
await waitForPortal();
|
||||
await setPublicPageLimitForTest();
|
||||
const owner = await registerAndLogin(users[0]);
|
||||
const other = await registerAndLogin(users[1]);
|
||||
|
||||
@@ -243,6 +271,7 @@ try {
|
||||
|
||||
let currentPublicationId = republished.body.data.id;
|
||||
const offlineCurrentPublication = async () => {
|
||||
if (!currentPublicationId) return;
|
||||
const response = await request(
|
||||
`/api/mindspace/v1/publications/${currentPublicationId}/offline`,
|
||||
{
|
||||
@@ -318,6 +347,7 @@ try {
|
||||
]);
|
||||
const afterExpiry = await request(publicUrl);
|
||||
assert.equal(afterExpiry.response.status, 404);
|
||||
currentPublicationId = null;
|
||||
|
||||
const finalPublication = await publishMode('public');
|
||||
const finalView = await request(publicUrl, {
|
||||
@@ -410,6 +440,7 @@ try {
|
||||
|
||||
console.log('MindSpace publication API E2E passed');
|
||||
} finally {
|
||||
await restorePublicPageLimit();
|
||||
await pool.query(`DELETE FROM h5_users WHERE username IN (?, ?)`, [
|
||||
users[0].username,
|
||||
users[1].username,
|
||||
|
||||
Reference in New Issue
Block a user