Files
vyndr/tests/integration/foundersRoute.test.js
T
builtbykev 41fc2b90e2 Item 2 — founder counter is REAL or hidden (kills the hardcoded 47/100)
ClaimMeter rendered a fabricated "47 / 100 CLAIMED" (a hardcoded default; the
comment even said "Cosmetic conversion driver… Static here"). Now:

- GET /api/founders/count counts ONLY real paying founders — user_profiles
  where founder_pricing = true AND subscription_status = 'active' (the
  Stripe-webhook-synced mirror, so we never hammer the Stripe API). Cached 5
  min in Redis on top of that.
- If the source is unavailable (Supabase unconfigured, query error, column not
  migrated, client throws) the endpoint returns { available: false } and the
  ClaimMeter renders NOTHING — counter and progress bar both hidden. We never
  fall back to a number.
- A low real count is shown honestly (0 → "0 / 100"); the truth is the feature.

Next proxy at app/api/founders/count. 6 route tests cover real count, low
count, error/unconfigured/throw → hidden, and cache-hit. Suite 271/3260 green,
web build exit 0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-17 15:32:18 -04:00

77 lines
3.0 KiB
JavaScript

'use strict';
// Item 2 (Truth-Everywhere Part 2) — the founder-seat counter is REAL or hidden,
// never a fabricated "47 / 100". Redis mocked; the Supabase client injected.
const request = require('supertest');
let mockStore = {};
jest.mock('../../src/utils/redis', () => ({
getRedisClient: () => ({}),
cacheGet: async (k) => (k in mockStore ? mockStore[k] : null),
cacheSet: async (k, v) => { mockStore[k] = v; return true; },
cacheDel: async () => true,
isDegraded: () => false,
}));
const app = require('../../src/app');
const foundersRouter = require('../../src/routes/founders');
// A fake Supabase query builder that resolves to a fixed count/error.
function fakeClient({ count = 0, error = null } = {}) {
const b = {
from() { return b; },
select() { return b; },
eq() { return b; },
then(resolve) { return Promise.resolve({ count, error }).then(resolve); },
};
return b;
}
beforeEach(() => { mockStore = {}; foundersRouter.__setDeps({}); });
describe('GET /api/founders/count', () => {
test('real active-founder count → { available, claimed, total }', async () => {
foundersRouter.__setDeps({ getClient: () => fakeClient({ count: 3 }) });
const res = await request(app).get('/api/founders/count');
expect(res.status).toBe(200);
expect(res.body.available).toBe(true);
expect(res.body.claimed).toBe(3);
expect(res.body.total).toBe(100);
});
test('a low real count is shown honestly (no fabricated floor)', async () => {
foundersRouter.__setDeps({ getClient: () => fakeClient({ count: 0 }) });
const res = await request(app).get('/api/founders/count');
expect(res.body).toEqual({ available: true, claimed: 0, total: 100 });
});
test('query error (column missing) → available:false, NEVER a number', async () => {
foundersRouter.__setDeps({ getClient: () => fakeClient({ error: { message: 'no column' } }) });
const res = await request(app).get('/api/founders/count');
expect(res.body).toEqual({ available: false });
expect(res.body).not.toHaveProperty('claimed');
});
test('unconfigured source (no client) → available:false, hidden', async () => {
foundersRouter.__setDeps({ getClient: () => null });
const res = await request(app).get('/api/founders/count');
expect(res.body).toEqual({ available: false });
});
test('client throws → available:false, never fabricates', async () => {
foundersRouter.__setDeps({ getClient: () => { throw new Error('down'); } });
const res = await request(app).get('/api/founders/count');
expect(res.body).toEqual({ available: false });
});
test('served from cache when warm (no client call)', async () => {
mockStore['founders:count'] = { claimed: 7 };
let clientCalled = false;
foundersRouter.__setDeps({ getClient: () => { clientCalled = true; return fakeClient({ count: 999 }); } });
const res = await request(app).get('/api/founders/count');
expect(res.body).toEqual({ available: true, claimed: 7, total: 100 });
expect(clientCalled).toBe(false);
});
});