Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/endpoint/src/schemas/Invalidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export default class Invalidate<
args: readonly any[],
unvisit: (schema: any, input: any) => any,
): AbstractInstanceType<E> {
// TODO: is this really always going to be the full object - validate that calling fetch will give this even when input is a string
return unvisit(this._entity, id) as any;
// TODO: this return type should offer string, but we need to figure out an ergonomic way to do this
return unvisit(this._entity, id) ?? id;
}

/* istanbul ignore next */
Expand Down
45 changes: 45 additions & 0 deletions packages/react/src/hooks/__tests__/useController/fetch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,51 @@ describe.each([
expect(warnSpy.mock.calls.length).toBe(0);
});

it('should return denormalized value when schema is present (delete)', async () => {
const { controller } = renderDataClient(
() => {
return 'hi';
},
{
resolverFixtures: [
{
endpoint: CoolerArticleResource.delete,
args: [{ id: payload.id }],
response: payload,
},
],
},
);
const ret = await controller.fetch(CoolerArticleResource.delete, {
id: payload.id,
});
expect(ret.content).toEqual(payload.content);
expect(ret).toBeInstanceOf(CoolerArticle);
expect(warnSpy.mock.calls.length).toBe(0);
});

it('should return denormalized value when schema is present (delete with string response)', async () => {
const { controller } = renderDataClient(
() => {
return 'hi';
},
{
resolverFixtures: [
{
endpoint: CoolerArticleResource.delete,
args: [{ id: payload.id }],
response: payload.id,
},
],
},
);
const ret = await controller.fetch(CoolerArticleResource.delete, {
id: payload.id,
});
expect(ret).toEqual(payload.id);
expect(warnSpy.mock.calls.length).toBe(0);
});

it('should return denormalized value when schema is present (unions)', async () => {
const response = [
null,
Expand Down