mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 22:29:11 +03:00
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { stripIndent } from 'common-tags'
|
|
import { checkDestructiveQuery } from 'components/interfaces/SQLEditor/SQLEditor.utils'
|
|
|
|
describe(`destructive query check`, () => {
|
|
it('drop statement matches', () => {
|
|
const match = checkDestructiveQuery('drop table films, distributors;')
|
|
|
|
expect(match).toBe(true)
|
|
})
|
|
|
|
it('truncate statement matches', () => {
|
|
const match = checkDestructiveQuery('truncate films;')
|
|
|
|
expect(match).toBe(true)
|
|
})
|
|
|
|
it('delete statement matches', () => {
|
|
const match = checkDestructiveQuery("delete from films where kind <> 'Musical';")
|
|
|
|
expect(match).toBe(true)
|
|
})
|
|
|
|
it('delete statement after another statement matches', () => {
|
|
const match = checkDestructiveQuery(stripIndent`
|
|
select * from films;
|
|
|
|
delete from films where kind <> 'Musical';
|
|
`)
|
|
|
|
expect(match).toBe(true)
|
|
})
|
|
|
|
it("rls policy containing delete doesn't match", () => {
|
|
const match = checkDestructiveQuery(stripIndent`
|
|
create policy "Users can delete their own files"
|
|
on storage.objects for delete to authenticated using (
|
|
bucket id = 'files' and auth.uid () = owner
|
|
);
|
|
`)
|
|
|
|
expect(match).toBe(false)
|
|
})
|
|
|
|
it('capitalized statement matches', () => {
|
|
const match = checkDestructiveQuery("DELETE FROM films WHERE kind <> 'Musical';")
|
|
|
|
expect(match).toBe(true)
|
|
})
|
|
|
|
it("comment containing keyword doesn't match", () => {
|
|
const match = checkDestructiveQuery(stripIndent`
|
|
-- Going to drop this in here, might delete later
|
|
select * from films;
|
|
`)
|
|
|
|
expect(match).toBe(false)
|
|
})
|
|
})
|