Addons.utils.test.ts 5.7 KB

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