Files
supabase/apps/studio/components/interfaces/Database/CronJobs/CronJobs.utils.test.ts
T
Ivan VasilovandJoshen Lim fd3309c886 feat: UI for pg-cron (#29291)
* Add crons option in the database menu.

* Add react-hook-form to the studio package.json.

* Refactor the functionSelector to be used by other features.

* Add the bulk of the functionality for the cron UI. Some of the code is copy-pasted from functions feature, needs to be cleaned before merging.

* Tons of changes, the Create Cron sheet works now.

* Added some more functionality for the cronjob feature.

* Convert the Cron table to a listing with cards.

* Add click-to-copy in the Auth Hooks feature.

* Remove extra prop.

* Fix type errors.

* Fix some random issues. Fix the tests.

* Fix the tests.

* Add a style for disabled radio button item.

* Make the default SQL snippet. Handle the case pg_net is not installed.

* Fix the heading and save button when creating a new cron job.

* Change the name of the custom label in the schedule dropdown.

* Minor fixes.

* Rename all mentions of cronjobs to cron jobs.

* Always show the cron jobs link.

* Rename the link from crons to cron-jobs.

* Fix the disabled state for the stacked radio group.

* More minor fixes.

* More small fixes.

* Fix the tests.

* Minor UI tweaks

* More minor tweaks

* Add padding bottom

* Add feature flag for the cron ui.

* Fix the SQL function option.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-10-03 15:11:17 -02:30

38 lines
1.3 KiB
TypeScript

import { it } from 'vitest'
import { parseCronJobCommand } from './CronJobs.utils'
describe('parseCronJobCommand', () => {
it('should return a default object when the command is null', () => {
expect(parseCronJobCommand('')).toStrictEqual({ snippet: '', type: 'sql_snippet' })
})
it('should return a default object when the command is random', () => {
const command = 'some random text'
expect(parseCronJobCommand(command)).toStrictEqual({
snippet: 'some random text',
type: 'sql_snippet',
})
})
it('should return a sql function command when the command is CALL auth.jwt ()', () => {
const command = 'CALL auth.jwt ()'
expect(parseCronJobCommand(command)).toStrictEqual({
type: 'sql_function',
schema: 'auth',
functionName: 'jwt',
})
})
it('should return a edge function config when the command posts to supabase.co', () => {
const command = `select net.http_post( url:='https://_.supabase.co/functions/v1/_', headers:=jsonb_build_object(), body:=jsonb_build_object(), timeout_milliseconds:=5000 );`
expect(parseCronJobCommand(command)).toStrictEqual({
edgeFunctionName: 'https://_.supabase.co/functions/v1/_',
method: 'POST',
httpHeaders: [],
httpParameters: [],
timeoutMs: 5000,
type: 'edge_function',
})
})
})