Skip to content

Repository files, collaboration, releases and project activity.

archforge-external-status / tests/branding-persistence.test.jsmain
▤ tests/branding-persistence.test.js3556 bytes
61 lines · Select a line number for a permalink
1'use strict';
2const {test}=require('node:test');
3const assert=require('node:assert/strict');
4const fs=require('node:fs');const os=require('node:os');const path=require('node:path');
5const {openDatabase,one,syncServices}=require('../src/database');
6const {serviceDefinitions}=require('../src/probes');
7const {serviceLabel,presentService}=require('../src/branding');
8const {homepage,adminDashboard,details}=require('../src/views');
10test('existing labels are migrated by normal service startup without deleting samples',()=>{
11 const db=openDatabase(':memory:');
12 db.prepare("INSERT INTO services (id,label,description,configured,category) VALUES('git_ssh','ArchForge SSH','banner',1,'ArchForge')").run();
13 db.prepare("INSERT INTO samples(service_id,checked_at,success,detail) VALUES('git_ssh',100,1,'ok')").run();
14 // Mimics a previous release process attempting to restore Git branding.
15 db.prepare("UPDATE services SET label='Git SSH',category='Git' WHERE id='git_ssh'").run();
16 assert.equal(one(db,"SELECT label FROM services WHERE id='git_ssh'").label,'ArchForge SSH');
17 syncServices(db,serviceDefinitions({api:'',gitHttp:''}));
18 assert.equal(one(db,"SELECT label FROM services WHERE id='git_ssh'").label,'ArchForge SSH');
19 assert.equal(one(db,"SELECT COUNT(*) AS n FROM samples WHERE service_id='git_ssh'").n,1);
20 db.close();
21});
22test('older processes cannot revert public service branding via insert or update',()=>{
23 const db=openDatabase(':memory:');
24 for(const [id,wrong,expected] of [
25 ['git_ssh','Git SSH','ArchForge SSH'],['git_http','Git Smart HTTP','ArchForge HTTPS']]){
26 db.prepare('INSERT INTO services(id,label,description,configured,category) VALUES(?,?,?,?,?)').run(id,wrong,'banner',1,'Git');
27 let state=one(db,'SELECT label,category FROM services WHERE id=?',id);
28 assert.equal(state.label,expected);assert.equal(state.category,'ArchForge');
29 db.prepare('UPDATE services SET label=?,category=? WHERE id=?').run(wrong,'Git',id);
30 state=one(db,'SELECT label,category FROM services WHERE id=?',id);
31 assert.equal(state.label,expected);assert.equal(state.category,'ArchForge');
32 }
33 db.close();
34});
35test('branding guard persists after SQLite database reopens',()=>{
36 const folder=fs.mkdtempSync(path.join(os.tmpdir(),'af-branding-'));
37 try{
38 const file=path.join(folder,'monitor.db');
39 let db=openDatabase(file);
40 db.prepare("INSERT INTO services(id,label,description) VALUES('git_ssh','Git SSH','legacy')").run();
41 db.close();
42 db=openDatabase(file);
43 db.prepare("UPDATE services SET label='Git SSH' WHERE id='git_ssh'").run();
44 assert.equal(one(db,"SELECT label FROM services WHERE id='git_ssh'").label,'ArchForge SSH');
45 db.close();
46 }finally{fs.rmSync(folder,{force:true,recursive:true});}
47});
48test('browser rendering and API output canonicalize stale service record names',()=>{
49 const bad={id:'git_http',label:'Git Smart HTTP',description:'read-only public repository',category:'Git',current_state:'operational',last_latency:123,
50 stats:{days:7,coverage:1,uptime:100,buckets:[]}};
51 assert.equal(serviceLabel(bad),'ArchForge HTTPS');
52 assert.deepEqual(presentService(bad),{...bad,label:'ArchForge HTTPS',category:'ArchForge'});
53 const home=homepage({services:[bad],days:7,incidents:[],maintenance:[],config:{}});
54 const admin=adminDashboard({csrf:'test-token',services:[bad],incidents:[],maintenance:[],queue:0});
55 const detail=details(bad,[],7,false);
56 for(const html of [home,admin,detail]){
57 assert.match(html,/ArchForge HTTPS/);
58 assert.doesNotMatch(html,/>Git Smart HTTP</);
59 }
60});