| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- import { describe, expect, it } from 'vitest'
- import {
- getCustomDomainDisabledReason,
- getIPv4DisabledReason,
- getPitrAlertState,
- getPitrDisabledReason,
- } from './Addons.utils'
- describe('getIPv4DisabledReason', () => {
- it('returns the AWS-only message for non-AWS projects', () => {
- expect(
- getIPv4DisabledReason({
- isAws: false,
- isProjectActive: true,
- projectUpdateDisabled: false,
- canUpdateIPv4: true,
- ipv4Enabled: false,
- })
- ).toBe('Dedicated IPv4 address is only available for AWS projects')
- })
- it('returns the inactive-project message before other checks', () => {
- expect(
- getIPv4DisabledReason({
- isAws: true,
- isProjectActive: false,
- projectUpdateDisabled: true,
- canUpdateIPv4: false,
- ipv4Enabled: false,
- })
- ).toBe('Project must be active to update IPv4')
- })
- it('returns the updates-disabled message when project updates are blocked', () => {
- expect(
- getIPv4DisabledReason({
- isAws: true,
- isProjectActive: true,
- projectUpdateDisabled: true,
- canUpdateIPv4: true,
- ipv4Enabled: false,
- })
- ).toBe('Project updates are currently disabled')
- })
- it('returns the IPv6 requirement when IPv4 cannot be added yet', () => {
- expect(
- getIPv4DisabledReason({
- isAws: true,
- isProjectActive: true,
- projectUpdateDisabled: false,
- canUpdateIPv4: false,
- ipv4Enabled: false,
- })
- ).toBe('You can only add IPv4 when your project network configuration is set to IPv6')
- })
- it('returns undefined when IPv4 is already enabled', () => {
- expect(
- getIPv4DisabledReason({
- isAws: true,
- isProjectActive: true,
- projectUpdateDisabled: false,
- canUpdateIPv4: false,
- ipv4Enabled: true,
- })
- ).toBeUndefined()
- })
- })
- describe('getPitrDisabledReason', () => {
- it('returns the inactive-project message first', () => {
- expect(
- getPitrDisabledReason({
- isProjectActive: false,
- projectUpdateDisabled: true,
- hasHipaaAddon: true,
- sufficientPgVersion: false,
- isOrioleDbInAws: true,
- })
- ).toBe('Project must be active to update PITR')
- })
- it('returns the updates-disabled message before feature-specific checks', () => {
- expect(
- getPitrDisabledReason({
- isProjectActive: true,
- projectUpdateDisabled: true,
- hasHipaaAddon: true,
- sufficientPgVersion: false,
- isOrioleDbInAws: true,
- })
- ).toBe('Project updates are currently disabled')
- })
- it('returns the HIPAA message when HIPAA is enabled', () => {
- expect(
- getPitrDisabledReason({
- isProjectActive: true,
- projectUpdateDisabled: false,
- hasHipaaAddon: true,
- sufficientPgVersion: true,
- isOrioleDbInAws: false,
- })
- ).toBe('PITR cannot be changed with HIPAA enabled')
- })
- it('returns the legacy-project message when the database version is too old', () => {
- expect(
- getPitrDisabledReason({
- isProjectActive: true,
- projectUpdateDisabled: false,
- hasHipaaAddon: false,
- sufficientPgVersion: false,
- isOrioleDbInAws: false,
- })
- ).toBe('Your project is too old to enable PITR')
- })
- it('returns the OrioleDB message when PITR is unsupported', () => {
- expect(
- getPitrDisabledReason({
- isProjectActive: true,
- projectUpdateDisabled: false,
- hasHipaaAddon: false,
- sufficientPgVersion: true,
- isOrioleDbInAws: true,
- })
- ).toBe('Point in time recovery is not supported with OrioleDB')
- })
- it('returns undefined when PITR can be updated', () => {
- expect(
- getPitrDisabledReason({
- isProjectActive: true,
- projectUpdateDisabled: false,
- hasHipaaAddon: false,
- sufficientPgVersion: true,
- isOrioleDbInAws: false,
- })
- ).toBeUndefined()
- })
- })
- describe('getCustomDomainDisabledReason', () => {
- it('returns the inactive-project message', () => {
- expect(
- getCustomDomainDisabledReason({
- isProjectActive: false,
- projectUpdateDisabled: true,
- })
- ).toBe('Project must be active to update custom domain')
- })
- it('returns the updates-disabled message when applicable', () => {
- expect(
- getCustomDomainDisabledReason({
- isProjectActive: true,
- projectUpdateDisabled: true,
- })
- ).toBe('Project updates are currently disabled')
- })
- it('returns undefined when the custom domain panel can be opened', () => {
- expect(
- getCustomDomainDisabledReason({
- isProjectActive: true,
- projectUpdateDisabled: false,
- })
- ).toBeUndefined()
- })
- })
- describe('getPitrAlertState', () => {
- it('prefers the HIPAA alert over other blocking reasons', () => {
- expect(
- getPitrAlertState({
- hasHipaaAddon: true,
- sufficientPgVersion: false,
- isOrioleDbInAws: true,
- })
- ).toBe('hipaa')
- })
- it('returns the legacy-project alert when HIPAA is not enabled', () => {
- expect(
- getPitrAlertState({
- hasHipaaAddon: false,
- sufficientPgVersion: false,
- isOrioleDbInAws: true,
- })
- ).toBe('legacy-project')
- })
- it('returns the OrioleDB alert when it is the remaining blocker', () => {
- expect(
- getPitrAlertState({
- hasHipaaAddon: false,
- sufficientPgVersion: true,
- isOrioleDbInAws: true,
- })
- ).toBe('orioledb')
- })
- it('returns undefined when no PITR alert is needed', () => {
- expect(
- getPitrAlertState({
- hasHipaaAddon: false,
- sufficientPgVersion: true,
- isOrioleDbInAws: false,
- })
- ).toBeUndefined()
- })
- })
|