web/website/tests/code-redemption.test.mjs

18 lines
1.2 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {describeRedemption} from '../control-panel/public/cp-v2/cp-v2-code-redemption.mjs';
test('existing deliverable codes describe their real route',()=>{
assert.equal(describeRedemption(' drk-'+ 'a'.repeat(32)+' ').kind,'kit');
assert.equal(describeRedemption('DRQ-'+ 'A'.repeat(40)).available,true);
assert.equal(describeRedemption('DRU-'+ 'A'.repeat(48)).href,'#realm/kits-exchange');
});
test('clan upgrades are available while company and political decisions retain their own routes',()=>{
assert.equal(describeRedemption('CLAN-'+ 'A'.repeat(48)).available,true);
for(const prefix of ['COM','POL'])assert.equal(describeRedemption(prefix+'-'+ 'A'.repeat(48)).available,false);
assert.match(describeRedemption('CLAN-'+ 'A'.repeat(48)).description,/separate political appointment/);
assert.match(describeRedemption('POL-'+ 'A'.repeat(48)).description,/recorded by a political decision/);
});
test('partial, malformed and unsupported codes cannot advance to confirmation',()=>{
for(const code of ['', 'CLAN-123', 'DRK-'+ '0'.repeat(32), '/communitycode test','<script>','POL-'+ 'A'.repeat(47)])assert.throws(()=>describeRedemption(code));
});