Files
wekan/tests/githubWiki.test.cjs
T
Lauri Ojansivu 935e68dfdd GitHub organization import: repositories, issues, releases, Actions, wiki.
Import -> GitHub -> Import a whole GitHub organization makes every
repository of an organization or user its own board, opening in Board View
/ Version Control. Issues go through the ordinary importBoard, as the person
who started the job, with their comments, labels and files. Releases are
cards in a Releases list, their files attached only when chosen. Each
.github/workflows file becomes Rules. The wiki is read from its git
repository with isomorphic-git (1.42.4, pinned), every request through the
SSRF guard and only to github.com: a page is a card in the Wiki list, its
[[links]] point at and are attached to the linked pages' cards, and each
commit that changed it is a dated edit in the card's history, so Restore
brings back an older version. The job shows progress, can be cancelled,
pauses on a restart and stops at a rate limit; the token is kept in memory
only.

Version Control gains Releases and Wiki tabs: the wiki as GitHub shows it,
with the page list, _Sidebar and _Footer, links that stay in the tab, and
each page's history with Restore.

GitHub Actions workflows map to Rules: issue events to triggers, label,
close, reopen, comment, assign and create steps to actions, actions/stale to
an aging rule. Code - builds, tests, scripts - is never run: such a workflow
is a disabled rule with its YAML as the description. WeKan's Rules gain what
they lacked for it: a "commented on" trigger, an "add comment" action written
as the person whose change ran the rule and only where they may comment,
cron schedules in UTC, and a rule description shown on the rule. A disabled
rule no longer fires on a schedule or from its button, which it did.

The new strings are translated in every locale.

Thanks to xet7 !
2026-10-14 12:43:36 +03:00

57 lines
2.8 KiB
JavaScript

'use strict';
// Guard: a GitHub wiki as cards (models/lib/githubWiki.js) - one page one
// card, [[links]] as "link to card", the page history as the card's history.
// Run: node tests/githubWiki.test.cjs
const assert = require('assert');
const w = require('../models/lib/githubWiki.js');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(`ok - ${name}`); }
test('file names are page names; non-pages are not', () => {
assert.strictEqual(w.pageNameFromPath('Getting-Started.md'), 'Getting Started');
assert.strictEqual(w.pageNameFromPath('docs/Install-on-Linux.markdown'), 'Install on Linux');
assert.strictEqual(w.pageNameFromPath('Home.md'), 'Home');
assert.strictEqual(w.pageNameFromPath('logo.png'), null);
assert.strictEqual(w.pageKey('Getting Started'), w.pageKey('getting-started'));
assert.ok(w.isSpecialPage('_Sidebar') && !w.isSpecialPage('Sidebar notes'));
});
const cards = { home: { _id: 'c1', url: '/b/B/x/c1' }, 'getting-started': { _id: 'c2', url: '/b/B/x/c2' } };
const cardFor = key => cards[key] || null;
const repoWikiUrl = 'https://github.com/wekan/wekan/wiki';
test('[[links]] in both orders, markdown links and wiki URLs point at the cards', () => {
const text = 'See [[Getting Started]], [[the start|Home]], [[Home|start page]], '
+ '[guide](Getting-Started) and [full](https://github.com/wekan/wekan/wiki/Home#top).';
const { text: out, linkedCardIds } = w.rewriteWikiLinks(text, { repoWikiUrl, cardFor });
assert.strictEqual(out, 'See [Getting Started](/b/B/x/c2), [the start](/b/B/x/c1), [start page](/b/B/x/c1), '
+ '[guide](/b/B/x/c2) and [full](/b/B/x/c1).');
assert.deepStrictEqual(linkedCardIds, ['c2', 'c1']);
});
test('negative: missing pages, images, outside and anchor links stay as they are', () => {
const text = '[[No Such Page]] ![logo](Home) [x](https://example.com/Home) [y](#Home) [z](logo.png)';
const { text: out, linkedCardIds } = w.rewriteWikiLinks(text, { repoWikiUrl, cardFor });
assert.strictEqual(out, text);
assert.deepStrictEqual(linkedCardIds, []);
});
test('history: one edit per commit that changed the text, oldest first', () => {
const h = w.pageHistory([
{ commit: 'a', at: '2020-01-01', author: 'alice', text: 'one' },
{ commit: 'b', at: '2020-01-02', author: 'bob', text: 'one' },
{ commit: 'c', at: '2020-01-03', author: 'bob', text: 'two' },
{ commit: 'd', at: '2020-01-04', author: 'carol', text: null },
]);
assert.deepStrictEqual(h.map(e => [e.commit, e.previous, e.next]), [['a', null, 'one'], ['c', 'one', 'two'], ['d', 'two', null]]);
});
test('Home first, then by name', () => {
assert.deepStrictEqual(w.sortPages([{ name: 'Zeta' }, { name: 'alpha' }, { name: 'Home' }]).map(p => p.name), ['Home', 'alpha', 'Zeta']);
});
console.log(`# ${passed} passed`);