first commit

This commit is contained in:
2025-04-24 13:11:28 +08:00
commit ff9c54d5e4
5960 changed files with 834111 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { expect } from 'chai'
import isInFreeTrial from '../../../../../frontend/js/features/subscription/util/is-in-free-trial'
import dateformat from 'dateformat'
describe('isInFreeTrial', function () {
it('returns false when no date sent', function () {
expect(isInFreeTrial()).to.be.false
})
it('returns false when date is null', function () {
expect(isInFreeTrial(null)).to.be.false
})
it('returns false when date is in the past', function () {
expect(isInFreeTrial('2000-02-16T17:59:07.000Z')).to.be.false
})
it('returns true when date is in the future', function () {
const today = new Date()
const sevenDaysFromToday = new Date().setDate(today.getDate() + 7)
const sevenDaysFromTodayFormatted = dateformat(
sevenDaysFromToday,
'dS mmmm yyyy'
)
expect(isInFreeTrial(sevenDaysFromTodayFormatted)).to.be.true
})
})

View File

@@ -0,0 +1,17 @@
import { expect } from 'chai'
import isMonthlyCollaboratorPlan from '../../../../../frontend/js/features/subscription/util/is-monthly-collaborator-plan'
describe('isMonthlyCollaboratorPlan', function () {
it('returns false when a plan code without "collaborator" ', function () {
expect(isMonthlyCollaboratorPlan('test', false)).to.be.false
})
it('returns false when on a plan with "collaborator" and "ann"', function () {
expect(isMonthlyCollaboratorPlan('collaborator-annual', false)).to.be.false
})
it('returns false when on a plan with "collaborator" and without "ann" but is a group plan', function () {
expect(isMonthlyCollaboratorPlan('collaborator', true)).to.be.false
})
it('returns true when on a plan with non-group "collaborator" monthly plan', function () {
expect(isMonthlyCollaboratorPlan('collaborator', false)).to.be.true
})
})

View File

@@ -0,0 +1,37 @@
import { expect } from 'chai'
import { formatPriceForDisplayData } from '../../../../../frontend/js/features/subscription/util/recurly-pricing'
describe('formatPriceForDisplayData', function () {
it('should handle no tax rate', function () {
const data = formatPriceForDisplayData('1000', 0, 'USD', 'en')
expect(data).to.deep.equal({
totalForDisplay: '$1,000',
totalAsNumber: 1000,
subtotal: '$1,000.00',
tax: '$0.00',
includesTax: false,
})
})
it('should handle a tax rate', function () {
const data = formatPriceForDisplayData('380', 0.2, 'EUR', 'en')
expect(data).to.deep.equal({
totalForDisplay: '€456',
totalAsNumber: 456,
subtotal: '€380.00',
tax: '€76.00',
includesTax: true,
})
})
it('should handle total with cents', function () {
const data = formatPriceForDisplayData('8', 0.2, 'EUR', 'en')
expect(data).to.deep.equal({
totalForDisplay: '€9.60',
totalAsNumber: 9.6,
subtotal: '€8.00',
tax: '€1.60',
includesTax: true,
})
})
})

View File

@@ -0,0 +1,68 @@
import { expect } from 'chai'
import showDowngradeOption from '../../../../../frontend/js/features/subscription/util/show-downgrade-option'
import dateformat from 'dateformat'
describe('showDowngradeOption', function () {
const today = new Date()
const sevenDaysFromToday = new Date().setDate(today.getDate() + 7)
const sevenDaysFromTodayFormatted = dateformat(
sevenDaysFromToday,
'dS mmmm yyyy'
)
it('returns false when no trial end date', function () {
expect(showDowngradeOption('collab')).to.be.false
})
it('returns false when a plan code without "collaborator" ', function () {
expect(showDowngradeOption('test', false, sevenDaysFromTodayFormatted)).to
.be.false
})
it('returns false when on a plan with trial date in future but has "collaborator" and "ann" in plan code', function () {
expect(
showDowngradeOption(
'collaborator-annual',
false,
sevenDaysFromTodayFormatted
)
).to.be.false
})
it('returns false when on a plan with trial date in future and plan code has "collaborator" and no "ann" but is a group plan', function () {
expect(
showDowngradeOption('collaborator', true, sevenDaysFromTodayFormatted)
).to.be.false
})
it('returns false when on a plan with "collaborator" and without "ann" and trial date in future', function () {
expect(
showDowngradeOption('collaborator', false, sevenDaysFromTodayFormatted)
).to.be.false
})
it('returns true when on a plan with "collaborator" and without "ann" and no trial date', function () {
expect(showDowngradeOption('collaborator', false)).to.be.true
})
it('returns true when on a plan with "collaborator" and without "ann" and trial date is in the past', function () {
expect(
showDowngradeOption('collaborator', false, '2000-02-16T17:59:07.000Z')
).to.be.true
})
it('returns false when on a monthly collaborator plan with a pending pause', function () {
expect(
showDowngradeOption(
'collaborator',
false,
null,
'2030-01-01T12:00:00.000Z'
)
).to.be.false
})
it('returns false when on a monthly collaborator plan with an active pause', function () {
expect(
showDowngradeOption(
'collaborator',
false,
null,
'2030-01-01T12:00:00.000Z',
5
)
).to.be.false
})
})