forked from unimatrix/web
Replace monthly community goals with JARVIS server projects, staff review, scoped funding and automatic closure
This commit is contained in:
parent
bf3ae53053
commit
3fab6cd650
1 changed files with 293 additions and 22 deletions
17
website/tests/server-project-api.test.mjs
Normal file
17
website/tests/server-project-api.test.mjs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import test from 'node:test';import assert from 'node:assert/strict';import {randomUUID} from 'node:crypto';
|
||||
import {createServerProjectAPI} from '../node/server-project-api.mjs';
|
||||
function fixture(){let user={id:randomUUID()};const calls=[];const service={list:async actor=>({projects:[],accountId:actor.id}),submit:async(actor,body)=>{calls.push({actor,body});return {replayed:false};},review:async()=>{calls.push('review');return{};}};
|
||||
const api=createServerProjectAPI({},service,{authenticate:async()=>user});
|
||||
return{calls,logout:()=>{user=null;},call:(path='',body,origin='https://cp.dunerealms.com')=>api(new Request('https://cp.dunerealms.com/api/projects'+path,body?{method:'POST',headers:{origin,'Content-Type':'application/json'},body:JSON.stringify(body)}:{}))};}
|
||||
test('project API scopes private requests to the authenticated account and rejects browser overrides',async()=>{
|
||||
const f=fixture();assert.equal((await f.call()).status,200);assert.equal((await f.call('?accountId=other')).status,400);
|
||||
const submit={requestId:randomUUID(),title:'Arena',proposal:'A proposal for a new public arena.',requestedMinor:25000,confirmed:true};
|
||||
assert.equal((await f.call('/submit',{...submit,applicantId:randomUUID()})).status,400);assert.equal((await f.call('/submit',submit,'https://elsewhere.example')).status,403);assert.equal(f.calls.length,0);
|
||||
assert.equal((await f.call('/submit',submit)).status,200);assert.equal(f.calls.length,1);assert.equal(typeof f.calls[0].actor.revalidate,'function');
|
||||
f.logout();assert.equal((await f.call()).status,401);
|
||||
});
|
||||
test('review instructions require a boolean decision and cannot inject bank accounts or payment destinations',async()=>{
|
||||
const f=fixture(),review={projectId:randomUUID(),requestId:randomUUID(),version:1,approve:true,approvedMinor:100,note:'Approved.',confirmed:true};
|
||||
assert.equal((await f.call('/review',{...review,approve:'true'})).status,400);assert.equal((await f.call('/review',{...review,targetNumber:'any-bank-account'})).status,400);assert.equal(f.calls.length,0);
|
||||
assert.equal((await f.call('/review',review)).status,200);
|
||||
});
|
||||
Loading…
Reference in a new issue

Staff