edgeFunctions.test.ts67 lines · main
1import { describe, expect, it } from 'vitest'
2
3import { isValidEdgeFunctionURL } from './edgeFunctions'
4
5describe('isValidEdgeFunctionURL', () => {
6 const validEdgeFunctionUrls = [
7 'https://uniquetwentychararef.supabase.co/functions/v1/hello-world',
8 'https://uniquetwentychararef.briven.red/functions/v1/hello-world',
9 'https://uniquetwentychararef.briven.red/functions/v3/hello-world',
10 'https://uniquetwentychararef.briven.red/functions/v3/hello-world',
11 ]
12
13 const validLocalEdgeFunctionsUrls = [
14 'https://projectref.notbriven.com/functions/v1/test',
15 'https://notbriven.com/functions/v1/test',
16 'http://localhost:54321/functions/v1/test-2',
17 'http://kong:8000/functions/v1/hello-world',
18 'https://127.0.0.1:54321/functions/v1/test-3',
19 'https://127.0.0.1:54321/functions/v1/test-5',
20 ]
21
22 const invalidPlatformEdgeFunctionUrls = [
23 'https://notbriven.com/functions/v1/test',
24 'https://projectref.notbriven.com/functions/v1/test',
25 'https://localhost?https://aaaa.supabase.co/functions/v1/xxx',
26 'https://localhost:3000/?https://aaaa.supabase.co/functions/v1/xxx',
27 'http://localhost:3000/?https://aaaa.supabase.co/functions/v1/xxx',
28 ]
29
30 const invalidEdgeFunctionUrls = [
31 'https://localhost?https://aaaa.supabase.co/functions/v1/xxx',
32 'https://localhost:3000/?https://aaaa.supabase.co/functions/v1/xxx',
33 'http://localhost:3000/?https://aaaa.supabase.co/functions/v1/xxx',
34 ]
35
36 it('should match valid edge function URLs on platform', () => {
37 for (const url of validEdgeFunctionUrls) {
38 expect(isValidEdgeFunctionURL(url, true), `Expected ${url} to be valid`).toBe(true)
39 }
40 })
41
42 it('should not match local URLs on platform', () => {
43 for (const url of validLocalEdgeFunctionsUrls) {
44 expect(isValidEdgeFunctionURL(url, true), `Expected ${url} to be invalid on platform`).toBe(
45 false
46 )
47 }
48 })
49
50 it('should match valid local edge function URLs off platform', () => {
51 for (const url of validLocalEdgeFunctionsUrls) {
52 expect(isValidEdgeFunctionURL(url, false), `Expected ${url} to be valid`).toBe(true)
53 }
54 })
55
56 it('should not match invalid edge function URLs on platform', () => {
57 for (const url of invalidPlatformEdgeFunctionUrls) {
58 expect(isValidEdgeFunctionURL(url, true), `Expected ${url} to be invalid`).toBe(false)
59 }
60 })
61
62 it('should not match invalid edge function URLs off platform', () => {
63 for (const url of invalidEdgeFunctionUrls) {
64 expect(isValidEdgeFunctionURL(url, false), `Expected ${url} to be invalid`).toBe(false)
65 }
66 })
67})