TASKS-1832
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { test } from '@japa/runner'
|
||||
import drive from '@adonisjs/drive/services/main'
|
||||
import { FSStorageService } from '#base_modules/FileManager/services/storage_service/fs_storage_service'
|
||||
|
||||
const disk = drive.use('fs')
|
||||
const storage = new FSStorageService()
|
||||
|
||||
async function cleanup() {
|
||||
for (const dir of ['aa', 'aab', 'cc', 'ghostdir', 'ghostdir2']) {
|
||||
await disk.deleteAll(dir)
|
||||
}
|
||||
}
|
||||
|
||||
test.group('FSStorageService directories', (group) => {
|
||||
group.each.setup(() => cleanup())
|
||||
group.each.teardown(() => cleanup())
|
||||
|
||||
test('finds a directory that has no .keep marker', async ({ assert }) => {
|
||||
await disk.put('ghostdir/a.txt', 'hello')
|
||||
|
||||
assert.isTrue(await storage.entryExists('ghostdir'))
|
||||
assert.deepInclude(await storage.getEntry('ghostdir'), { type: 'folder', name: 'ghostdir' })
|
||||
})
|
||||
|
||||
test('moves a marker-less directory with its contents', async ({ assert }) => {
|
||||
await disk.put('ghostdir/nested/a.txt', 'hello')
|
||||
|
||||
await storage.moveEntry('ghostdir', 'ghostdir2')
|
||||
|
||||
assert.isFalse(await disk.exists('ghostdir/nested/a.txt'))
|
||||
assert.equal(await disk.get('ghostdir2/nested/a.txt'), 'hello')
|
||||
assert.deepInclude(await storage.getEntry('ghostdir2'), { type: 'folder' })
|
||||
})
|
||||
|
||||
test('does not touch a sibling directory sharing the same name prefix', async ({ assert }) => {
|
||||
await disk.put('aa/a.txt', 'from aa')
|
||||
await disk.put('aab/a.txt', 'from aab')
|
||||
|
||||
await storage.moveEntry('aa', 'cc')
|
||||
|
||||
assert.equal(await disk.get('cc/a.txt'), 'from aa')
|
||||
assert.equal(await disk.get('aab/a.txt'), 'from aab')
|
||||
})
|
||||
|
||||
test('deletes a directory without touching a prefix sibling', async ({ assert }) => {
|
||||
await disk.put('aa/a.txt', 'from aa')
|
||||
await disk.put('aab/a.txt', 'from aab')
|
||||
|
||||
await storage.deleteEntry('aa')
|
||||
|
||||
assert.isFalse(await disk.exists('aa/a.txt'))
|
||||
assert.equal(await disk.get('aab/a.txt'), 'from aab')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user