Addons.utils.test.ts215 lines · main
1import { describe, expect, it } from 'vitest'
2
3import {
4 getCustomDomainDisabledReason,
5 getIPv4DisabledReason,
6 getPitrAlertState,
7 getPitrDisabledReason,
8} from './Addons.utils'
9
10describe('getIPv4DisabledReason', () => {
11 it('returns the AWS-only message for non-AWS projects', () => {
12 expect(
13 getIPv4DisabledReason({
14 isAws: false,
15 isProjectActive: true,
16 projectUpdateDisabled: false,
17 canUpdateIPv4: true,
18 ipv4Enabled: false,
19 })
20 ).toBe('Dedicated IPv4 address is only available for AWS projects')
21 })
22
23 it('returns the inactive-project message before other checks', () => {
24 expect(
25 getIPv4DisabledReason({
26 isAws: true,
27 isProjectActive: false,
28 projectUpdateDisabled: true,
29 canUpdateIPv4: false,
30 ipv4Enabled: false,
31 })
32 ).toBe('Project must be active to update IPv4')
33 })
34
35 it('returns the updates-disabled message when project updates are blocked', () => {
36 expect(
37 getIPv4DisabledReason({
38 isAws: true,
39 isProjectActive: true,
40 projectUpdateDisabled: true,
41 canUpdateIPv4: true,
42 ipv4Enabled: false,
43 })
44 ).toBe('Project updates are currently disabled')
45 })
46
47 it('returns the IPv6 requirement when IPv4 cannot be added yet', () => {
48 expect(
49 getIPv4DisabledReason({
50 isAws: true,
51 isProjectActive: true,
52 projectUpdateDisabled: false,
53 canUpdateIPv4: false,
54 ipv4Enabled: false,
55 })
56 ).toBe('You can only add IPv4 when your project network configuration is set to IPv6')
57 })
58
59 it('returns undefined when IPv4 is already enabled', () => {
60 expect(
61 getIPv4DisabledReason({
62 isAws: true,
63 isProjectActive: true,
64 projectUpdateDisabled: false,
65 canUpdateIPv4: false,
66 ipv4Enabled: true,
67 })
68 ).toBeUndefined()
69 })
70})
71
72describe('getPitrDisabledReason', () => {
73 it('returns the inactive-project message first', () => {
74 expect(
75 getPitrDisabledReason({
76 isProjectActive: false,
77 projectUpdateDisabled: true,
78 hasHipaaAddon: true,
79 sufficientPgVersion: false,
80 isOrioleDbInAws: true,
81 })
82 ).toBe('Project must be active to update PITR')
83 })
84
85 it('returns the updates-disabled message before feature-specific checks', () => {
86 expect(
87 getPitrDisabledReason({
88 isProjectActive: true,
89 projectUpdateDisabled: true,
90 hasHipaaAddon: true,
91 sufficientPgVersion: false,
92 isOrioleDbInAws: true,
93 })
94 ).toBe('Project updates are currently disabled')
95 })
96
97 it('returns the HIPAA message when HIPAA is enabled', () => {
98 expect(
99 getPitrDisabledReason({
100 isProjectActive: true,
101 projectUpdateDisabled: false,
102 hasHipaaAddon: true,
103 sufficientPgVersion: true,
104 isOrioleDbInAws: false,
105 })
106 ).toBe('PITR cannot be changed with HIPAA enabled')
107 })
108
109 it('returns the legacy-project message when the database version is too old', () => {
110 expect(
111 getPitrDisabledReason({
112 isProjectActive: true,
113 projectUpdateDisabled: false,
114 hasHipaaAddon: false,
115 sufficientPgVersion: false,
116 isOrioleDbInAws: false,
117 })
118 ).toBe('Your project is too old to enable PITR')
119 })
120
121 it('returns the OrioleDB message when PITR is unsupported', () => {
122 expect(
123 getPitrDisabledReason({
124 isProjectActive: true,
125 projectUpdateDisabled: false,
126 hasHipaaAddon: false,
127 sufficientPgVersion: true,
128 isOrioleDbInAws: true,
129 })
130 ).toBe('Point in time recovery is not supported with OrioleDB')
131 })
132
133 it('returns undefined when PITR can be updated', () => {
134 expect(
135 getPitrDisabledReason({
136 isProjectActive: true,
137 projectUpdateDisabled: false,
138 hasHipaaAddon: false,
139 sufficientPgVersion: true,
140 isOrioleDbInAws: false,
141 })
142 ).toBeUndefined()
143 })
144})
145
146describe('getCustomDomainDisabledReason', () => {
147 it('returns the inactive-project message', () => {
148 expect(
149 getCustomDomainDisabledReason({
150 isProjectActive: false,
151 projectUpdateDisabled: true,
152 })
153 ).toBe('Project must be active to update custom domain')
154 })
155
156 it('returns the updates-disabled message when applicable', () => {
157 expect(
158 getCustomDomainDisabledReason({
159 isProjectActive: true,
160 projectUpdateDisabled: true,
161 })
162 ).toBe('Project updates are currently disabled')
163 })
164
165 it('returns undefined when the custom domain panel can be opened', () => {
166 expect(
167 getCustomDomainDisabledReason({
168 isProjectActive: true,
169 projectUpdateDisabled: false,
170 })
171 ).toBeUndefined()
172 })
173})
174
175describe('getPitrAlertState', () => {
176 it('prefers the HIPAA alert over other blocking reasons', () => {
177 expect(
178 getPitrAlertState({
179 hasHipaaAddon: true,
180 sufficientPgVersion: false,
181 isOrioleDbInAws: true,
182 })
183 ).toBe('hipaa')
184 })
185
186 it('returns the legacy-project alert when HIPAA is not enabled', () => {
187 expect(
188 getPitrAlertState({
189 hasHipaaAddon: false,
190 sufficientPgVersion: false,
191 isOrioleDbInAws: true,
192 })
193 ).toBe('legacy-project')
194 })
195
196 it('returns the OrioleDB alert when it is the remaining blocker', () => {
197 expect(
198 getPitrAlertState({
199 hasHipaaAddon: false,
200 sufficientPgVersion: true,
201 isOrioleDbInAws: true,
202 })
203 ).toBe('orioledb')
204 })
205
206 it('returns undefined when no PITR alert is needed', () => {
207 expect(
208 getPitrAlertState({
209 hasHipaaAddon: false,
210 sufficientPgVersion: true,
211 isOrioleDbInAws: false,
212 })
213 ).toBeUndefined()
214 })
215})