镜像自地址
https://github.com/lhly/cloud-drive-renamer.git
已同步 2026-10-20 13:47:47 +08:00
新增 OneDrive 个人版适配器、MAIN 桥接、名称校验与冲突检测、目录身份与分页遍历。同步更新三语简介、商店素材、仓库描述及 manifest 域名注册。修复面板键盘冒泡至宿主页面的隔离与工具栏 Escape 作用域。修正 OneDrive 同步结果语义为手动刷新提示, 避免误报同步失败。补全对应单测与浏览器验收脚本。
57 行
2.7 KiB
TypeScript
57 行
2.7 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
makeOneDriveDirectoryKey,
|
|
parseOneDriveChildrenPage,
|
|
toOneDriveFileItem,
|
|
validateOneDriveContinuation,
|
|
} from '../../../src/adapters/onedrive/models';
|
|
|
|
const item = {
|
|
id: 'hex!item-1',
|
|
name: 'Episode 01.mkv',
|
|
size: 128,
|
|
eTag: '"version-1"',
|
|
parentReference: { id: 'hex!folder', driveId: 'drive-1' },
|
|
sharepointIds: {
|
|
siteId: '11111111-1111-1111-1111-111111111111',
|
|
listId: '22222222-2222-2222-2222-222222222222',
|
|
listItemUniqueId: '33333333-3333-3333-3333-333333333333',
|
|
},
|
|
file: { mimeType: 'video/x-matroska' },
|
|
lastModifiedDateTime: '2026-09-27T00:00:00Z',
|
|
};
|
|
|
|
describe('OneDrive data mapping', () => {
|
|
it('keeps SharePoint GUID identity stable and qualifies the parent folder', () => {
|
|
expect(toOneDriveFileItem(item)).toMatchObject({
|
|
id: '11111111-1111-1111-1111-111111111111:22222222-2222-2222-2222-222222222222:33333333-3333-3333-3333-333333333333',
|
|
parentId: 'drive-1:hex!folder',
|
|
driveItemId: 'drive-1:hex!item-1',
|
|
ext: '.mkv',
|
|
size: 128,
|
|
mtime: Date.parse('2026-09-27T00:00:00Z'),
|
|
});
|
|
});
|
|
|
|
it('excludes folders, remote items, special folders, and incomplete identities', () => {
|
|
expect(toOneDriveFileItem({ ...item, folder: { childCount: 1 } })).toBeNull();
|
|
expect(toOneDriveFileItem({ ...item, remoteItem: { id: 'remote' } })).toBeNull();
|
|
expect(toOneDriveFileItem({ ...item, specialFolder: { name: 'vault' } })).toBeNull();
|
|
expect(toOneDriveFileItem({ ...item, sharepointIds: { ...item.sharepointIds, listItemUniqueId: 'bad' } })).toBeNull();
|
|
});
|
|
|
|
it('rejects malformed list payloads and unsafe continuation links', () => {
|
|
expect(() => parseOneDriveChildrenPage({ value: 'not-an-array' })).toThrow(/invalid children response/i);
|
|
expect(parseOneDriveChildrenPage({ value: [], '@odata.nextLink': '/personal/user/_api/v2.0/drive/root/children?$skiptoken=x' }).value).toEqual([]);
|
|
expect(() => validateOneDriveContinuation('https://evil.example/_api/v2.0/drive/root/children', 'https://onedrive.live.com', '/personal/')).toThrow(/outside/i);
|
|
expect(() => validateOneDriveContinuation('/photos', 'https://onedrive.live.com', '/personal/')).toThrow(/outside/i);
|
|
});
|
|
|
|
it('isolates directory keys by site path and folder', () => {
|
|
expect(makeOneDriveDirectoryKey('https://onedrive.live.com/personal/a', 'drive', 'folder'))
|
|
.not.toBe(makeOneDriveDirectoryKey('https://onedrive.live.com/personal/b', 'drive', 'folder'));
|
|
expect(makeOneDriveDirectoryKey('https://onedrive.live.com/personal/a', 'drive', 'one'))
|
|
.not.toBe(makeOneDriveDirectoryKey('https://onedrive.live.com/personal/a', 'drive', 'two'));
|
|
});
|
|
});
|