stat.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. const { verify_fsentry } = require("./fsentry");
  2. const { expect } = require("chai");
  3. module.exports = {
  4. name: 'stat',
  5. do: async t => {
  6. let result;
  7. const TEST_FILENAME = 'test_stat.txt';
  8. let recorded_uid = null;
  9. await t.case('stat with path (no flags)', async () => {
  10. await t.write(TEST_FILENAME, 'stat test\n', { overwrite: true });
  11. result = await t.stat(TEST_FILENAME);
  12. await verify_fsentry(t, result);
  13. recorded_uid = result.uid;
  14. await t.case('filename is correct', () => {
  15. expect(result.name).equal('test_stat.txt');
  16. });
  17. })
  18. await t.case('stat with uid (no flags)', async () => {
  19. result = await t.statu(recorded_uid);
  20. await verify_fsentry(t, result);
  21. await t.case('filename is correct', () => {
  22. expect(result.name).equal('test_stat.txt');
  23. });
  24. })
  25. await t.case('stat with no path or uid provided fails', async () => {
  26. let threw = false;
  27. try {
  28. const res = await t.get('stat', {});
  29. } catch (e) {
  30. expect(e.response.status).equal(400);
  31. expect(e.response.data).deep.equal({
  32. code: 'field_missing',
  33. message: 'Field `subject` is required.',
  34. key: 'subject',
  35. });
  36. threw = true;
  37. }
  38. expect(threw).true;
  39. });
  40. const flags = ['permissions', 'versions'];
  41. for ( const flag of flags ) {
  42. await t.case('stat with ' + flag, async () => {
  43. result = await t.stat(TEST_FILENAME, {
  44. ['return_' + flag]: true,
  45. });
  46. await verify_fsentry(t, result);
  47. await t.case('filename is correct', () => {
  48. expect(result.name).equal(`test_stat.txt`);
  49. });
  50. await t.case(`result has ${flag} array`, () => {
  51. expect(Array.isArray(result[flag])).true;
  52. });
  53. })
  54. }
  55. await t.mkdir('test_stat_subdomains', { overwrite: true });
  56. await t.case('stat with subdomains', async () => {
  57. result = await t.stat('test_stat_subdomains', {
  58. return_subdomains: true,
  59. });
  60. await verify_fsentry(t, result);
  61. await t.case('directory name is correct', () => {
  62. expect(result.name).equal(`test_stat_subdomains`);
  63. });
  64. await t.case(`result has subdomains array`, () => {
  65. expect(Array.isArray(result.subdomains)).true;
  66. });
  67. console.log('RESULT', result);
  68. })
  69. {
  70. const flag = 'size';
  71. await t.case('stat with ' + flag, async () => {
  72. result = await t.stat(TEST_FILENAME, {
  73. ['return_' + flag]: true,
  74. });
  75. await verify_fsentry(t, result);
  76. await t.case('filename is correct', () => {
  77. expect(result.name).equal(`test_stat.txt`);
  78. });
  79. console.log('RESULT', result);
  80. })
  81. }
  82. // console.log('result?', result);
  83. }
  84. };