-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test case for billing and workspaceLock compnent. (#3781)
- Loading branch information
Rajat Dabade
authored
Oct 20, 2023
1 parent
f12abfb
commit e12cf3e
Showing
8 changed files
with
450 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
frontend/src/container/BillingContainer/BillingContainer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
import { billingSuccessResponse } from 'mocks-server/__mockdata__/billing'; | ||
import { | ||
notOfTrailResponse, | ||
trialConvertedToSubscriptionResponse, | ||
} from 'mocks-server/__mockdata__/licenses'; | ||
import { server } from 'mocks-server/server'; | ||
import { rest } from 'msw'; | ||
import { act, render, screen } from 'tests/test-utils'; | ||
import { getFormattedDate } from 'utils/timeUtils'; | ||
|
||
import BillingContainer from './BillingContainer'; | ||
|
||
const lisenceUrl = 'http://localhost/api/v2/licenses'; | ||
|
||
describe('BillingContainer', () => { | ||
test('Component should render', async () => { | ||
act(() => { | ||
render(<BillingContainer />); | ||
}); | ||
const unit = screen.getAllByText(/unit/i); | ||
expect(unit[1]).toBeInTheDocument(); | ||
const dataInjection = screen.getByRole('columnheader', { | ||
name: /data ingested/i, | ||
}); | ||
expect(dataInjection).toBeInTheDocument(); | ||
const pricePerUnit = screen.getByRole('columnheader', { | ||
name: /price per unit/i, | ||
}); | ||
expect(pricePerUnit).toBeInTheDocument(); | ||
const cost = screen.getByRole('columnheader', { | ||
name: /cost \(billing period to date\)/i, | ||
}); | ||
expect(cost).toBeInTheDocument(); | ||
|
||
const total = screen.getByRole('cell', { | ||
name: /total/i, | ||
}); | ||
expect(total).toBeInTheDocument(); | ||
|
||
const manageBilling = screen.getByRole('button', { | ||
name: /manage billing/i, | ||
}); | ||
expect(manageBilling).toBeInTheDocument(); | ||
|
||
const dollar = screen.getByRole('cell', { | ||
name: /\$0/i, | ||
}); | ||
expect(dollar).toBeInTheDocument(); | ||
|
||
const currentBill = screen.getByRole('heading', { | ||
name: /current bill total/i, | ||
}); | ||
expect(currentBill).toBeInTheDocument(); | ||
}); | ||
|
||
test('OnTrail', async () => { | ||
act(() => { | ||
render(<BillingContainer />); | ||
}); | ||
|
||
const freeTrailText = await screen.findByText('Free Trial'); | ||
expect(freeTrailText).toBeInTheDocument(); | ||
|
||
const currentBill = await screen.findByRole('heading', { | ||
name: /current bill total/i, | ||
}); | ||
expect(currentBill).toBeInTheDocument(); | ||
|
||
const dollar0 = await screen.findByText(/\$0/i); | ||
expect(dollar0).toBeInTheDocument(); | ||
const onTrail = await screen.findByText( | ||
/You are in free trial period. Your free trial will end on 20 Oct 2023/i, | ||
); | ||
expect(onTrail).toBeInTheDocument(); | ||
|
||
const numberOfDayRemaining = await screen.findByText( | ||
/1 days remaining in your billing period./i, | ||
); | ||
expect(numberOfDayRemaining).toBeInTheDocument(); | ||
const upgradeButton = await screen.findAllByRole('button', { | ||
name: /upgrade/i, | ||
}); | ||
expect(upgradeButton[1]).toBeInTheDocument(); | ||
expect(upgradeButton.length).toBe(2); | ||
const checkPaidPlan = await screen.findByText( | ||
/Check out features in paid plans/i, | ||
); | ||
expect(checkPaidPlan).toBeInTheDocument(); | ||
|
||
const link = screen.getByRole('link', { name: /here/i }); | ||
expect(link).toBeInTheDocument(); | ||
}); | ||
|
||
test('OnTrail but trialConvertedToSubscription', async () => { | ||
server.use( | ||
rest.get(lisenceUrl, (req, res, ctx) => | ||
res(ctx.status(200), ctx.json(trialConvertedToSubscriptionResponse)), | ||
), | ||
); | ||
|
||
act(() => { | ||
render(<BillingContainer />); | ||
}); | ||
|
||
const currentBill = await screen.findByRole('heading', { | ||
name: /current bill total/i, | ||
}); | ||
expect(currentBill).toBeInTheDocument(); | ||
|
||
const dollar0 = await screen.findByText(/\$0/i); | ||
expect(dollar0).toBeInTheDocument(); | ||
|
||
const onTrail = await screen.findByText( | ||
/You are in free trial period. Your free trial will end on 20 Oct 2023/i, | ||
); | ||
expect(onTrail).toBeInTheDocument(); | ||
|
||
const receivedCardDetails = await screen.findByText( | ||
/We have received your card details, your billing will only start after the end of your free trial period./i, | ||
); | ||
expect(receivedCardDetails).toBeInTheDocument(); | ||
|
||
const manageBillingButton = await screen.findByRole('button', { | ||
name: /manage billing/i, | ||
}); | ||
expect(manageBillingButton).toBeInTheDocument(); | ||
|
||
const dayRemainingInBillingPeriod = await screen.findByText( | ||
/1 days remaining in your billing period./i, | ||
); | ||
expect(dayRemainingInBillingPeriod).toBeInTheDocument(); | ||
}); | ||
|
||
test('Not on ontrail', async () => { | ||
server.use( | ||
rest.get(lisenceUrl, (req, res, ctx) => | ||
res(ctx.status(200), ctx.json(notOfTrailResponse)), | ||
), | ||
); | ||
render(<BillingContainer />); | ||
|
||
const billingPeriodText = `Your current billing period is from ${getFormattedDate( | ||
billingSuccessResponse.data.billingPeriodStart, | ||
)} to ${getFormattedDate(billingSuccessResponse.data.billingPeriodEnd)}`; | ||
|
||
const billingPeriod = await screen.findByRole('heading', { | ||
name: new RegExp(billingPeriodText, 'i'), | ||
}); | ||
expect(billingPeriod).toBeInTheDocument(); | ||
|
||
const currentBill = await screen.findByRole('heading', { | ||
name: /current bill total/i, | ||
}); | ||
expect(currentBill).toBeInTheDocument(); | ||
|
||
const dollar0 = await screen.findAllByText(/\$1278.3/i); | ||
expect(dollar0[0]).toBeInTheDocument(); | ||
expect(dollar0.length).toBe(2); | ||
|
||
const metricsRow = await screen.findByRole('row', { | ||
name: /metrics Million 4012 0.1 \$ 401.2/i, | ||
}); | ||
expect(metricsRow).toBeInTheDocument(); | ||
|
||
const logRow = await screen.findByRole('row', { | ||
name: /Logs GB 497 0.4 \$ 198.8/i, | ||
}); | ||
expect(logRow).toBeInTheDocument(); | ||
|
||
const totalBill = await screen.findByRole('cell', { | ||
name: /\$1278/i, | ||
}); | ||
expect(totalBill).toBeInTheDocument(); | ||
|
||
const totalBillRow = await screen.findByRole('row', { | ||
name: /total \$1278/i, | ||
}); | ||
expect(totalBillRow).toBeInTheDocument(); | ||
|
||
screen.debug(); | ||
}); | ||
|
||
test('Should render corrent day remaining in billing period', async () => { | ||
server.use( | ||
rest.get(lisenceUrl, (req, res, ctx) => | ||
res(ctx.status(200), ctx.json(notOfTrailResponse)), | ||
), | ||
); | ||
render(<BillingContainer />); | ||
const dayRemainingInBillingPeriod = await screen.findByText( | ||
/11 days remaining in your billing period./i, | ||
); | ||
expect(dayRemainingInBillingPeriod).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
export const billingSuccessResponse = { | ||
status: 'success', | ||
data: { | ||
billingPeriodStart: 1697197809, | ||
billingPeriodEnd: 1698777000, | ||
details: { | ||
total: 1278.3, | ||
breakdown: [ | ||
{ | ||
type: 'Metrics', | ||
unit: 'Million', | ||
tiers: [ | ||
{ | ||
unitPrice: 0.1, | ||
quantity: 4012, | ||
tierStart: 0, | ||
tierEnd: 0, | ||
tierCost: 401.2, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'Traces', | ||
unit: 'GB', | ||
tiers: [ | ||
{ | ||
unitPrice: 0.3, | ||
quantity: 2261, | ||
tierStart: 0, | ||
tierEnd: 0, | ||
tierCost: 678.3, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'Logs', | ||
unit: 'GB', | ||
tiers: [ | ||
{ | ||
unitPrice: 0.4, | ||
quantity: 497, | ||
tierStart: 0, | ||
tierEnd: 0, | ||
tierCost: 198.8, | ||
}, | ||
], | ||
}, | ||
], | ||
baseFee: 199, | ||
billTotal: 1278.3, | ||
}, | ||
discount: 0, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
export const licensesSuccessResponse = { | ||
status: 'success', | ||
data: { | ||
trialStart: 1695992049, | ||
trialEnd: 1697806449, | ||
onTrial: true, | ||
workSpaceBlock: false, | ||
trialConvertedToSubscription: false, | ||
gracePeriodEnd: -1, | ||
licenses: [ | ||
{ | ||
key: 'testKeyId1', | ||
activationId: 'testActivationId1', | ||
ValidationMessage: '', | ||
isCurrent: false, | ||
planKey: 'ENTERPRISE_PLAN', | ||
ValidFrom: '2022-10-13T13:48:51Z', | ||
ValidUntil: '2023-10-13T19:37:37Z', | ||
status: 'VALID', | ||
}, | ||
{ | ||
key: 'testKeyId2', | ||
activationId: 'testActivationId2', | ||
ValidationMessage: '', | ||
isCurrent: true, | ||
planKey: 'ENTERPRISE_PLAN', | ||
ValidFrom: '2023-09-12T11:35:43Z', | ||
ValidUntil: '2024-09-11T17:24:29Z', | ||
status: 'VALID', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export const trialConvertedToSubscriptionResponse = { | ||
status: 'success', | ||
data: { | ||
trialStart: 1695992049, | ||
trialEnd: 1697806449, | ||
onTrial: true, | ||
workSpaceBlock: false, | ||
trialConvertedToSubscription: true, | ||
gracePeriodEnd: -1, | ||
licenses: [ | ||
{ | ||
key: 'testKeyId1', | ||
activationId: 'testActivationId1', | ||
ValidationMessage: '', | ||
isCurrent: false, | ||
planKey: 'ENTERPRISE_PLAN', | ||
ValidFrom: '2022-10-13T13:48:51Z', | ||
ValidUntil: '2023-10-13T19:37:37Z', | ||
status: 'VALID', | ||
}, | ||
{ | ||
key: 'testKeyId2', | ||
activationId: 'testActivationId2', | ||
ValidationMessage: '', | ||
isCurrent: true, | ||
planKey: 'ENTERPRISE_PLAN', | ||
ValidFrom: '2023-09-12T11:35:43Z', | ||
ValidUntil: '2024-09-11T17:24:29Z', | ||
status: 'VALID', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export const notOfTrailResponse = { | ||
...trialConvertedToSubscriptionResponse, | ||
data: { | ||
...trialConvertedToSubscriptionResponse.data, | ||
onTrial: false, | ||
trialConvertedToSubscriptionResponse: false, | ||
trialStart: -1, | ||
trialEnd: -1, | ||
}, | ||
}; | ||
|
||
export const workSpaceBlockResponse = { | ||
...trialConvertedToSubscriptionResponse, | ||
data: { | ||
...trialConvertedToSubscriptionResponse.data, | ||
onTrial: false, | ||
trialConvertedToSubscriptionResponse: false, | ||
trialStart: -1, | ||
trialEnd: -1, | ||
workSpaceBlock: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.