WIP: AI: #485 タグ広場 V1 /posts/changes の非 admin アクセス時 503 を修正
#489
@@ -8,7 +8,12 @@ RSpec.describe 'Post history privacy', type: :request do
|
|||||||
let!(:other_post) do
|
let!(:other_post) do
|
||||||
create(:post, created_at: origin, updated_at: origin + 3.days + 1.hour)
|
create(:post, created_at: origin, updated_at: origin + 3.days + 1.hour)
|
||||||
end
|
end
|
||||||
let!(:tag) { create(:tag, primary_name: 'private-history-tag') }
|
let!(:tag) do
|
||||||
|
# Locale completion in the tag factory can create its own version 1.
|
||||||
|
create(:tag, primary_tag_name: nil).tap do |record|
|
||||||
|
create(:tag_name, tag: record, name: 'private-history-tag')
|
||||||
|
end
|
||||||
|
end
|
||||||
let!(:external) { create(:external_tag, name: 'external-history-tag') }
|
let!(:external) { create(:external_tag, name: 'external-history-tag') }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@@ -138,7 +143,9 @@ RSpec.describe 'Post history privacy', type: :request do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'paginates public tag additions and removals using the same exact count' do
|
it 'paginates public tag additions and removals using the same exact count' do
|
||||||
public_tag = create(:tag, primary_name: 'public-history-tag')
|
public_tag = create(:tag, primary_tag_name: nil).tap do |record|
|
||||||
|
create(:tag_name, tag: record, name: 'public-history-tag')
|
||||||
|
end
|
||||||
public_external = create(:external_tag)
|
public_external = create(:external_tag)
|
||||||
TagVersion.create!(tag: public_tag, version_no: 1, event_type: 'create',
|
TagVersion.create!(tag: public_tag, version_no: 1, event_type: 'create',
|
||||||
name: 'public-history-tag', category: 'general', aliases: '', parent_tag_ids: '',
|
name: 'public-history-tag', category: 'general', aliases: '', parent_tag_ids: '',
|
||||||
|
|||||||
@@ -418,6 +418,37 @@ test ('YouTube posts return HTTP 200 with the embed rendered by SSR', async t =>
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test ('post history HTTP requests preserve filters for every role', async t => {
|
||||||
|
const accounts = [
|
||||||
|
{ role: 'guest', cookie: null },
|
||||||
|
{ role: 'member', cookie: await authenticatedCookie ('second-recovery-secret') },
|
||||||
|
{ role: 'admin', cookie: await authenticatedCookie () }]
|
||||||
|
for (const account of accounts) {
|
||||||
|
for (const prefix of ['', '/ja', '/ain-Kana']) {
|
||||||
|
await t.test (`${account.role} ${prefix || 'no locale prefix'}`, async () => {
|
||||||
|
for (const query of ['', '?id=1&page=2&limit=5']) {
|
||||||
|
const start = requests.length
|
||||||
|
const response = await fetch (
|
||||||
|
`${httpOrigin}${prefix}/posts/changes${query}`, {
|
||||||
|
headers: account.cookie == null ? {} : { Cookie: account.cookie } })
|
||||||
|
assert.equal (response.status, 200)
|
||||||
|
const html = await response.text ()
|
||||||
|
assert.match (html, /<table/)
|
||||||
|
assert.doesNotMatch (html, /Switched to client rendering|template id="B:/)
|
||||||
|
const calls = requests.slice (start).map (request => new URL (request.url, apiURL))
|
||||||
|
.filter (url => url.pathname === '/posts/versions')
|
||||||
|
assert.equal (calls.length, 1)
|
||||||
|
assert.equal (calls[0].searchParams.get ('post'), query ? '1' : null)
|
||||||
|
assert.equal (calls[0].searchParams.get ('page'), query ? '2' : '1')
|
||||||
|
assert.equal (calls[0].searchParams.get ('limit'), query ? '5' : '20')
|
||||||
|
assert.equal (calls[0].searchParams.get ('locale'), prefix === '/ain-Kana'
|
||||||
|
? 'ain-Kana' : 'ja')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
test ('parallel localized requests keep list data isolated', async () => {
|
test ('parallel localized requests keep list data isolated', async () => {
|
||||||
const start = requests.length
|
const start = requests.length
|
||||||
const pages = await Promise.all (['ja', 'ain-Kana', 'ja', 'ain-Kana'].map (locale =>
|
const pages = await Promise.all (['ja', 'ain-Kana', 'ja', 'ain-Kana'].map (locale =>
|
||||||
|
|||||||
@@ -127,15 +127,23 @@ describe ('prefetchForURL', () => {
|
|||||||
.toEqual ({ versions: [], count: 0 })
|
.toEqual ({ versions: [], count: 0 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it ('prefetches unfiltered post history with its own cache key', async () => {
|
it ('keeps one post history separate from unfiltered history in the cache', async () => {
|
||||||
const client = qc ()
|
const client = qc ()
|
||||||
const params = { page: 2, limit: 5 }
|
const params = { page: 2, limit: 5 }
|
||||||
|
const postParams = { ...params, post: '12' }
|
||||||
|
const history = { versions: [], count: 7 }
|
||||||
|
postsApi.fetchPostChanges.mockResolvedValueOnce (history)
|
||||||
|
|
||||||
|
await prefetchForURL (client, '/ja/posts/changes?id=12&page=2&limit=5')
|
||||||
await prefetchForURL (client, '/ja/posts/changes?page=2&limit=5')
|
await prefetchForURL (client, '/ja/posts/changes?page=2&limit=5')
|
||||||
|
|
||||||
expect (postsApi.fetchPostChanges).toHaveBeenCalledExactlyOnceWith (params, 'ja')
|
expect (postsApi.fetchPostChanges).toHaveBeenCalledTimes (2)
|
||||||
|
expect (postsApi.fetchPostChanges).toHaveBeenNthCalledWith (1, postParams, 'ja')
|
||||||
|
expect (postsApi.fetchPostChanges).toHaveBeenNthCalledWith (2, params, 'ja')
|
||||||
|
expect (client.getQueryData (postsKeys.changes (postParams, 'ja'))).toEqual (history)
|
||||||
expect (client.getQueryData (postsKeys.changes (params, 'ja')))
|
expect (client.getQueryData (postsKeys.changes (params, 'ja')))
|
||||||
.toEqual ({ versions: [], count: 0 })
|
.toEqual ({ versions: [], count: 0 })
|
||||||
|
expect (client.getQueryCache ().getAll ()).toHaveLength (2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it ('prefetches tag indexes from query parameters', async () => {
|
it ('prefetches tag indexes from query parameters', async () => {
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ if (typeof originalTransform === 'function')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineConfig ({
|
export default defineConfig (({ command }) => ({
|
||||||
|
// Production React does not provide jsxDEV, regardless of the build environment.
|
||||||
|
esbuild: command === 'build' ? { jsxDev: false } : undefined,
|
||||||
plugins: [{ name: 'request-render-context', enforce: 'pre',
|
plugins: [{ name: 'request-render-context', enforce: 'pre',
|
||||||
resolveId (id, _importer, options) {
|
resolveId (id, _importer, options) {
|
||||||
const contextPath = path.resolve (__dirname, './src/lib/renderContext')
|
const contextPath = path.resolve (__dirname, './src/lib/renderContext')
|
||||||
@@ -40,4 +42,4 @@ export default defineConfig ({
|
|||||||
rewrite: requestPath => requestPath.replace (/^\/api/, ''),
|
rewrite: requestPath => requestPath.replace (/^\/api/, ''),
|
||||||
secure: false } },
|
secure: false } },
|
||||||
watch: { usePolling: true,
|
watch: { usePolling: true,
|
||||||
interval: 100 } } })
|
interval: 100 } } }))
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ import { defineConfig, mergeConfig } from 'vitest/config'
|
|||||||
import viteConfig from './vite.config'
|
import viteConfig from './vite.config'
|
||||||
|
|
||||||
|
|
||||||
export default mergeConfig (
|
export default defineConfig (env => mergeConfig (
|
||||||
viteConfig,
|
viteConfig (env),
|
||||||
defineConfig ({
|
{ test: { environment: 'jsdom',
|
||||||
test: { environment: 'jsdom',
|
|
||||||
testTimeout: 30_000,
|
testTimeout: 30_000,
|
||||||
exclude: ['**/node_modules/**', '**/dist/**', 'server.ssr.test.mjs'],
|
exclude: ['**/node_modules/**', '**/dist/**', 'server.ssr.test.mjs'],
|
||||||
setupFiles: './src/test/setup.ts',
|
setupFiles: './src/test/setup.ts',
|
||||||
|
|||||||
新しいイシューから参照
ユーザーをブロックする