Skip to content

Commit

Permalink
Fix Env Var
Browse files Browse the repository at this point in the history
  • Loading branch information
jedtan committed Jul 14, 2023
1 parent 89fdf61 commit 170a09d
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ NEXT_PUBLIC_GROWTHBOOK_ENV=dev

########## Estimated Money Per Tab ##########

NEXT_EST_MONEY_RAISED_PER_TAB=0.000765
NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB=0.000765
2 changes: 1 addition & 1 deletion .env.local.info
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ NEXT_PUBLIC_GROWTHBOOK_ENV=local

########## Estimated Money Per Tab ##########

NEXT_EST_MONEY_RAISED_PER_TAB=0.000765
NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB=0.000765
2 changes: 1 addition & 1 deletion .env.preview.info
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ NEXT_PUBLIC_GROWTHBOOK_ENV=dev

########## Estimated Money Per Tab ##########

NEXT_EST_MONEY_RAISED_PER_TAB=0.000765
NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB=0.000765
2 changes: 1 addition & 1 deletion .env.production.info
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ NEXT_PUBLIC_GROWTHBOOK_ENV=production

########## Estimated Money Per Tab ##########

NEXT_EST_MONEY_RAISED_PER_TAB=0.000765
NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB=0.000765
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const getMockProps = () => ({
})

beforeEach(() => {
process.env.NEXT_EST_MONEY_RAISED_PER_TAB = 0.00001
process.env.NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB = 0.00001
})

describe('GroupImpactLeaderboard component', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const getMockProps = () => ({
})

beforeEach(() => {
process.env.NEXT_EST_MONEY_RAISED_PER_TAB = 0.00001
process.env.NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB = 0.00001
})

describe('GroupImpactLeaderboardRow component', () => {
Expand Down
14 changes: 7 additions & 7 deletions src/utils/__tests__/misc.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
jest.mock('../logger')

beforeEach(() => {
process.env.NEXT_EST_MONEY_RAISED_PER_TAB = '0.01287'
process.env.NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB = '0.01287'
})

afterEach(() => {
Expand All @@ -10,25 +10,25 @@ afterEach(() => {

describe('globals', () => {
it('returns the estimated money raised per tab [test #1]', () => {
process.env.NEXT_EST_MONEY_RAISED_PER_TAB = '0.01287'
process.env.NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB = '0.01287'
const { getEstimatedMoneyRaisedPerTab } = require('../misc')
expect(getEstimatedMoneyRaisedPerTab()).toBe(0.01287)
})

it('returns the estimated money raised per tab [test #2]', () => {
process.env.NEXT_EST_MONEY_RAISED_PER_TAB = '2'
process.env.NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB = '2'
const { getEstimatedMoneyRaisedPerTab } = require('../misc')
expect(getEstimatedMoneyRaisedPerTab()).toBe(2.0)
})

it('returns 0 for the estimated money raised per tab if process.env.NEXT_EST_MONEY_RAISED_PER_TAB is undefined', () => {
process.env.NEXT_EST_MONEY_RAISED_PER_TAB = undefined
it('returns 0 for the estimated money raised per tab if process.env.NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB is undefined', () => {
process.env.NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB = undefined
const { getEstimatedMoneyRaisedPerTab } = require('../misc')
expect(getEstimatedMoneyRaisedPerTab()).toBe(0.0)
})

it('returns 0 for the estimated money raised per tab if process.env.NEXT_EST_MONEY_RAISED_PER_TAB does not parse into a float', () => {
process.env.NEXT_EST_MONEY_RAISED_PER_TAB = 'xyz'
it('returns 0 for the estimated money raised per tab if process.env.NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB does not parse into a float', () => {
process.env.NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB = 'xyz'
const { getEstimatedMoneyRaisedPerTab } = require('../misc')
expect(getEstimatedMoneyRaisedPerTab()).toBe(0.0)
})
Expand Down
4 changes: 2 additions & 2 deletions src/utils/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import logger from './logger'
* @return {Number}
*/
export const getEstimatedMoneyRaisedPerTab = () => {
let moneyRaised = parseFloat(process.env.NEXT_EST_MONEY_RAISED_PER_TAB)
let moneyRaised = parseFloat(process.env.NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB)
if (Number.isNaN(moneyRaised)) {
moneyRaised = 0.0
logger.error(
`Could not parse float from money raised env var value ${process.env.NEXT_EST_MONEY_RAISED_PER_TAB}`
`Could not parse float from money raised env var value ${process.env.NEXT_PUBLIC_EST_MONEY_RAISED_PER_TAB}`
)
}
return moneyRaised
Expand Down

0 comments on commit 170a09d

Please sign in to comment.