[READ-ONLY] a fast, modern browser for the npm registry
at main 82 lines 2.4 kB view raw
1import { describe, expect, it, vi } from 'vitest' 2import { createConnectorApp } from '../../../cli/src/server.ts' 3 4const TEST_TOKEN = 'test-token-123' 5vi.mock('../../../cli/src/logger.ts', () => { 6 return { 7 logError: () => {}, 8 logDebug: () => {}, 9 } 10}) 11 12describe('connector server', () => { 13 describe('GET /team/:scopeTeam/users', () => { 14 it('returns 400 for invalid scope:team format (missing @ prefix)', async () => { 15 const app = createConnectorApp(TEST_TOKEN) 16 17 const response = await app.fetch( 18 new Request('http://localhost/team/netlify%3Adevelopers/users', { 19 headers: { Authorization: `Bearer ${TEST_TOKEN}` }, 20 }), 21 ) 22 23 expect(response.status).toBe(400) 24 const body = await response.json() 25 expect(body.message).toContain('Invalid scope:team format') 26 }) 27 28 it('returns 401 without auth token', async () => { 29 const app = createConnectorApp(TEST_TOKEN) 30 31 const response = await app.fetch( 32 new Request('http://localhost/team/@netlify%3Adevelopers/users'), 33 ) 34 35 expect(response.status).toBe(401) 36 }) 37 }) 38 39 describe('GET /user/packages', () => { 40 it('returns 401 without auth token', async () => { 41 const app = createConnectorApp(TEST_TOKEN) 42 43 const response = await app.fetch(new Request('http://localhost/user/packages')) 44 45 expect(response.status).toBe(401) 46 }) 47 48 it('returns 401 with invalid auth token', async () => { 49 const app = createConnectorApp(TEST_TOKEN) 50 51 const response = await app.fetch( 52 new Request('http://localhost/user/packages', { 53 headers: { Authorization: 'Bearer wrong-token' }, 54 }), 55 ) 56 57 expect(response.status).toBe(401) 58 }) 59 }) 60 61 describe('GET /user/orgs', () => { 62 it('returns 401 without auth token', async () => { 63 const app = createConnectorApp(TEST_TOKEN) 64 65 const response = await app.fetch(new Request('http://localhost/user/orgs')) 66 67 expect(response.status).toBe(401) 68 }) 69 70 it('returns 401 with invalid auth token', async () => { 71 const app = createConnectorApp(TEST_TOKEN) 72 73 const response = await app.fetch( 74 new Request('http://localhost/user/orgs', { 75 headers: { Authorization: 'Bearer wrong-token' }, 76 }), 77 ) 78 79 expect(response.status).toBe(401) 80 }) 81 }) 82})