Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
test: cover studio plugin registration
  • Loading branch information
Entr0zy committed May 30, 2026
commit 7122d2cc2abf203e372660e6c96af961688384b9
68 changes: 68 additions & 0 deletions 68 plugins/studio/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { describe, expect, it, vi } from 'vitest'
import { StudioPlugin } from './index'

function basicAuth(username: string, password: string) {
return `Basic ${btoa(`${username}:${password}`)}`
}

describe('StudioPlugin', () => {
it('registers the default studio route and serves authenticated studio HTML', async () => {
const get = vi.fn()
const app = { get }
const plugin = new StudioPlugin({
username: 'admin',
password: 'secret',
apiKey: 'starbase-api-key',
})

await plugin.register(app as never)

expect(get).toHaveBeenCalledTimes(1)
expect(get).toHaveBeenCalledWith('/studio', expect.any(Function))

const routeHandler = get.mock.calls[0][1]
const response = await routeHandler({
req: {
raw: new Request('https://example.com/studio', {
headers: {
Authorization: basicAuth('admin', 'secret'),
},
}),
},
})

await expect(response.text()).resolves.toContain(
'Authorization": "Bearer starbase-api-key"'
)
expect(response.headers.get('Content-Type')).toBe('text/html')
})

it('uses a custom route prefix when provided', async () => {
const get = vi.fn()
const plugin = new StudioPlugin({
username: 'admin',
password: 'secret',
apiKey: 'key',
prefix: '/internal/studio',
})

await plugin.register({ get } as never)

expect(get).toHaveBeenCalledWith(
'/internal/studio',
expect.any(Function)
)
})

it('does not register a route when the prefix is disabled', async () => {
const get = vi.fn()
const plugin = new StudioPlugin({
apiKey: 'key',
prefix: '',
})

await plugin.register({ get } as never)

expect(get).not.toHaveBeenCalled()
})
})
Morty Proxy This is a proxified and sanitized view of the page, visit original site.