mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
fix: add refresh context to schema for loader args (#11960)
* fix: add refresh context to schema for loader args * fix negative match test
This commit is contained in:
parent
f13c357753
commit
4410130df7
4 changed files with 16 additions and 3 deletions
5
.changeset/cuddly-shoes-press.md
Normal file
5
.changeset/cuddly-shoes-press.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes an issue where the refresh context data was not passed correctly to content layer loaders
|
|
@ -80,6 +80,7 @@ const collectionConfigParser = z.union([
|
|||
parseData: z.any(),
|
||||
generateDigest: z.function(z.tuple([z.any()], z.string())),
|
||||
watcher: z.any().optional(),
|
||||
refreshContextData: z.record(z.unknown()).optional(),
|
||||
}),
|
||||
],
|
||||
z.unknown(),
|
||||
|
|
|
@ -87,7 +87,10 @@ describe('Content Layer', () => {
|
|||
assert.ok(json.hasOwnProperty('probes'));
|
||||
assert.ok(Array.isArray(json.probes));
|
||||
assert.equal(json.probes.length, 5);
|
||||
assert.equal(json.probes.at(-1).id, 'philae-lander', 'Voyager probes should not be included');
|
||||
assert.ok(
|
||||
json.probes.every(({ id }) => !id.startsWith('voyager')),
|
||||
'Voyager probes should not be included',
|
||||
);
|
||||
});
|
||||
|
||||
it('Returns data entry by id', async () => {
|
||||
|
@ -290,16 +293,18 @@ describe('Content Layer', () => {
|
|||
const rawJsonResponse = await fixture.fetch('/collections.json');
|
||||
const initialJson = devalue.parse(await rawJsonResponse.text());
|
||||
assert.equal(initialJson.increment.data.lastValue, 1);
|
||||
const now = new Date().toISOString();
|
||||
|
||||
const refreshResponse = await fixture.fetch('/_refresh', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({}),
|
||||
body: JSON.stringify({ now }),
|
||||
});
|
||||
const refreshData = await refreshResponse.json();
|
||||
assert.equal(refreshData.message, 'Content refreshed successfully');
|
||||
const updatedJsonResponse = await fixture.fetch('/collections.json');
|
||||
const updated = devalue.parse(await updatedJsonResponse.text());
|
||||
assert.equal(updated.increment.data.lastValue, 2);
|
||||
assert.deepEqual(updated.increment.data.refreshContextData, { webhookBody: { now } });
|
||||
});
|
||||
|
||||
it('updates collection when data file is changed', async () => {
|
||||
|
|
|
@ -123,7 +123,7 @@ const images = defineCollection({
|
|||
const increment = defineCollection({
|
||||
loader: {
|
||||
name: 'increment-loader',
|
||||
load: async ({ store }) => {
|
||||
load: async ({ store, refreshContextData }) => {
|
||||
const entry = store.get<{ lastValue: number }>('value');
|
||||
const lastValue = entry?.data.lastValue ?? 0;
|
||||
store.set({
|
||||
|
@ -131,6 +131,7 @@ const increment = defineCollection({
|
|||
data: {
|
||||
lastValue: lastValue + 1,
|
||||
lastUpdated: new Date(),
|
||||
refreshContextData
|
||||
},
|
||||
});
|
||||
},
|
||||
|
@ -139,6 +140,7 @@ const increment = defineCollection({
|
|||
z.object({
|
||||
lastValue: z.number(),
|
||||
lastUpdated: z.date(),
|
||||
refreshContextData: z.record(z.unknown()),
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue