Skip to content

Commit

Permalink
feat: Use a scaling review factor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Artmann committed Sep 26, 2023
1 parent 816995b commit 4949e14
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
9 changes: 5 additions & 4 deletions app/revenue/calculate-revenue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ describe('Calculate Revenue', () => {
describe('calculateRevenue', () => {

it('calculates the gross revenue.', () => {
expect(calculateRevenue(100, 10)).toEqual(45000)
expect(calculateRevenue(1000, 15)).toEqual(675000)
expect(calculateRevenue(10000, 4.99)).toEqual(2245500)
expect(calculateRevenue(50030, 59.99)).toEqual(135058486.5)
expect(calculateRevenue(100, 10)).toEqual(20_000)
expect(calculateRevenue(1_000, 10)).toEqual(360_000)
expect(calculateRevenue(25_000, 10)).toEqual(12_250_000)
expect(calculateRevenue(50_000, 10)).toEqual(29_500_000)
expect(calculateRevenue(500_000, 10)).toEqual(240_000_000)
})

})
Expand Down
23 changes: 22 additions & 1 deletion app/revenue/calculate-revenue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ export interface RevenueBreakdown {
}

export function calculateRevenue(numberOfReviews: number, price: number): number {
const numberOfCopiesSold = numberOfReviews * 45.0
// Source: https://newsletter.gamediscover.co/p/steam-sales-estimates-why-game-popularity
const K = () => {
if (numberOfReviews < 999) {
return 20
}

if (numberOfReviews < 9999) {
return 36
}

if (numberOfReviews < 49999) {
return 49
}

if (numberOfReviews < 99999) {
return 59
}

return 48
}

const numberOfCopiesSold = numberOfReviews * K()
const grossRevenue = numberOfCopiesSold * price

return grossRevenue
Expand Down
1 change: 1 addition & 0 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from 'react'

import { Page } from '~/components/page'
import { calculateRevenue, revenueBreakdown } from '~/revenue'
import { RevenueBreakdownTable } from '~/revenue/revenue-breakdown-table'
Expand Down
7 changes: 6 additions & 1 deletion app/tests/routes/game-page.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import '@testing-library/jest-dom'
import { render, screen } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'

import GameRoute from '~/routes/app.$id.$slug'

Expand Down Expand Up @@ -33,7 +34,11 @@ describe('GameRoute', () => {
}
}))

render(<GameRoute />)
render(
<MemoryRouter>
<GameRoute />
</MemoryRouter>
)

expect(screen.getByTestId('title')).toHaveTextContent('Rust')
expect(screen.getByTestId('description')).toHaveTextContent(
Expand Down
13 changes: 9 additions & 4 deletions app/tests/routes/home-page.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
import '@testing-library/jest-dom'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MemoryRouter } from 'react-router-dom'

import HomePageRoute from '~/routes/_index'

describe('HomePageRoute', () => {
it('uses the price and number of reviews to calculate the gross & net revenue.', async () => {
render(<HomePageRoute />)
render(
<MemoryRouter>
<HomePageRoute />
</MemoryRouter>
)

expect(screen.getByTestId('gross-revenue')).toHaveTextContent('$1,038,807')
expect(screen.getByTestId('gross-revenue')).toHaveTextContent('$831,046')

await userEvent.clear(screen.getByLabelText('Reviews'))
await userEvent.type(screen.getByLabelText('Reviews'), '2300')

await userEvent.clear(screen.getByLabelText('Price'))
await userEvent.type(screen.getByLabelText('Price'), '6.99')

expect(screen.getByTestId('gross-revenue')).toHaveTextContent('$723,465')
expect(screen.getByTestId('gross-revenue')).toHaveTextContent('$578,772')

expect(screen.getByTestId('net-revenue')).toHaveTextContent('$213,422.18')
expect(screen.getByTestId('net-revenue')).toHaveTextContent('$170,737.74')
})
})

0 comments on commit 4949e14

Please sign in to comment.