chore: changeset

This commit is contained in:
Guido D'Orsi
2025-08-20 16:39:48 +02:00
parent 2e73d09ab9
commit c55297cdc5
4 changed files with 93 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"cojson": patch
---
Move the session log management into WASM

View File

@@ -5,7 +5,8 @@
"workspaces": [
"packages/*",
"examples/*",
"starters/*"
"starters/*",
"crates/*"
],
"packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c",
"engines": {

View File

@@ -0,0 +1,85 @@
import { assert, beforeEach, describe, expect, test } from "vitest";
import { co, z } from "../../exports.js";
import { createJazzTestAccount, setupJazzTestSync } from "../../testing.js";
// Define the difficulty levels enum
const difficultyLevels = ["easy", "medium", "hard"] as const;
// Define the Quest schema with migration
const QuestSchema = co
.map({
title: z.string(),
description: z.string(),
imageUrl: z.string(),
twigs: z.number(),
difficulty: z.enum(difficultyLevels),
category: z.string(),
categories: z.array(z.string()),
completed: z.boolean(),
})
.withMigration((quest) => {
if (quest.categories === undefined) {
quest.categories = [quest.category];
}
});
beforeEach(async () => {
await setupJazzTestSync();
await createJazzTestAccount({
isCurrentActiveAccount: true,
creationProps: { name: "Quest Tester" },
});
});
describe("QuestSchema", () => {
test("should fill categories array with category when categories is undefined", async () => {
// Create a quest without categories
// @ts-expect-error - (simulating old data)
const quest = QuestSchema.create({
title: "Test Quest",
description: "A test quest description",
imageUrl: "https://example.com/image.jpg",
twigs: 100,
difficulty: "medium",
category: "adventure",
completed: false,
});
// Initially categories should be undefined
expect(quest.categories).toBeUndefined();
// Load the quest to trigger the migration
const loadedQuest = await QuestSchema.load(quest.id);
assert(loadedQuest);
// After loading, the migration should have run and filled categories
expect(loadedQuest.categories).toEqual(["adventure"]);
expect(loadedQuest.category).toEqual("adventure");
});
test("should preserve existing categories when they are already defined", async () => {
// Create a quest with categories already defined
const quest = QuestSchema.create({
title: "Test Quest",
description: "A test quest description",
imageUrl: "https://example.com/image.jpg",
twigs: 150,
difficulty: "hard",
category: "combat",
categories: ["combat", "boss-fight", "endgame"],
completed: false,
});
// Categories should be defined initially
expect(quest.categories).toEqual(["combat", "boss-fight", "endgame"]);
// Load the quest to ensure migration doesn't change existing categories
const loadedQuest = await QuestSchema.load(quest.id);
assert(loadedQuest);
// Categories should remain unchanged after migration
expect(loadedQuest.categories).toEqual(["combat", "boss-fight", "endgame"]);
expect(loadedQuest.category).toEqual("combat");
});
});

View File

@@ -3,7 +3,7 @@ packages:
- 'examples/*'
- 'starters/*'
- 'tests/*'
- 'crates/cojson-core-wasm'
- 'crates/*'
- 'bench'
catalogs: