Changeset 0.37.17 (#229)
Co-authored-by: gobha <jasafpro@gmail.com> Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
83
packages/sdk-test-runner/js/domains/workspaces.js
Normal file
83
packages/sdk-test-runner/js/domains/workspaces.js
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* SDK Test Runner — Domain: workspaces
|
||||
*
|
||||
* Tests: list, create, get, update, delete, files.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
var T = window.SDKR;
|
||||
if (!T) return;
|
||||
|
||||
T.registerDomain('workspaces', async function () {
|
||||
var tag = 'sdkr-' + Date.now();
|
||||
var wsId = null;
|
||||
|
||||
// Get current user for owner_type/owner_id
|
||||
var me = await sw.api.profile.get();
|
||||
var userId = me.id;
|
||||
|
||||
// ── List ──
|
||||
|
||||
await T.test('workspaces', 'list', 'sw.api.workspaces.list()', {
|
||||
sdk: function () { return sw.api.workspaces.list(); },
|
||||
raw: { method: 'GET', path: '/workspaces' },
|
||||
validate: function (r) { var arr = T.unwrapList(r); T.assert(arr.length >= 0, 'expected list'); }
|
||||
});
|
||||
|
||||
// ── Create ──
|
||||
|
||||
await T.test('workspaces', 'crud', 'sw.api.workspaces.create()', {
|
||||
sdk: function () {
|
||||
return sw.api.workspaces.create({ name: tag + '-ws', owner_type: 'user', owner_id: userId });
|
||||
},
|
||||
raw: { method: 'POST', path: '/workspaces', body: { name: tag + '-ws', owner_type: 'user', owner_id: userId } },
|
||||
validate: function (r) {
|
||||
T.assertShape(r, T.S.workspace, 'workspace');
|
||||
wsId = r.id;
|
||||
T.registerCleanup(function () { if (wsId) return T.safeDelete('/workspaces/' + wsId); });
|
||||
}
|
||||
});
|
||||
|
||||
if (!wsId) return;
|
||||
|
||||
// ── Get ──
|
||||
|
||||
await T.test('workspaces', 'crud', 'sw.api.workspaces.get(id)', {
|
||||
sdk: function () { return sw.api.workspaces.get(wsId); },
|
||||
raw: { method: 'GET', path: '/workspaces/' + wsId },
|
||||
validate: function (r) {
|
||||
T.assertShape(r, T.S.workspace, 'workspace');
|
||||
T.assert(r.id === wsId, 'id mismatch');
|
||||
}
|
||||
});
|
||||
|
||||
// ── Update (KNOWN BUG: SDK uses PUT, backend expects PATCH) ──
|
||||
|
||||
await T.test('workspaces', 'crud', 'sw.api.workspaces.update(id, data)', {
|
||||
sdk: function () {
|
||||
return sw.api.workspaces.update(wsId, { name: tag + '-ws-updated' });
|
||||
},
|
||||
raw: { method: 'PATCH', path: '/workspaces/' + wsId,
|
||||
body: { name: tag + '-ws-updated' } },
|
||||
validate: function (r) {
|
||||
T.assertShape(r, T.S.workspace, 'workspace');
|
||||
}
|
||||
});
|
||||
|
||||
// ── Files list ──
|
||||
|
||||
await T.test('workspaces', 'files', 'sw.api.workspaces.files(id)', {
|
||||
sdk: function () { return sw.api.workspaces.files(wsId); },
|
||||
raw: { method: 'GET', path: '/workspaces/' + wsId + '/files' },
|
||||
validate: function (r) { T.assert(typeof r === 'object' || Array.isArray(r), 'expected object or array'); }
|
||||
});
|
||||
|
||||
// ── Delete ──
|
||||
|
||||
await T.test('workspaces', 'crud', 'sw.api.workspaces.del(id)', {
|
||||
sdk: function () { return sw.api.workspaces.del(wsId); },
|
||||
raw: { method: 'DELETE', path: '/workspaces/' + wsId },
|
||||
validate: function () { wsId = null; }
|
||||
});
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user