PlatformWebhooks.utils.test.ts36 lines · main
1import { afterEach, describe, expect, it, vi } from 'vitest'
2
3import {
4 generateWebhookEndpointName,
5 getWebhookEndpointDisplayName,
6} from './PlatformWebhooks.utils'
7
8describe('PlatformWebhooks.utils', () => {
9 afterEach(() => {
10 vi.restoreAllMocks()
11 })
12
13 it('returns the trimmed endpoint name when present', () => {
14 expect(
15 getWebhookEndpointDisplayName({
16 name: ' Billing events ',
17 url: 'https://hooks.example.com/billing',
18 })
19 ).toBe('Billing events')
20 })
21
22 it('falls back to the endpoint url when the name is empty', () => {
23 expect(
24 getWebhookEndpointDisplayName({
25 name: ' ',
26 url: 'https://hooks.example.com/fallback',
27 })
28 ).toBe('https://hooks.example.com/fallback')
29 })
30
31 it('generates an adjective-noun endpoint name', () => {
32 vi.spyOn(Math, 'random').mockReturnValueOnce(0).mockReturnValueOnce(0.1)
33
34 expect(generateWebhookEndpointName()).toBe('swift-courier')
35 })
36})