forked from unimatrix/web
19 lines
2 KiB
JavaScript
19 lines
2 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';import {randomUUID} from 'node:crypto';
|
|
import {companyFixture} from './company-deed-fixture.mjs';
|
|
import {initializeProgression} from '../node/progression-schema.mjs';
|
|
import {GAZETTE_SCHEMA} from '../node/jarvis-gazette.mjs';
|
|
import {createProgressionMilestoneNews} from '../node/progression-milestone-news.mjs';
|
|
test('halfway and completion publish once through existing news, while ordinary levels never become public',async()=>{
|
|
const f=await companyFixture();try{
|
|
await initializeProgression(f.db);await f.db.query(GAZETTE_SCHEMA);
|
|
await f.db.query('CREATE TABLE website_posts(id TEXT PRIMARY KEY,source_key TEXT UNIQUE,category TEXT,title TEXT,body TEXT,status TEXT,author_id TEXT,created_at INT,updated_at INT,published_at INT,version INT)');
|
|
await f.db.query("INSERT INTO jarvis_progression_seasons(season_id,starts_at,ends_at,level_cap,curve_base,state) VALUES('S01',0,10000,70,25,'active')");
|
|
await f.db.query('INSERT INTO jarvis_progression_accounts(account_id,total_xp,effective_xp,level_no,version,updated_at) VALUES(?,60375,60375,70,1,1000)',[f.people.Member.id]);
|
|
for(const purpose of ['level-35','level-70','level-3'])await f.db.query("INSERT INTO jarvis_progression_outbox(id,account_id,season_id,purpose,payload_json,state,created_at) VALUES(?,?,'S01',?,'{}','queued',1000)",[randomUUID(),f.people.Member.id,purpose]);
|
|
const worker=createProgressionMilestoneNews(f.db,f.keys,{clock:()=>2000});
|
|
assert.deepEqual(await worker.drain(),{published:2,failed:1});
|
|
assert.deepEqual(await worker.drain(),{published:0,failed:1});
|
|
const posts=await f.db.query('SELECT title,body FROM website_posts');assert.equal(posts.length,2);assert(posts.some(p=>p.title.endsWith('level 35')));assert(posts.some(p=>p.title.endsWith('level 70')));
|
|
assert(posts.every(p=>!p.body.includes(f.people.Member.id)));assert.equal((await f.db.query('SELECT id FROM jarvis_gazette_records')).length,2);
|
|
}finally{f.db.close();}
|
|
});
|

Staff