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