Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(world): add namespaceLabel to system config #3057

Merged
merged 11 commits into from
Aug 23, 2024
Prev Previous commit
Next Next commit
more tests
  • Loading branch information
holic committed Aug 22, 2024
commit 65ecfb1451eda3d17610527dab330bed728995ec
35 changes: 35 additions & 0 deletions packages/store/ts/config/v2/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,22 @@ describe("defineStore", () => {
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineStore({
namespace: "CustomNS",
tables: {
Example: {
// @ts-expect-error "Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context"
namespaceLabel: "NotAllowed",
schema: { id: "address" },
key: ["id"],
},
},
}),
).throwsAndHasTypeError(
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineStore({
namespace: "CustomNS",
Expand Down Expand Up @@ -697,6 +713,25 @@ describe("defineStore", () => {
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineStore({
namespaces: {
CustomNS: {
tables: {
Example: {
// @ts-expect-error "Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context"
namespaceLabel: "NotAllowed",
schema: { id: "address" },
key: ["id"],
},
},
},
},
}),
).throwsAndHasTypeError(
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineStore({
namespaces: {
Expand Down
127 changes: 127 additions & 0 deletions packages/world/ts/config/v2/world.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,22 @@ describe("defineWorld", () => {
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineWorld({
namespace: "CustomNS",
tables: {
Example: {
// @ts-expect-error "Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context"
namespaceLabel: "NotAllowed",
schema: { id: "address" },
key: ["id"],
},
},
}),
).throwsAndHasTypeError(
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineWorld({
namespace: "CustomNS",
Expand Down Expand Up @@ -563,6 +579,25 @@ describe("defineWorld", () => {
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineWorld({
namespaces: {
CustomNS: {
tables: {
Example: {
// @ts-expect-error "Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context"
namespaceLabel: "NotAllowed",
schema: { id: "address" },
key: ["id"],
},
},
},
},
}),
).throwsAndHasTypeError(
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineWorld({
namespaces: {
Expand Down Expand Up @@ -631,6 +666,98 @@ describe("defineWorld", () => {
attest<false>(config.systems.Example.openAccess).equals(false);
});

it("should throw if system label/namespace is overridden in namespace context", () => {
attest(() =>
defineWorld({
systems: {
Example: {
// @ts-expect-error "Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context"
label: "",
},
},
}),
).throwsAndHasTypeError(
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineWorld({
systems: {
Example: {
// @ts-expect-error "Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context"
namespaceLabel: "",
},
},
}),
).throwsAndHasTypeError(
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineWorld({
systems: {
Example: {
// @ts-expect-error "Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context"
namespace: "",
},
},
}),
).throwsAndHasTypeError(
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineWorld({
namespaces: {
CustomNS: {
systems: {
Example: {
// @ts-expect-error "Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context"
label: "",
},
},
},
},
}),
).throwsAndHasTypeError(
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineWorld({
namespaces: {
CustomNS: {
systems: {
Example: {
// @ts-expect-error "Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context"
namespaceLabel: "",
},
},
},
},
}),
).throwsAndHasTypeError(
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);

attest(() =>
defineWorld({
namespaces: {
CustomNS: {
systems: {
Example: {
// @ts-expect-error "Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context"
namespace: "",
},
},
},
},
}),
).throwsAndHasTypeError(
"Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context",
);
});

it("should allow a const config as input", () => {
const config = {
tables: {
Expand Down
Loading