MC/website/tests/organisation-quest-grants.test.mjs
2026-11-27 23:43:05 +00:00

9 lines
1.1 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';
import {organisationQuestGrantPlan} from '../scripts/organisation-quest-grants.mjs';
test('organisation reward settlement requests only receipt read/insert for the central connection on the same transactional server',async()=>{
const identity={db:'dune_site',host:'central',port:3306,server_id:1},db={query:async sql=>[sql.includes('CURRENT_USER')?{identity:'dune_app@localhost'}:identity]},bank={first:async()=>({...identity,db:'dune_bank'})};
assert.equal(await organisationQuestGrantPlan(db,bank),"GRANT SELECT,INSERT ON `dune_bank`.`pb_organisation_quest_rewards` TO 'dune_app'@'localhost';\n");
await assert.rejects(organisationQuestGrantPlan(db,{first:async()=>({...identity,host:'foreign',db:'dune_bank'})}),/One transactional/);
await assert.rejects(organisationQuestGrantPlan(db,{first:async()=>({...identity,db:'dune_bank`;DROP'})}),/One transactional/);
await assert.rejects(organisationQuestGrantPlan({query:async sql=>[sql.includes('CURRENT_USER')?{identity:"app'@localhost"}:identity]},bank),/identity/);
});