Files
puter/tests/api-tester/tests/fsentry.js
T
Xiaochen Cui c93a53ead2 ci: init e2e test for browser env, tidy other tests (#1796)
* ci: init e2e test for browser env

stash changes

* test: update fsentry definition, add tests

stash changes

* test: pass puter-js mkdir test

* test: add test for puter-js move

* tidy code

* tidy code

* doc: add docs for playwright test

* recover memoryfs

* test: puter-js readdir/stat

* test: puter-js write

* test: puter-js read

* test: puter-js move_cart

* test: fix failed tests on move

* tests: rename files

* test: puter-js copy_cart

* tests: puter-js batch/delete, read config from file

* ci: add vitest

* ci: update names and timeout

* ci: simplify playwright-test

* ci: simplify api-test

* move "api-tester" from tools to tests

* test: update example config

* test: remove folder tests/api-tester/ci

* test: unify config location

* test: remove unused files

* ci: fix wrong config

* ci: fix wrong path

* test: add docs

* ci: update timeout, print artifact url
2025-10-28 16:35:37 -07:00

83 lines
2.4 KiB
JavaScript

const { expect } = require("chai");
const _bitBooleans = [
'immutable',
'is_shortcut',
'is_symlink',
'is_dir',
];
const _integers = [
'created',
'accessed',
'modified',
];
const _strings = [
'id', 'uid', 'parent_id', 'name',
]
const verify_fsentry = async (t, o) => {
await t.case('fsentry is valid', async () => {
for ( const k of _strings ) {
await t.case(`${k} is a string`, () => {
expect(typeof o[k]).equal('string');
});
}
if ( o.is_dir ) {
await t.case(`type is null for directories`, () => {
expect(o.type).equal(null);
});
}
if ( ! o.is_dir ) {
await t.case(`type is a string for files`, () => {
expect(typeof o.type).equal('string');
});
}
await t.case('id === uid', () => {
expect(o.id).equal(o.uid);
});
await t.case('uid is string', () => {
expect(typeof o.uid).equal('string');
});
for ( const k of _bitBooleans ) {
if ( k === 'is_dir' ) {
await t.case(`is_dir is true or false`, () => {
expect(o[k]).oneOf([true, false], `${k} should be true or false`);
});
continue;
}
await t.case(`${k} is 0 or 1`, () => {
expect(o[k]).oneOf([0, 1], `${k} should be 0 or 1`);
});
}
t.quirk('is_shared is not populated currently');
// expect(o.is_shared).oneOf([true, false]);
for ( const k of _integers ) {
if ( o.is_dir && k === 'accessed' ) {
t.quirk('accessed is null for new directories');
continue;
}
await t.case(`${k} is numeric type`, () => {
expect(typeof o[k]).equal('number');
});
await t.case(`${k} has no fractional component`, () => {
expect(Number.isInteger(o[k])).true;
});
}
await t.case('symlink_path is null or string', () => {
expect(
o.symlink_path === null ||
typeof o.symlink_path === 'string'
).true;
});
await t.case('owner object has expected properties', () => {
expect(o.owner).to.haveOwnProperty('username');
});
})
}
module.exports = {
verify_fsentry,
};