feat: add context to auth and globals local API (#4449)
* feat: add context to auth and globals local API * chore: add int test
This commit is contained in:
@@ -67,6 +67,10 @@ export const DataHooksGlobal: GlobalConfig = {
|
||||
|
||||
afterRead: [
|
||||
({ global, field, context }) => {
|
||||
if (context['field_beforeChange_GlobalAndField_override']) {
|
||||
return context['field_beforeChange_GlobalAndField_override']
|
||||
}
|
||||
|
||||
return (
|
||||
(context['field_beforeChange_GlobalAndField'] as string) +
|
||||
JSON.stringify(global) +
|
||||
|
||||
@@ -251,6 +251,22 @@ describe('Hooks', () => {
|
||||
expect(retrievedDoc.value).toEqual('data from local API')
|
||||
})
|
||||
|
||||
it('should pass context from local API to global hooks', async () => {
|
||||
const globalDocument = await payload.findGlobal({
|
||||
slug: dataHooksGlobalSlug,
|
||||
})
|
||||
|
||||
expect(globalDocument.field_globalAndField).not.toEqual('data from local API context')
|
||||
|
||||
const globalDocumentWithContext = await payload.findGlobal({
|
||||
slug: dataHooksGlobalSlug,
|
||||
context: {
|
||||
field_beforeChange_GlobalAndField_override: 'data from local API context',
|
||||
},
|
||||
})
|
||||
expect(globalDocumentWithContext.field_globalAndField).toEqual('data from local API context')
|
||||
})
|
||||
|
||||
it('should pass context from rest API to hooks', async () => {
|
||||
const params = new URLSearchParams({
|
||||
context_secretValue: 'data from rest API',
|
||||
|
||||
Reference in New Issue
Block a user