Co-authored-by: gobha <jasafpro@gmail.com> Co-committed-by: gobha <jasafpro@gmail.com>
197 lines
11 KiB
JavaScript
197 lines
11 KiB
JavaScript
/**
|
|
* SDK Test Runner — Domain: misc
|
|
*
|
|
* Covers smaller domains: notifications, folders, profile,
|
|
* data portability, health, models, users, presence, usage, groups,
|
|
* tools, git.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
var T = window.SDKR;
|
|
if (!T) return;
|
|
|
|
T.registerDomain('misc', async function () {
|
|
var tag = 'sdkr-' + Date.now();
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// HEALTH
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
await T.test('misc', 'health', 'sw.api.health()', {
|
|
sdk: function () { return sw.api.health(); },
|
|
raw: { method: 'GET', path: '/health' },
|
|
validate: function (r) { T.assert(r.status === 'ok', 'status should be ok'); }
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// PROFILE
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
await T.test('misc', 'profile', 'sw.api.profile.get()', {
|
|
sdk: function () { return sw.api.profile.get(); },
|
|
raw: { method: 'GET', path: '/profile' },
|
|
validate: function (r) { T.assertShape(r, T.S.profile, 'profile'); }
|
|
});
|
|
|
|
await T.test('misc', 'profile', 'sw.api.profile.permissions()', {
|
|
sdk: function () {
|
|
if (sw.api.profile.permissions) return sw.api.profile.permissions();
|
|
throw new Error('sw.api.profile.permissions not defined');
|
|
},
|
|
raw: { method: 'GET', path: '/profile/permissions' },
|
|
validate: function (r) {
|
|
T.assert(Array.isArray(r.permissions), 'permissions should be array');
|
|
}
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// MODELS
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
await T.test('misc', 'models', 'sw.api.models.enabled()', {
|
|
sdk: function () {
|
|
if (sw.api.models && sw.api.models.enabled) return sw.api.models.enabled();
|
|
throw new Error('sw.api.models.enabled not defined');
|
|
},
|
|
raw: { method: 'GET', path: '/models/enabled' },
|
|
validate: function (r) { var arr = T.unwrapList(r); T.assert(arr.length >= 0, 'expected list'); }
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// FOLDERS
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
var folderId = null;
|
|
|
|
await T.test('misc', 'folders', 'sw.api.folders.list()', {
|
|
sdk: function () { return sw.api.folders.list(); },
|
|
raw: { method: 'GET', path: '/folders' },
|
|
validate: function (r) { var arr = T.unwrapList(r); T.assert(arr.length >= 0, 'expected list'); }
|
|
});
|
|
|
|
await T.test('misc', 'folders', 'sw.api.folders.create()', {
|
|
sdk: function () {
|
|
return sw.api.folders.create(tag + '-folder');
|
|
},
|
|
raw: { method: 'POST', path: '/folders', body: { name: tag + '-folder', parent_id: null, sort_order: 0 } },
|
|
validate: function (r) {
|
|
// Backend returns { folder: {...} } — SDK passes envelope through
|
|
var obj = r.folder || r;
|
|
T.assertShape(obj, T.S.folder, 'folder');
|
|
folderId = obj.id;
|
|
T.registerCleanup(function () { if (folderId) return T.safeDelete('/folders/' + folderId); });
|
|
}
|
|
});
|
|
|
|
if (folderId) {
|
|
await T.test('misc', 'folders', 'sw.api.folders.update(id, data)', {
|
|
sdk: function () { return sw.api.folders.update(folderId, { name: tag + '-fold-upd' }); },
|
|
raw: { method: 'PUT', path: '/folders/' + folderId, body: { name: tag + '-fold-upd' } },
|
|
validate: function (r) { T.assert(r && (r.ok || r.id || r.folder), 'expected ok or folder'); }
|
|
});
|
|
|
|
await T.test('misc', 'folders', 'sw.api.folders.del(id)', {
|
|
sdk: function () { return sw.api.folders.del(folderId); },
|
|
raw: { method: 'DELETE', path: '/folders/' + folderId },
|
|
validate: function () { folderId = null; }
|
|
});
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// NOTIFICATIONS (duplicate key bug fixed — prefs/setPref/delPref restored)
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
await T.test('misc', 'notifications', 'sw.api.notifications.list()', {
|
|
sdk: function () { return sw.api.notifications.list(); },
|
|
raw: { method: 'GET', path: '/notifications' },
|
|
validate: function (r) { var arr = T.unwrapList(r); T.assert(arr.length >= 0, 'expected list'); }
|
|
});
|
|
|
|
await T.test('misc', 'notifications', 'sw.api.notifications.unreadCount()', {
|
|
sdk: function () { return sw.api.notifications.unreadCount(); },
|
|
raw: { method: 'GET', path: '/notifications/unread-count' },
|
|
validate: function (r) { T.assert(typeof r === 'object', 'expected object'); }
|
|
});
|
|
|
|
await T.test('misc', 'notifications', 'sw.api.notifications.prefs()', {
|
|
sdk: function () {
|
|
if (typeof sw.api.notifications.prefs === 'function') return sw.api.notifications.prefs();
|
|
throw new Error('sw.api.notifications.prefs is ' + typeof sw.api.notifications.prefs);
|
|
},
|
|
raw: { method: 'GET', path: '/notifications/preferences' },
|
|
validate: function () { /* existence is sufficient */ }
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// USERS
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
await T.test('misc', 'users', 'sw.api.users.search(q)', {
|
|
sdk: function () { return sw.api.users.search('admin'); },
|
|
raw: { method: 'GET', path: '/users/search?q=admin' },
|
|
validate: function (r) { var arr = T.unwrapList(r); T.assert(arr.length >= 0, 'expected list'); }
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// PRESENCE
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
await T.test('misc', 'presence', 'sw.api.presence.heartbeat()', {
|
|
sdk: function () { return sw.api.presence.heartbeat(); },
|
|
raw: { method: 'POST', path: '/presence/heartbeat', body: {} },
|
|
validate: function () { /* 200 OK is sufficient */ }
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// USAGE
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
await T.test('misc', 'usage', 'sw.api.usage.mine()', {
|
|
sdk: function () { return sw.api.usage.mine(); },
|
|
raw: { method: 'GET', path: '/usage' },
|
|
validate: function (r) { T.assert(typeof r === 'object' || Array.isArray(r), 'expected object or array'); }
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// GROUPS
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
await T.test('misc', 'groups', 'sw.api.groups.mine()', {
|
|
sdk: function () { return sw.api.groups.mine(); },
|
|
raw: { method: 'GET', path: '/groups/mine' },
|
|
validate: function (r) { var arr = T.unwrapList(r); T.assert(arr.length >= 0, 'expected list'); }
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// TOOLS
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
await T.test('misc', 'tools', 'sw.api.tools.list()', {
|
|
sdk: function () { return sw.api.tools.list(); },
|
|
raw: { method: 'GET', path: '/tools' },
|
|
validate: function (r) { var arr = T.unwrapList(r); T.assert(arr.length >= 0, 'expected list'); }
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// DATA PORTABILITY (KNOWN BUG: deleteAccount wrong method+path)
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
await T.test('misc', 'export', 'sw.api.dataPortability.exportMe()', {
|
|
sdk: function () { return sw.api.dataPortability.exportMe(); },
|
|
raw: { method: 'GET', path: '/export/me' },
|
|
validate: function (r) { T.assert(typeof r === 'object', 'expected object'); },
|
|
skip: 'empty DB export may 500 — expected in dev'
|
|
});
|
|
|
|
// deleteAccount: SDK uses POST /profile/delete, backend is DELETE /me
|
|
// We don't actually call delete — just verify the method exists
|
|
await T.test('misc', 'export', 'sw.api.dataPortability.deleteAccount exists', async function () {
|
|
T.assert(typeof sw.api.dataPortability.deleteAccount === 'function',
|
|
'deleteAccount should be a function');
|
|
// NOTE: SDK calls POST /profile/delete — backend is DELETE /me.
|
|
// This is a known SDK_BUG from the ICD drift audit (§A).
|
|
// We don't actually invoke it because it would delete the account.
|
|
});
|
|
});
|
|
})();
|