PlatformWebhooks.utils.test.ts 971 B

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