59 lines
2.3 KiB
JavaScript
59 lines
2.3 KiB
JavaScript
import assert from 'node:assert/strict';
|
|||
|
|
import test from 'node:test';
|
||
|
|
import {makeArchive} from '../scripts/portable.mjs';
|
||
|
|
import {openVault} from '../scripts/vault.mjs';
|
||
|
|
|
||
|
|
test('vault import requests stable embedded IDs and remaps the actor in embedded UUIDs', async t => {
|
||
|
|
const actorId = 'ABCDEFGHIJKLMNOP';
|
||
|
|
const itemId = '1234567890abcdef';
|
||
|
|
const newId = 'ZYXWVUTSRQPONMLK';
|
||
|
|
const user = {id: 'recipient', name: 'Recipient', role: 1};
|
||
|
|
const sourceActor = {
|
||
|
|
documentName: 'Actor',
|
||
|
|
uuid: `Actor.${actorId}`,
|
||
|
|
toObject: () => ({
|
||
|
|
_id: actorId,
|
||
|
|
name: 'Hero',
|
||
|
|
type: 'character',
|
||
|
|
items: [{_id: itemId, name: 'Spell', type: 'spell'}],
|
||
|
|
system: {details: {biography: {value: `@UUID[Actor.${actorId}.Item.${itemId}]{Spell}`}}}
|
||
|
|
})
|
||
|
|
};
|
||
|
|
const {blob} = await makeArchive({docs: [sourceActor], metadata: {system: 'dnd5e', systemVersion: '6.1.2'}});
|
||
|
|
const calls = [];
|
||
|
|
const DialogV2 = {
|
||
|
|
wait: async () => 'import',
|
||
|
|
confirm: async () => true,
|
||
|
|
prompt: async ({ok}) => ok.callback(null, null, {
|
||
|
|
element: {querySelector: () => ({files: [blob]})}
|
||
|
|
})
|
||
|
|
};
|
||
|
|
const create = async (data, options) => {
|
||
|
|
calls.push({data, options});
|
||
|
|
return {id: data._id, toObject: () => data};
|
||
|
|
};
|
||
|
|
const globals = {
|
||
|
|
CONST: {USER_ROLES: {GAMEMASTER: 4}},
|
||
|
|
CONFIG: {Actor: {documentClass: {create}}},
|
||
|
|
game: {user, system: {version: '6.1.2'}, folders: new Map(), actors: [], items: []},
|
||
|
|
foundry: {applications: {api: {DialogV2}}, utils: {randomID: () => newId}},
|
||
|
|
ui: {notifications: {info: () => {}, error: message => assert.fail(message)}}
|
||
|
|
};
|
||
|
|
for (const [key, value] of Object.entries(globals)) {
|
||
|
|
const descriptor = Object.getOwnPropertyDescriptor(globalThis, key);
|
||
|
|
Object.defineProperty(globalThis, key, {value, configurable: true});
|
||
|
|
t.after(() => {
|
||
|
|
if (descriptor) Object.defineProperty(globalThis, key, descriptor);
|
||
|
|
else delete globalThis[key];
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
await openVault();
|
||
|
|
|
||
|
|
assert.equal(calls.length, 1);
|
||
|
|
const [{data, options}] = calls;
|
||
|
|
assert.deepEqual(options, {keepId: true, keepEmbeddedIds: true});
|
||
|
|
assert.deepEqual(data.ownership, {default: 0, [user.id]: 3});
|
||
|
|
assert.equal(data.items[0]._id, itemId);
|
||
|
|
assert.equal(data.system.details.biography.value, `@UUID[Actor.${newId}.Item.${itemId}]{Spell}`);
|
||
|
|
});
|