PlatformWebhooksPage.utils.test.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { beforeEach, describe, expect, it } from 'vitest'
  2. import {
  3. clearPendingSigningSecretReveal,
  4. getPendingSigningSecretReveal,
  5. resetPendingSigningSecretRevealForTests,
  6. setPendingSigningSecretReveal,
  7. shouldHandleEndpointNotFound,
  8. } from './PlatformWebhooksPage.utils'
  9. describe('PlatformWebhooksPage.utils', () => {
  10. const endpointId = '7f2c9d4a-6e31-4d9d-9a1f-2c4b5e6f7081'
  11. const otherEndpointId = '1a4e8c73-5b29-44af-8c62-9f1d2b3c4d5e'
  12. const missingEndpointId = '00000000-0000-4000-8000-000000000000'
  13. beforeEach(() => {
  14. resetPendingSigningSecretRevealForTests()
  15. })
  16. it('returns false when endpoint id is absent', () => {
  17. expect(
  18. shouldHandleEndpointNotFound({
  19. endpointId: undefined,
  20. hasSelectedEndpoint: false,
  21. pendingCreatedEndpointId: null,
  22. })
  23. ).toBe(false)
  24. })
  25. it('returns false when endpoint is selected', () => {
  26. expect(
  27. shouldHandleEndpointNotFound({
  28. endpointId,
  29. hasSelectedEndpoint: true,
  30. pendingCreatedEndpointId: null,
  31. })
  32. ).toBe(false)
  33. })
  34. it('returns false while route is transitioning to a newly created endpoint', () => {
  35. expect(
  36. shouldHandleEndpointNotFound({
  37. endpointId,
  38. hasSelectedEndpoint: false,
  39. pendingCreatedEndpointId: endpointId,
  40. })
  41. ).toBe(false)
  42. })
  43. it('returns true for invalid endpoint routes', () => {
  44. expect(
  45. shouldHandleEndpointNotFound({
  46. endpointId: missingEndpointId,
  47. hasSelectedEndpoint: false,
  48. pendingCreatedEndpointId: null,
  49. })
  50. ).toBe(true)
  51. })
  52. it('stores and reads pending signing secret reveal for matching endpoint route', () => {
  53. setPendingSigningSecretReveal('project', {
  54. endpointId,
  55. signingSecret: 'whsec_example',
  56. })
  57. expect(getPendingSigningSecretReveal('project', endpointId)).toEqual({
  58. endpointId,
  59. signingSecret: 'whsec_example',
  60. })
  61. })
  62. it('ignores pending signing secret reveal when endpoint route does not match', () => {
  63. setPendingSigningSecretReveal('project', {
  64. endpointId,
  65. signingSecret: 'whsec_example',
  66. })
  67. expect(getPendingSigningSecretReveal('project', otherEndpointId)).toBeNull()
  68. })
  69. it('clears pending signing secret reveal', () => {
  70. setPendingSigningSecretReveal('project', {
  71. endpointId,
  72. signingSecret: 'whsec_example',
  73. })
  74. clearPendingSigningSecretReveal('project')
  75. expect(getPendingSigningSecretReveal('project', endpointId)).toBeNull()
  76. })
  77. })