Skip to content

Commit

Permalink
DISPLAY_SELF_HOSTED_EXPIRATION_BANNER probably (#3695)
Browse files Browse the repository at this point in the history
Co-authored-by: katia-sentry <[email protected]>
Co-authored-by: Jerry Feng <[email protected]>
  • Loading branch information
3 people authored Jan 30, 2025
1 parent 57a466b commit e9ca127
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const defaultConfig = {
GH_APP: DEFAULT_GH_APP,
GH_APP_AI: 'codecov-ai',
SUNBURST_ENABLED: true,
DISPLAY_SELF_HOSTED_EXPIRATION_BANNER: true,
}

export function removeReactAppPrefix(obj) {
Expand All @@ -38,6 +39,11 @@ export function removeReactAppPrefix(obj) {
keys['SUNBURST_ENABLED'] = keys['SUNBURST_ENABLED'].toLowerCase() === 'true'
}

if ('DISPLAY_SELF_HOSTED_EXPIRATION_BANNER' in keys) {
keys['DISPLAY_SELF_HOSTED_EXPIRATION_BANNER'] =
keys['DISPLAY_SELF_HOSTED_EXPIRATION_BANNER'].toLowerCase() === 'true'
}

if ('SENTRY_TRACING_SAMPLE_RATE' in keys) {
keys['SENTRY_TRACING_SAMPLE_RATE'] = parseFloat(
keys['SENTRY_TRACING_SAMPLE_RATE']
Expand Down
10 changes: 10 additions & 0 deletions src/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ describe('config', () => {
})
})

describe('sets DISPLAY_SELF_HOSTED_EXPIRATION_BANNER to boolean', () => {
it('sets to true', () => {
const obj = { DISPLAY_SELF_HOSTED_EXPIRATION_BANNER: 'true' }

expect(removeReactAppPrefix(obj)).toEqual({
DISPLAY_SELF_HOSTED_EXPIRATION_BANNER: true,
})
})
})

describe('sets IS_DEDICATED_NAMESPACE to boolean', () => {
it('sets to true', () => {
const obj = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ describe('SelfHostedLicenseExpiration', () => {
expect(resolveIssueButton).not.toBeInTheDocument()
})

it('does not render the banner when disabled', async () => {
config.IS_SELF_HOSTED = true
config.IS_DEDICATED_NAMESPACE = true
config.DISPLAY_SELF_HOSTED_EXPIRATION_BANNER = false
setup({
seatsUsed: 5,
seatsLimit: 10,
expirationDate: null,
})
render(<SelfHostedLicenseExpiration />, { wrapper: wrapper(['']) })

const resolveIssueButton = screen.queryByText(/Resolve issue/)
expect(resolveIssueButton).not.toBeInTheDocument()
})

it('does not render the banner when there are no seats used', async () => {
config.IS_SELF_HOSTED = true
config.IS_DEDICATED_NAMESPACE = true
Expand Down Expand Up @@ -200,6 +215,7 @@ describe('SelfHostedLicenseExpiration', () => {
vi.setSystemTime(new Date('2023-08-01'))
config.IS_SELF_HOSTED = true
config.IS_DEDICATED_NAMESPACE = true
config.DISPLAY_SELF_HOSTED_EXPIRATION_BANNER = true
})

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ const SelfHostedLicenseExpiration = () => {
const isLicenseExpiringWithin30Days = dateDiff < 31 && dateDiff >= 0

const shouldDisplayBanner =
isSeatsLimitReached || isLicenseExpired || isLicenseExpiringWithin30Days
(isSeatsLimitReached ||
isLicenseExpired ||
isLicenseExpiringWithin30Days) &&
config.DISPLAY_SELF_HOSTED_EXPIRATION_BANNER

if (!shouldDisplayBanner) {
return null
Expand Down

0 comments on commit e9ca127

Please sign in to comment.