-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcharacter.test.js
More file actions
55 lines (51 loc) · 2.53 KB
/
character.test.js
File metadata and controls
55 lines (51 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Character } from '../src/index.js';
import { test, describe } from 'node:test';
import assert from 'node:assert';
describe('Character', () => {
test('Character.fromFile with JSON file', async () => {
const file = new File(['{"name": "John Doe"}'], 'character.json', { type: 'application/json' });
const character = await Character.fromFile(file);
assert.strictEqual(character.name, 'John Doe');
});
test('Character.fromFile with PNG file', async () => {
const pngData = new Uint8Array([
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53, 0xDE, 0x00, 0x00, 0x00,
0x0A, 0x74, 0x45, 0x58, 0x74, 0x63, 0x68, 0x61, 0x72, 0x61, 0x00, 0x7B,
0x22, 0x6E, 0x61, 0x6D, 0x65, 0x22, 0x3A, 0x22, 0x4A, 0x6F, 0x68, 0x6E,
0x20, 0x44, 0x6F, 0x65, 0x22, 0x7D, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44,
0x41, 0x54, 0x78, 0x9C, 0x63, 0x60, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,
0xE2, 0x21, 0xBC, 0x33, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44,
0xAE, 0x42, 0x60, 0x82
]);
const file = new File([pngData], 'character.png', { type: 'image/png' });
const character = await Character.fromFile(file);
assert.strictEqual(character.name, 'John Doe');
});
test('Character.fromFile with WEBP file', async () => {
const webpData = new Uint8Array([
0x52, 0x49, 0x46, 0x46, 0x3A, 0x00, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50,
0x56, 0x50, 0x38, 0x20, 0x0A, 0x00, 0x00, 0x00, 0x30, 0x2E, 0x30, 0x30,
0x2E, 0x30, 0x30, 0x2E, 0x30, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x00,
0x4C, 0x49, 0x53, 0x54, 0x3A, 0x00, 0x00, 0x00, 0x4A, 0x53, 0x4F, 0x4E,
0x3A, 0x7B, 0x22, 0x6E, 0x61, 0x6D, 0x65, 0x22, 0x3A, 0x22, 0x4A, 0x6F,
0x68, 0x6E, 0x20, 0x44, 0x6F, 0x65, 0x22, 0x7D, 0x00, 0x00, 0x00, 0x00
]);
const file = new File([webpData], 'character.webp', { type: 'image/webp' });
const character = await Character.fromFile(file);
assert.strictEqual(character.name, 'John Doe');
});
test('Character properties and methods', async () => {
const metadata = {
name: 'John Doe',
description: 'A brave warrior',
avatar: 'none',
system_prompt: 'A warrior in a fantasy world'
};
const character = new Character(metadata);
assert.strictEqual(character.name, 'John Doe');
assert.strictEqual(character.description, 'A warrior in a fantasy world');
assert.strictEqual(character.avatar, '');
});
});