Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,67 @@ describe('useUpdateMutation', () => {
await screen.findByText('success: true', {}, { timeout: 10000 });
});

it('should return an error', async () => {
const USERNAME_1 = `${testRunPrefix}-2`;
const USERNAME_2 = `${testRunPrefix}-3`;
function Page() {
const { data, count } = useQuery(
client
.from('contact')
.select('id,username', { count: 'exact' })
.in('username', [USERNAME_1, USERNAME_2]),
{
revalidateOnFocus: false,
revalidateOnReconnect: false,
},
);
const { trigger: insert } = useInsertMutation(client.from('contact'), [
'id',
]);
const { trigger: update, error } = useUpdateMutation(
client.from('contact'),
['id'],
'idonotexist',
);
return (
<div>
<div
data-testid="insert"
onClick={async () => await insert([{ username: USERNAME_1 }])}
/>
<div
data-testid="update"
onClick={async () =>
await update({
id: (data ?? []).find((d) => d.username === USERNAME_1)?.id,
username: USERNAME_2,
})
}
/>
<span>
{
data?.find((d) =>
[USERNAME_1, USERNAME_2].includes(d.username ?? ''),
)?.username
}
</span>
<span data-testid="count">{`count: ${count}`}</span>
<span data-testid="error">{`error: ${!!error}`}</span>
</div>
);
}

renderWithConfig(<Page />, { provider: () => provider });
await screen.findByText('count: 0', {}, { timeout: 10000 });

fireEvent.click(screen.getByTestId('insert'));
await screen.findByText(USERNAME_1, {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 1');

fireEvent.click(screen.getByTestId('update'));
await screen.findByText('error: true', {}, { timeout: 10000 });
});

it('should update existing cache item', async () => {
const USERNAME_1 = `${testRunPrefix}-2`;
const USERNAME_2 = `${testRunPrefix}-3`;
Expand Down
Loading