All checks were successful
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
180 lines
9.8 KiB
JavaScript
180 lines
9.8 KiB
JavaScript
/**
|
|
* SDK Test Runner — Domain: misc
|
|
*
|
|
* Covers kernel domains: health, profile, notifications, users, groups,
|
|
* data portability.
|
|
* Extension-dependent domains (models, folders, presence, usage, tools)
|
|
* belong in package runners, not here.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
var T = window.SDKR;
|
|
if (!T) return;
|
|
|
|
sw.testing.suite('sdk/misc', async function (s) {
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// HEALTH
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
s.test('health: sw.api.health()', async function (t) {
|
|
var result = await T.dualTest(
|
|
function () { return sw.api.health(); },
|
|
{ method: 'GET', path: '/health' },
|
|
function (r) { T.assert(r.status === 'ok', 'status should be ok'); }
|
|
);
|
|
if (result.verdict === 'PASS') return;
|
|
if (result.verdict === 'SDK_BUG') t.assert.ok(false, 'SDK_BUG: ' + result.sdkErr);
|
|
if (result.verdict === 'ICD_BUG') t.assert.ok(false, 'ICD_BUG: ' + result.rawErr);
|
|
if (result.verdict === 'SHAPE_BUG') t.warn('SHAPE_BUG: ' + result.sdkErr);
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// PROFILE
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
s.test('profile: sw.api.profile.get()', async function (t) {
|
|
var result = await T.dualTest(
|
|
function () { return sw.api.profile.get(); },
|
|
{ method: 'GET', path: '/profile' },
|
|
function (r) { T.assertShape(r, T.S.profile, 'profile'); }
|
|
);
|
|
if (result.verdict === 'PASS') return;
|
|
if (result.verdict === 'SDK_BUG') t.assert.ok(false, 'SDK_BUG: ' + result.sdkErr);
|
|
if (result.verdict === 'ICD_BUG') t.assert.ok(false, 'ICD_BUG: ' + result.rawErr);
|
|
if (result.verdict === 'SHAPE_BUG') t.warn('SHAPE_BUG: ' + result.sdkErr);
|
|
});
|
|
|
|
s.test('profile: sw.api.profile.permissions()', async function (t) {
|
|
var result = await T.dualTest(
|
|
function () {
|
|
if (sw.api.profile.permissions) return sw.api.profile.permissions();
|
|
throw new Error('sw.api.profile.permissions not defined');
|
|
},
|
|
{ method: 'GET', path: '/profile/permissions' },
|
|
function (r) {
|
|
T.assert(Array.isArray(r.permissions), 'permissions should be array');
|
|
}
|
|
);
|
|
if (result.verdict === 'PASS') return;
|
|
if (result.verdict === 'SDK_BUG') t.assert.ok(false, 'SDK_BUG: ' + result.sdkErr);
|
|
if (result.verdict === 'ICD_BUG') t.assert.ok(false, 'ICD_BUG: ' + result.rawErr);
|
|
if (result.verdict === 'SHAPE_BUG') t.warn('SHAPE_BUG: ' + result.sdkErr);
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// NOTIFICATIONS
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
s.test('notifications: sw.api.notifications.list()', async function (t) {
|
|
var result = await T.dualTest(
|
|
function () { return sw.api.notifications.list(); },
|
|
{ method: 'GET', path: '/notifications' },
|
|
function (r) { var arr = T.unwrapList(r); T.assert(arr.length >= 0, 'expected list'); }
|
|
);
|
|
if (result.verdict === 'PASS') return;
|
|
if (result.verdict === 'SDK_BUG') t.assert.ok(false, 'SDK_BUG: ' + result.sdkErr);
|
|
if (result.verdict === 'ICD_BUG') t.assert.ok(false, 'ICD_BUG: ' + result.rawErr);
|
|
if (result.verdict === 'SHAPE_BUG') t.warn('SHAPE_BUG: ' + result.sdkErr);
|
|
});
|
|
|
|
s.test('notifications: sw.api.notifications.unreadCount()', async function (t) {
|
|
var result = await T.dualTest(
|
|
function () { return sw.api.notifications.unreadCount(); },
|
|
{ method: 'GET', path: '/notifications/unread-count' },
|
|
function (r) { T.assert(typeof r === 'object', 'expected object'); }
|
|
);
|
|
if (result.verdict === 'PASS') return;
|
|
if (result.verdict === 'SDK_BUG') t.assert.ok(false, 'SDK_BUG: ' + result.sdkErr);
|
|
if (result.verdict === 'ICD_BUG') t.assert.ok(false, 'ICD_BUG: ' + result.rawErr);
|
|
if (result.verdict === 'SHAPE_BUG') t.warn('SHAPE_BUG: ' + result.sdkErr);
|
|
});
|
|
|
|
s.test('notifications: sw.api.notifications.prefs()', async function (t) {
|
|
var result = await T.dualTest(
|
|
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);
|
|
},
|
|
{ method: 'GET', path: '/notifications/preferences' },
|
|
function () { /* existence is sufficient */ }
|
|
);
|
|
if (result.verdict === 'PASS') return;
|
|
if (result.verdict === 'SDK_BUG') t.assert.ok(false, 'SDK_BUG: ' + result.sdkErr);
|
|
if (result.verdict === 'ICD_BUG') t.assert.ok(false, 'ICD_BUG: ' + result.rawErr);
|
|
if (result.verdict === 'SHAPE_BUG') t.warn('SHAPE_BUG: ' + result.sdkErr);
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// USERS
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
s.test('users: sw.api.users.search(q)', async function (t) {
|
|
var result = await T.dualTest(
|
|
function () { return sw.api.users.search('admin'); },
|
|
{ method: 'GET', path: '/users/search?q=admin' },
|
|
function (r) { var arr = T.unwrapList(r); T.assert(arr.length >= 0, 'expected list'); }
|
|
);
|
|
if (result.verdict === 'PASS') return;
|
|
if (result.verdict === 'SDK_BUG') t.assert.ok(false, 'SDK_BUG: ' + result.sdkErr);
|
|
if (result.verdict === 'ICD_BUG') t.assert.ok(false, 'ICD_BUG: ' + result.rawErr);
|
|
if (result.verdict === 'SHAPE_BUG') t.warn('SHAPE_BUG: ' + result.sdkErr);
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// GROUPS
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
s.test('groups: sw.api.groups.mine()', async function (t) {
|
|
var result = await T.dualTest(
|
|
function () { return sw.api.groups.mine(); },
|
|
{ method: 'GET', path: '/groups/mine' },
|
|
function (r) { var arr = T.unwrapList(r); T.assert(arr.length >= 0, 'expected list'); }
|
|
);
|
|
if (result.verdict === 'PASS') return;
|
|
if (result.verdict === 'SDK_BUG') t.assert.ok(false, 'SDK_BUG: ' + result.sdkErr);
|
|
if (result.verdict === 'ICD_BUG') t.assert.ok(false, 'ICD_BUG: ' + result.rawErr);
|
|
if (result.verdict === 'SHAPE_BUG') t.warn('SHAPE_BUG: ' + result.sdkErr);
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// EXTENSIONS
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
s.test('extensions: sw.api.get /extensions returns array', async function (t) {
|
|
var result = await T.dualTest(
|
|
function () { return sw.api.get('/api/v1/extensions'); },
|
|
{ method: 'GET', path: '/extensions' },
|
|
function (r) {
|
|
var arr = Array.isArray(r) ? r : (r && r.data);
|
|
T.assert(Array.isArray(arr), 'extensions should be array');
|
|
}
|
|
);
|
|
if (result.verdict === 'PASS') return;
|
|
if (result.verdict === 'SDK_BUG') t.assert.ok(false, 'SDK_BUG: ' + result.sdkErr);
|
|
if (result.verdict === 'ICD_BUG') t.assert.ok(false, 'ICD_BUG: ' + result.rawErr);
|
|
if (result.verdict === 'SHAPE_BUG') t.warn('SHAPE_BUG: ' + result.sdkErr);
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// DATA PORTABILITY (KNOWN BUG: deleteAccount wrong method+path)
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
s.test('export: sw.api.dataPortability.exportMe()', async function (t) {
|
|
// skip: empty DB export may 500 — expected in dev
|
|
t.warn('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
|
|
s.test('export: sw.api.dataPortability.deleteAccount exists', async function (t) {
|
|
if (!sw.api.dataPortability) { t.warn('SKIP: sw.api.dataPortability not defined'); return; }
|
|
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.
|
|
});
|
|
});
|
|
})();
|