This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { activityStatus, normalizeActivity } from '../src/lib/activities.js';
|
||||
|
||||
test('activityStatus distinguishes upcoming, active and ended', () => {
|
||||
const now = new Date('2026-09-21T12:00:00Z');
|
||||
assert.equal(activityStatus('2026-09-22T12:00:00Z', null, now), 'upcoming');
|
||||
assert.equal(activityStatus('2026-09-21T11:00:00Z', '2026-09-21T13:00:00Z', now), 'active');
|
||||
assert.equal(activityStatus('2026-09-20T11:00:00Z', '2026-09-20T13:00:00Z', now), 'ended');
|
||||
});
|
||||
test('normalizeActivity supplies stable arrays and numeric count', () => {
|
||||
const value = normalizeActivity({ startsAt: '2026-09-22T12:00:00Z', participantCount: '3' }, new Date('2026-09-21T12:00:00Z'));
|
||||
assert.deepEqual(value.images, []); assert.deepEqual(value.tags, []); assert.equal(value.participantCount, 3);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { loadConfig } from '../src/config.js';
|
||||
|
||||
test('production rejects missing secrets', () => assert.throws(() => loadConfig({ NODE_ENV: 'production' }), /Missing environment variables/));
|
||||
test('development permits local defaults', () => assert.equal(loadConfig({ NODE_ENV: 'development' }).allowDevLogin, true));
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { exchangeCode } from '../src/lib/wechat.js';
|
||||
|
||||
test('exchangeCode returns WeChat session', async () => {
|
||||
const session = await exchangeCode({ code: 'abc', appId: 'id', appSecret: 'secret', fetchImpl: async (url) => {
|
||||
assert.equal(url.searchParams.get('js_code'), 'abc'); return { ok: true, json: async () => ({ openid: 'openid-1' }) };
|
||||
}});
|
||||
assert.equal(session.openid, 'openid-1');
|
||||
});
|
||||
test('exchangeCode rejects WeChat API errors', async () => {
|
||||
await assert.rejects(exchangeCode({ code: 'bad', appId: 'id', appSecret: 'secret', fetchImpl: async () => ({ ok: true, json: async () => ({ errcode: 40029, errmsg: 'invalid code' }) }) }), /invalid code/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user