Skip to content
Snippets Groups Projects

[test] add readonly test

Merged Elodie Thiéblin requested to merge topic/default/test_useQuery_readonly into branch/default
1 file
+ 30
0
Compare changes
  • Side-by-side
  • Inline
+ 30
0
@@ -39,4 +39,34 @@ describe('useQuery', () => {
});
expect(result.current.resultsAndVariables.results.status).toBe('error');
});
it('should return an error in query is insert in readonly mode', async () => {
const queryRows = (query: string) => {
return Promise.resolve('Error in your query');
};
rqlClient.queryRows = queryRows.bind(rqlClient);
const {result} = renderHook(() =>
useQuery({rqlClient, readonly: true})
);
act(() => {
result.current.setQuery('INSERT 123 name "toto"');
});
await act(async () => {
await result.current.executeQuery();
});
expect(result.current.resultsAndVariables.results.status).toBe('error');
expect(result.current.isForbiddenQuery).toBe(true);
act(() => {
result.current.setQuery('Any X WHERE X is Toto');
});
await act(async () => {
await result.current.executeQuery();
});
expect(result.current.resultsAndVariables.results.status).toBe(
'success'
);
expect(result.current.isForbiddenQuery).toBe(false);
});
});
Loading