fix system entity registration by re-applying configs to modules

This commit is contained in:
dswbx
2025-01-17 15:46:05 +01:00
parent 9422cc5bb8
commit a6fd9f0d96
10 changed files with 112 additions and 14 deletions

View File

@@ -0,0 +1,73 @@
import { describe, expect, test } from "bun:test";
import { createApp, registries } from "../../src";
import * as proto from "../../src/data/prototype";
import { StorageLocalAdapter } from "../../src/media/storage/adapters/StorageLocalAdapter";
describe("repros", async () => {
/**
* steps:
* 1. enable media
* 2. create 'test' entity
* 3. add media to 'test'
*
* There was an issue that AppData had old configs because of system entity "media"
*/
test("registers media entity correctly to relate to it", async () => {
registries.media.register("local", StorageLocalAdapter);
const app = createApp();
await app.build();
{
// 1. enable media
const [, config] = await app.module.media.schema().patch("", {
enabled: true,
adapter: {
type: "local",
config: {
path: "./"
}
}
});
expect(config.enabled).toBe(true);
}
{
// 2. create 'test' entity
await app.module.data.schema().patch(
"entities.test",
proto
.entity("test", {
content: proto.text()
})
.toJSON()
);
expect(app.em.entities.map((e) => e.name)).toContain("test");
}
{
await app.module.data.schema().patch("entities.test.fields.files", {
type: "media",
config: {
required: false,
fillable: ["update"],
hidden: false,
mime_types: [],
virtual: true,
entity: "test"
}
});
expect(
app.module.data.schema().patch("relations.000", {
type: "poly",
source: "test",
target: "media",
config: { mappedBy: "files" }
})
).resolves.toBeDefined();
}
expect(app.em.entities.map((e) => e.name)).toEqual(["media", "test"]);
});
});