Last week we shipped /universities: one page offering careers services, sixth forms, colleges and student societies a free partnership. It is 251 lines of page, 185 lines of copy and 135 lines of test.
The test is the interesting part, because of where the offer came from. It was not written for the page. It was written as an outreach email and sent to schools weeks earlier, from scripts/school-outreach.ts. The page is the second copy, and a second copy of a commercial promise is a drift machine: somebody raises a rate in the email, a school reads the old one on the site, and now we are quoting two prices for the same thing.
So the guard test reads the email.
it('quotes the same two discounts as the partnership email already sent', () => {
const email = read('scripts', 'school-outreach.ts');
expect(email).toContain(`gets ${SCHOOL_DISCOUNT_BASE_PERCENT}% off everything automatically`);
expect(email).toContain(`the discount goes up to ${SCHOOL_DISCOUNT_MAX_PERCENT}%`);
expect(content.UNIVERSITIES_LEAD).toContain(`${SCHOOL_DISCOUNT_BASE_PERCENT}% off`);
expect(allCopy).toContain(`goes up to ${SCHOOL_DISCOUNT_MAX_PERCENT}%`);
expect(allCopy).toContain('once or twice a year');
});
Both halves have to hold. The constants are the source of truth, the email has to interpolate them, and the page has to interpolate them. Change the rate and nothing fails. Change the rate and forget one of the two surfaces and the test names which one.
The constants themselves moved into their own 23 line module, which imports nothing at all:
/** The inbox institutions write to. Also copied on the email a student sends. */
export const SCHOOL_PARTNERSHIP_EMAIL = 'sales@cogniprep.app';
/** What a partnered institution's students get off as soon as it is switched on. */
export const SCHOOL_DISCOUNT_BASE_PERCENT = 25;
/**
* What they get off once the institution shares a presentation with students
* once or twice a year. The most a partnered school's students are quoted.
*/
export const SCHOOL_DISCOUNT_MAX_PERCENT = 50;
Import-free matters because the three consumers are a public server page, a client dialog inside the dashboard, and a test. Anything with a transitive server import would have forced the dialog to hardcode the numbers, which is how you get a third copy.
The assertion I will be stealing again: no third percentage
// No other percentage is quoted anywhere on the page.
const quoted = new Set([...allCopy.matchAll(/(\d+)%/g)].map((match) => Number(match[1])));
expect([...quoted].sort()).toEqual([SCHOOL_DISCOUNT_BASE_PERCENT, SCHOOL_DISCOUNT_MAX_PERCENT]);
allCopy is every string in the copy module, flattened out of the nested objects:
function strings(value: unknown): string[] {
if (typeof value === 'string') return [value];
if (Array.isArray(value)) return value.flatMap(strings);
if (value && typeof value === 'object') return Object.values(value).flatMap(strings);
return [];
}
const copy = strings({ ...content });
const allCopy = copy.join('\n');
Spreading the module namespace object gives you every export without listing them, so a new FAQ answer or a new offer bullet is covered the day it is added rather than the day somebody remembers to add it to the test.
The value of the set assertion is that it is a closed-world check. A rate test proves the two numbers we meant to say are present. This proves no third number is: not a "save up to 60%", not an old 20%, not a marketing round number somebody liked. The same trick runs on the contact route:
const addresses = new Set(allCopy.match(/[a-z0-9.]+@[a-z0-9.]+\.[a-z]+/gi) ?? []);
expect([...addresses]).toEqual([SCHOOL_PARTNERSHIP_EMAIL]);
One inbox on the page, and it is the same one the dashboard already gives students.
One page, because the alternative is a doorway
The page was always going to be tempting to multiply. We have 211 employer guide pages, so a /universities/<name> folder per institution is a well-worn path, and it would rank for a while.
/**
* One page, on purpose. A page per university would be the same offer with the
* name swapped, which is a doorway page.
*/
That comment is load-bearing enough to have its own test, which asserts the single page.tsx exists and the path constant is exactly /universities. It will fail the day somebody adds the dynamic segment, and the failure message points at the comment explaining why not.
"Everything we sell" is pinned to the routes that sell it
The page claims the institution discount applies to everything, listed in the pricing page's own words. That is the sort of claim that is true the day you write it and quietly false two products later, so the test checks the checkout code rather than the copy:
for (const route of [
['games', 'provider-token'],
['user', 'premium-upgrade'],
['exercises'],
['interview', 'credits'],
]) {
expect(read('app', 'api', ...route, 'checkout', 'route.ts')).toContain('prepareSchoolCheckout');
}
expect(content.DISCOUNT_COVERS).toMatch(/Interview Access/);
Four purchase routes, four reads, one string. A fifth product with its own checkout route will not be caught by this test, which is a real limit: the honest version of the assertion is "the four things we currently sell all price it", and the copy lists exactly those four.
Two tests that assert the page does not say something
The owner settled a scoping question on 11 November: institutions do not buy access for their students, students buy for themselves at the institution rate. That decision has no code to point at, so it is written as a pair of negatives:
it('does not offer institution-funded access', () => {
expect(allCopy).not.toMatch(/pay for (access|your students|our students)/i);
expect(allCopy).not.toMatch(/students pay nothing/i);
});
The second one is my favourite in the file, because it makes the page tell an inconvenient truth. Student societies ask to partner, and a society's committee often lives on Gmail. The discount keys on a registered email domain and public mailbox providers are refused, so the FAQ has to say so, and the test proves both the refusal and the sentence:
expect(schoolDomainProblem('gmail.com')).not.toBeNull();
expect(schoolDomainProblem('outlook.com')).not.toBeNull();
const society = content.UNIVERSITY_FAQS.find((faq) => /society/i.test(faq.q));
expect(society?.a).toMatch(/Gmail or Outlook cannot be registered/);
One more nuance the page does not hide: these two constants are the rates we offer, while the rate a given registered domain actually carries is a per-domain column set in the admin. The page quotes the offer, not the database.
The counts are computed, including the prose lists
Nothing on the page is a typed figure. The provider names in the lead bullet come out of the registry and get their comma fixed by a regex:
const NAMED_PROVIDERS = (['shl', 'arctic-shores', 'pymetrics', 'hirevue'] as const)
.map((provider) => PROVIDER_META[provider].label)
.join(', ')
.replace(/, ([^,]+)$/, ' and $1');
and the exercise formats are derived from the exercise metadata, with each label's " Exercise" suffix stripped and the list joined the same way, so the sentence currently reads "Assessment centre exercises in 6 formats: e-tray, in-tray, written, presentation, group discussion and role-play". Add a seventh format and the "6" and the list both move.
See it
Open cogniprep.app/universities and run this in the console:
const t = document.body.innerText;
[...new Set([...t.matchAll(/(\d+)%/g)].map((m) => m[1]))];
You get 25, 50 and 100. The first two are the offer. The third is the site footer saying our practice tests are not 100% replicas of the real thing, which is chrome rather than copy, and is the honest reason the closed-world assertion runs against the copy module instead of the rendered page.
Then check the derived bullets against their sources: the page says 65 assessment providers, 428 practice tests and 87 free ones, and so does /llms.txt, which is generated from the same registries. Both should match what you can count on /games.
Finally, look for a form. There is not one. The partnership is agreed by email, so both calls to action are a mailto: with the subject line pre-filled, which is one fewer surface to keep in sync than a form that posts to a route that sends an email that quotes a rate.
Top comments (0)