Files
wekan/tests/listSyncSourceIdentity.test.cjs
T
Lauri Ojansivu 75a312809d Scope list Sync mappings and credentials to their source project
Preserve previous-source cards across project switches, require matching credentials before fetching, and bind identifiable legacy mappings before replacing or clearing settings. Reject unknown legacy sources and stale fetched configurations.

Verify with nine focused Node suites, nine Chromium scenarios and the local release audit. Concurrent jobs and configuration writes remain nontransactional.

Thanks to xet7 !
2026-09-27 21:32:16 +03:00

34 lines
1.9 KiB
JavaScript

'use strict';
const { test } = require('node:test');
const assert = require('node:assert/strict');
const { normalizeSyncSource, syncSourceKey } = require('../models/lib/listSyncSourceIdentity');
const source = { type: 'jira', url: 'https://tracker.example/jira', projectKey: 'ONE' };
test('provider, server path and project each separate otherwise identical issue IDs', () => {
const keys = [source, { ...source, type: 'gitea' },
{ ...source, url: 'https://other.example/jira' },
{ ...source, url: 'https://tracker.example/other' },
{ ...source, projectKey: 'TWO' }].map(syncSourceKey);
assert.equal(new Set(keys).size, keys.length);
});
test('equivalent URL spelling and settings changes retain the same source', () => {
assert.equal(syncSourceKey(source), syncSourceKey({ ...source,
url: 'https://TRACKER.example:443/jira/', projectKey: ' ONE ',
fields: [], enabled: false, token: 'never-in-the-key' }));
assert.ok(!syncSourceKey({ ...source, token: 'secret' }).includes('secret'));
assert.equal(syncSourceKey({ type: 'gitlab', projectKey: 'team/repo' }),
syncSourceKey({ type: 'gitlab', url: 'https://gitlab.com/', projectKey: 'team/repo' }));
// The GitHub fetcher always uses api.github.com, regardless of the URL input.
assert.equal(syncSourceKey({ type: 'github', projectKey: 'team/repo' }),
syncSourceKey({ type: 'github', url: 'https://ignored.example', projectKey: 'team/repo' }));
});
test('invalid server URLs and empty projects fail without exposing their contents', () => {
for (const url of ['', 'broken', 'file:///tmp/example', 'https://user:secret@tracker.example',
'https://tracker.example?token=secret', 'https://tracker.example/#secret']) {
assert.throws(() => normalizeSyncSource({ ...source, url }), error => {
assert.ok(!error.message.includes('secret')); return true;
});
}
assert.throws(() => syncSourceKey({ ...source, projectKey: ' ' }), /project is required/);
});