Hub 2.21.0: install the Church Website; Website storage bought in steps
- New install offers the Church Website: Accounts first when the church has none, at accounts.<its address> (www. dropped); the FastPanel email sends a www. site's bare domain to www. with a 301. - Licence.extraStorageSteps (migration): the token sends a Website its limit (5 GB + steps, limits.storageBytes, contracts 1.17.0); invoices bill the steps bought instead of the storage reported. Edit popup field 0-99. - A Website/App licence starts on its plan however it's made (New install too). - Vendored @crosscode/contracts 1.17.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ jest.mock('../src/config/db', () => ({}));
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { hub } = require('@crosscode/contracts');
|
||||
const { TIERS, WEBSITE_PLANS, APP_TIERS, tierForBand, appTierForBand, planPrice, extraStorageBlocks } = require('../src/utils/billing/tiers');
|
||||
const { TIERS, WEBSITE_PLANS, APP_TIERS, tierForBand, appTierForBand, planPrice, extraStorageBlocks, storageLimitBytes } = require('../src/utils/billing/tiers');
|
||||
const { day, ymd, addMonths, addDays, today, saHour, periodLabel, money } = require('../src/utils/billing/dates');
|
||||
const { draftCustomerInvoice, customerInvoiceLines, planChangesOf, cleanLines, totals, invoiceState, statement, recipientFor } = require('../src/utils/billing/compute');
|
||||
|
||||
@@ -78,6 +78,14 @@ describe('tiers', () => {
|
||||
expect(extraStorageBlocks({ usedBytes: 11 * GB })).toBe(2);
|
||||
expect(extraStorageBlocks(null)).toBe(0);
|
||||
});
|
||||
|
||||
test("2.21.0: a Website's storage limit is 5 GB plus the steps bought", () => {
|
||||
expect(storageLimitBytes(0)).toBe(5 * GB);
|
||||
expect(storageLimitBytes(2)).toBe(15 * GB);
|
||||
expect(storageLimitBytes(undefined)).toBe(5 * GB);
|
||||
expect(storageLimitBytes(-1)).toBe(5 * GB);
|
||||
expect(storageLimitBytes(1000)).toBe(500 * GB);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dates', () => {
|
||||
@@ -214,18 +222,23 @@ describe('drafting an invoice (several products, Hub 2.0)', () => {
|
||||
expect(invoice.lines.some(l => /Bundle|Accounts/.test(l.description))).toBe(false);
|
||||
});
|
||||
|
||||
test('extra website storage: R20 per 5 GB a month, never discounted', () => {
|
||||
const { invoice } = draft(customer({ founding: true }), [events(), website({ install: { product: 'website', stats: { storage: { usedBytes: 12 * GB, includedBytes: 5 * GB } } } })]);
|
||||
test('extra website storage: R20 per 5 GB bought a month, never discounted', () => {
|
||||
const { invoice } = draft(customer({ founding: true }), [events(), website({ extraStorageSteps: 2, install: { product: 'website', stats: { storage: { usedBytes: 7 * GB, includedBytes: 15 * GB } } } })]);
|
||||
expect(invoice.lines.at(-1)).toEqual({ description: 'Extra website storage: 2 × 5 GB, December 2026', quantity: 2, unitCents: 2000, amountCents: 4000 });
|
||||
// The bundle comes off the products only: (360 + 64) × 15% = R63.60.
|
||||
expect(invoice.lines.find(l => /Bundle/.test(l.description)).amountCents).toBe(-6360);
|
||||
});
|
||||
|
||||
test('yearly: add-ons are 12 months\' price (decision 2), products 10', () => {
|
||||
const { invoice } = draft(customer({ billingCycle: 'yearly', reviewDate: day('2027-12-01') }), [website({ install: { product: 'website', stats: { storage: { usedBytes: 8 * GB } } } })]);
|
||||
const { invoice } = draft(customer({ billingCycle: 'yearly', reviewDate: day('2027-12-01') }), [website({ extraStorageSteps: 1 })]);
|
||||
expect(invoice.lines.map(l => [l.quantity, l.unitCents])).toEqual([[10, 9900], [12, 2000]]);
|
||||
});
|
||||
|
||||
test('2.21.0: storage is billed on the steps bought, not on what the site reports using', () => {
|
||||
const { invoice } = draft(customer(), [website({ install: { product: 'website', stats: { storage: { usedBytes: 12 * GB, includedBytes: 5 * GB } } } })]);
|
||||
expect(invoice.lines.some(l => /storage/.test(l.description))).toBe(false);
|
||||
});
|
||||
|
||||
test('the App is reviewed on its active members', () => {
|
||||
const { invoice } = draft(customer({ nextInvoiceDate: day('2027-01-01') }), [app({ billedUntil: day('2026-12-31'), install: { product: 'app', stats: { activeMembers90d: '301–750' } } })]);
|
||||
expect(invoice.planChange).toEqual([expect.objectContaining({ licenceId: 'l3', product: 'app', from: 'Mustard Seed', to: 'Congregation', toMonthlyCents: 39900, band: '301–750' })]);
|
||||
|
||||
@@ -88,6 +88,12 @@ describe('licences', () => {
|
||||
await expect(generateLicence(mockDb, { customerId: 'c2', product: 'events', data: {} })).resolves.toBeTruthy();
|
||||
});
|
||||
|
||||
test('2.21.0: a Website licence starts on the Website plan and an App one on the first tier, however it is made', async () => {
|
||||
expect((await generateLicence(mockDb, { customerId: 'c1', product: 'website' })).licence.plan).toBe('Website');
|
||||
expect((await generateLicence(mockDb, { customerId: 'c1', product: 'app' })).licence.plan).toBe('Mustard Seed');
|
||||
expect((await generateLicence(mockDb, { customerId: 'c2', product: 'website', data: { plan: 'Custom' } })).licence.plan).toBe('Custom');
|
||||
});
|
||||
|
||||
test('a revoked licence can be replaced', async () => {
|
||||
const { licence } = await generateLicence(mockDb, { customerId: 'c1', product: 'events', data: {} });
|
||||
licence.status = 'revoked';
|
||||
|
||||
@@ -8,7 +8,7 @@ jest.mock('../src/utils/mail', () => ({ sendMail: jest.fn(async m => { mockMails
|
||||
process.env.HUB_ENCRYPTION_KEY = 'test-encryption-key-test-encryption-key';
|
||||
process.env.FRONTEND_URL = 'https://hub.test';
|
||||
|
||||
const { agent } = require('@crosscode/contracts');
|
||||
const { agent, hub } = require('@crosscode/contracts');
|
||||
const signing = require('@crosscode/contracts/signing');
|
||||
const db = require('../src/config/db');
|
||||
const servers = require('../src/utils/servers');
|
||||
@@ -473,7 +473,7 @@ describe('Accounts from the Hub (2.3.0)', () => {
|
||||
await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW);
|
||||
await expect(jobs.newInstall({ product: 'accounts', customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'accounts.hope.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'BUSY' });
|
||||
await expect(jobs.newInstall({ product: 'accounts', customerId: 'cust-1', serverId: other.id, shortName: 'hope', domain: 'accounts.hope.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'OTHER_SERVER' });
|
||||
await expect(jobs.newInstall({ product: 'website', customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'www.hope.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'BAD_REQUEST' });
|
||||
await expect(jobs.newInstall({ product: 'app', customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'app.hope.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'BAD_REQUEST' });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -539,6 +539,63 @@ describe('Cross Events 3.0 brings its Accounts (2.5.0)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('the Church Website from the Hub (2.21.0)', () => {
|
||||
const poll = (server) => jobs.poll(server, { agentApiVersion: 1, agentVersion: '1.1.0', mode: 'church', runningJobId: null }, NOW);
|
||||
beforeEach(async () => {
|
||||
await db.release.create({ data: { id: 'rw1', product: 'website', version: '1.0.0', notes: '- First release', requires: [{ product: 'accounts', version: '1.7.0' }], releasedAt: NOW } });
|
||||
await db.release.create({ data: { id: 'ra7', product: 'accounts', version: '1.7.0', notes: '- Brand style', releasedAt: NOW } });
|
||||
});
|
||||
|
||||
test('a new church: Accounts first at accounts.<its domain>, then the Website on www., with a CCW- licence on the Website plan', async () => {
|
||||
const { server } = await joinServer();
|
||||
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
|
||||
const out = await jobs.newInstall({ product: 'website', customerId: 'cust-1', serverId: server.id, shortName: 'grace', domain: 'www.grace.co.za' }, admin, NOW);
|
||||
expect(out.alsoInstalling).toEqual({ product: 'accounts', domain: 'accounts.grace.co.za', version: '1.7.0' });
|
||||
const [first] = (await poll(server)).jobs;
|
||||
expect(first).toMatchObject({ type: 'install', args: { products: ['accounts'] } });
|
||||
await jobs.receiveReport(server, signedReport(first, 'succeeded', { result: { versions: { accounts: 'accounts@1.7.0' } } }), NOW);
|
||||
const [second] = (await poll(server)).jobs;
|
||||
expect(second).toMatchObject({ type: 'add-product', args: { church: 'grace', product: 'website', version: 'website@1.0.0', domain: 'www.grace.co.za' } });
|
||||
expect(agent.agentJobSchema.safeParse(second).success).toBe(true);
|
||||
const key = signing.openConfig(second.config, keys.x.privateKeyPem).install.website.HUB_LICENCE_KEY;
|
||||
expect(key).toMatch(/^CCW-/);
|
||||
expect(await db.licence.findFirst({ where: { key } })).toMatchObject({ product: 'website', plan: 'Website' });
|
||||
});
|
||||
|
||||
test('on a Cross Code address, Accounts goes in front of it', async () => {
|
||||
const { server } = await joinServer();
|
||||
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
|
||||
const out = await jobs.newInstall({ product: 'website', customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'hope.crosscode.co.za' }, admin, NOW);
|
||||
expect(out.alsoInstalling.domain).toBe('accounts.hope.crosscode.co.za');
|
||||
});
|
||||
|
||||
test("the FastPanel steps send the bare domain to www. with a 301; a Cross Code address has no such step", async () => {
|
||||
const own = await jobs.fastPanelText({ id: 'd1', product: 'website', shortName: 'grace', domain: 'www.grace.co.za', webPort: 20010, apiPort: 20011, customer: { name: 'Grace' } });
|
||||
expect(own).toContain('Add grace.co.za as an alias');
|
||||
expect(own).toContain('return 301 https://www.grace.co.za$request_uri;');
|
||||
expect(own).toContain('DNS: www.grace.co.za and grace.co.za');
|
||||
expect(own).toContain('location ^~ /api/ {');
|
||||
const crosscode = await jobs.fastPanelText({ id: 'd2', product: 'website', shortName: 'hope', domain: 'hope.crosscode.co.za', webPort: 20012, apiPort: 20013, customer: { name: 'Hope' } });
|
||||
expect(crosscode).not.toContain('301');
|
||||
const events = await jobs.fastPanelText({ id: 'd3', product: 'events', shortName: 'hope', domain: 'www.hope.co.za', webPort: 20014, apiPort: 20015, customer: { name: 'Hope' } });
|
||||
expect(events).not.toContain('301');
|
||||
});
|
||||
});
|
||||
|
||||
describe("a Website licence carries its storage limit (2.21.0)", () => {
|
||||
const GB = 1024 ** 3;
|
||||
const licenceToken = require('../src/utils/licenceToken');
|
||||
const base = { id: '0b6f2c1e-8a3d-4f5b-9c7e-1d2e3f4a5b6c', customerId: '1c7a3d2f-9b4e-4a6c-8d8f-2e3f4a5b6c7d', plan: 'Website', status: 'active', expiresAt: null, graceDays: 14 };
|
||||
|
||||
test('5 GB plus the steps bought, valid for contracts 1.17.0; other products have none', () => {
|
||||
const p = licenceToken.buildPayload({ ...base, product: 'website', extraStorageSteps: 2 }, { id: '2d8b4e3a-0c5f-4b7d-9e9a-3f4a5b6c7d8e' }, 'Grace', NOW);
|
||||
expect(p.limits.storageBytes).toBe(15 * GB);
|
||||
expect(hub.licencePayloadSchema.safeParse(p).success).toBe(true);
|
||||
expect(licenceToken.buildPayload({ ...base, product: 'website' }, { id: '2d8b4e3a-0c5f-4b7d-9e9a-3f4a5b6c7d8e' }, 'Grace', NOW).limits.storageBytes).toBe(5 * GB);
|
||||
expect(licenceToken.buildPayload({ ...base, product: 'events', plan: 'Seed', extraStorageSteps: 3 }, { id: '2d8b4e3a-0c5f-4b7d-9e9a-3f4a5b6c7d8e' }, 'Grace', NOW).limits).not.toHaveProperty('storageBytes');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('settings for servers (found in the VM test)', () => {
|
||||
test('install defaults, the port range and the central IP are saved', async () => {
|
||||
|
||||
Reference in New Issue
Block a user