ipal-doctor: the raw 2FA view warning only for a view component
R3-1: the warning fired on any mention of the 2FA package's setup / verify view in the config, so it stayed after the fix its own text suggests (SafeTotpView with the path as ipalTotpView, plus the path in admin.dependencies). It now warns only when the path is a view's Component. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
b2c1dca5da
commit
3eee841dd0
+26
-7
@@ -68,15 +68,34 @@ describe('importmap rule and the 2FA back-link check', () => {
|
||||
expect(messages(older).join()).not.toContain('SafeTotpView')
|
||||
})
|
||||
|
||||
test("warns when the config registers the 2FA package's own view itself", async () => {
|
||||
describe("the 2FA package's own view in the config", () => {
|
||||
const map = entries('@clocklimited/payload-2fa/rsc#TOTPSetup', '@intecion/ipal-kit/admin#TotpRedirectProvider', '@intecion/ipal-kit/admin#SafeTotpView')
|
||||
const admin = 'export { SafeTotpView } from "./x.js"; export { TotpRedirectProvider } from "./y.js"'
|
||||
const own = "twoFactor: { plugin: payloadTotp }, admin: { components: { views: { Mine: { Component: '@clocklimited/payload-2fa/rsc#TOTPVerify', path: '/my-verify' } } } }"
|
||||
const raw = await doctor(project({ ...withPlugin(admin), [MAP]: map, 'src/payload.config.ts': own }), ['importmap'])
|
||||
const NOTE = /^warning: the config names the 2FA package's own setup \/ verify view/
|
||||
expect(messages(raw).filter((m) => NOTE.test(m))).toHaveLength(1)
|
||||
const plain = await doctor(project({ ...withPlugin(admin), [MAP]: map, 'src/payload.config.ts': 'twoFactor: { plugin: payloadTotp }' }), ['importmap'])
|
||||
expect(messages(plain).filter((m) => NOTE.test(m))).toEqual([])
|
||||
const NOTE = /^warning: the config registers the 2FA package's own setup \/ verify view/
|
||||
const notes = async (config: string) =>
|
||||
messages(await doctor(project({ ...withPlugin(admin), [MAP]: map, 'src/payload.config.ts': `twoFactor: { plugin: payloadTotp }, ${config}` }), ['importmap'])).filter((m) => NOTE.test(m))
|
||||
const RAW = '@clocklimited/payload-2fa/rsc#TOTPVerify'
|
||||
|
||||
test.each([
|
||||
['a string component', `admin: { components: { views: { Mine: { Component: '${RAW}', path: '/my-verify' } } } }`],
|
||||
['an object component', `admin: { components: { views: { Mine: { Component: { path: "${RAW}", serverProps: { a: 1 } }, path: '/my-verify' } } } }`],
|
||||
['an object component over several lines', `views: { Mine: { Component: {\n clientProps,\n path: \`${RAW}\`,\n}, path: '/my-verify' } }`],
|
||||
['the setup view', "views: { Mine: { Component: '@clocklimited/payload-2fa/rsc#TOTPSetup', path: '/my-setup' } }"],
|
||||
])('warns for %s', async (_name, config) => {
|
||||
expect(await notes(config)).toHaveLength(1)
|
||||
})
|
||||
|
||||
test.each([
|
||||
['no such view', ''],
|
||||
// the fix the warning itself suggests
|
||||
['the wrapper with the raw path as ipalTotpView, and the path in admin.dependencies',
|
||||
`admin: { components: { views: { Mine: { Component: { path: '@intecion/ipal-kit/admin#SafeTotpView', serverProps: { ipalTotpView: '${RAW}' } }, path: '/my-verify' } } }, dependencies: { 'my-verify': { path: '${RAW}', type: 'component' } } }`],
|
||||
['the wrapper with serverProps written first', `views: { Mine: { Component: { serverProps: { ipalTotpView: '${RAW}' }, path: '@intecion/ipal-kit/admin#SafeTotpView' }, path: '/my-verify' } }`],
|
||||
['a dependencies entry alone', `admin: { dependencies: { keep: { type: 'component', path: '${RAW}' } } }`],
|
||||
['a comment', `// Component: '${RAW}'`],
|
||||
])('does not warn for %s', async (_name, config) => {
|
||||
expect(await notes(config)).toEqual([])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user