github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/services/share.spec.ts (about) 1 import { Result } from '@webapp/util/fp'; 2 import { ZodError } from 'zod'; 3 import { shareWithFlamegraphDotcom } from './share'; 4 import { setupServer, rest } from './testUtils'; 5 // TODO move this testData to somewhere else 6 import TestData from './TestData'; 7 8 describe('Share', () => { 9 let server: ReturnType<typeof setupServer> | null; 10 11 afterEach(() => { 12 if (server) { 13 server.close(); 14 } 15 server = null; 16 }); 17 18 describe('shareWithFlamegraphDotcom', () => { 19 it('works', async () => { 20 server = setupServer( 21 rest.post(`http://localhost/export`, (req, res, ctx) => { 22 return res(ctx.status(200), ctx.json({ url: 'http://myurl.com' })); 23 }) 24 ); 25 26 server.listen(); 27 const res = await shareWithFlamegraphDotcom({ 28 name: 'myname', 29 flamebearer: TestData, 30 }); 31 32 expect(res).toMatchObject( 33 Result.ok({ 34 url: 'http://myurl.com', 35 }) 36 ); 37 }); 38 39 it('fails if response doesnt contain the key', async () => { 40 server = setupServer( 41 rest.post(`http://localhost/export`, (req, res, ctx) => { 42 return res(ctx.status(200), ctx.json({})); 43 }) 44 ); 45 server.listen(); 46 47 const res = await shareWithFlamegraphDotcom({ 48 name: 'myname', 49 flamebearer: TestData, 50 }); 51 expect(res.error).toBeInstanceOf(ZodError); 52 }); 53 }); 54 });