Copilot commented on code in PR #6687:
URL: https://github.com/apache/texera/pull/6687#discussion_r3626779094
##########
frontend/src/app/workspace/service/dynamic-schema/dynamic-schema.service.spec.ts:
##########
@@ -142,3 +143,106 @@ describe("DynamicSchemaService", () => {
})
);
});
+
+describe("DynamicSchemaService.mutateProperty", () => {
+ const matchByName = (name: string) => (propertyName: string, _:
CustomJSONSchema7) => propertyName === name;
+ const markMutated = (_: string, propertyValue: CustomJSONSchema7):
CustomJSONSchema7 => ({
+ ...propertyValue,
+ description: "mutated",
+ });
+
+ it("should replace a matched top-level property without mutating the
original schema", () => {
+ const original = {
+ type: "object",
+ properties: {
+ target: { type: "string", description: "original" },
+ other: { type: "number" },
+ },
+ } as CustomJSONSchema7;
+
+ const result = DynamicSchemaService.mutateProperty(original,
matchByName("target"), markMutated);
+
+ // the returned schema has the matched property mutated
+ expect((result.properties!.target as
CustomJSONSchema7).description).toEqual("mutated");
+ // the non-matching property is left untouched
+ expect(result.properties!.other).toEqual({ type: "number" });
+ // the original schema object is deep cloned and stays unchanged
+ expect((original.properties!.target as
CustomJSONSchema7).description).toEqual("original");
+ expect(result).not.toBe(original);
+ });
+
+ it("should recurse into nested object properties to find the matched
property", () => {
+ const original = {
+ type: "object",
+ properties: {
+ nested: {
+ type: "object",
+ properties: {
+ deepTarget: { type: "string", description: "original" },
+ },
+ },
+ },
+ } as CustomJSONSchema7;
+
+ const result = DynamicSchemaService.mutateProperty(original,
matchByName("deepTarget"), markMutated);
+
+ const nested = result.properties!.nested as CustomJSONSchema7;
+ expect((nested.properties!.deepTarget as
CustomJSONSchema7).description).toEqual("mutated");
+ });
+
+ it("should recurse into definitions to find the matched property", () => {
+ const original = {
+ type: "object",
+ definitions: {
+ target: { type: "string", description: "original" },
+ },
+ } as CustomJSONSchema7;
+
+ const result = DynamicSchemaService.mutateProperty(original,
matchByName("target"), markMutated);
+
+ expect((result.definitions!.target as
CustomJSONSchema7).description).toEqual("mutated");
+ });
+
+ it("should recurse into array items to find the matched property", () => {
+ const original = {
+ type: "object",
+ properties: {
+ list: {
+ type: "array",
+ items: [
+ {
+ type: "object",
+ properties: {
+ target: { type: "string", description: "original" },
+ },
+ },
+ ],
+ },
+ },
+ } as CustomJSONSchema7;
+
+ const result = DynamicSchemaService.mutateProperty(original,
matchByName("target"), markMutated);
+
+ const list = result.properties!.list as CustomJSONSchema7;
+ const firstItem = (list.items as CustomJSONSchema7[])[0];
+ expect((firstItem.properties!.target as
CustomJSONSchema7).description).toEqual("mutated");
+ });
Review Comment:
The current tests exercise the `items` branch when it is an array
(`Array.isArray(schemaItems)`), but they don't cover the other code path where
`items` is a single schema object. That leaves an explicit branch in
`mutateProperty` untested and could miss regressions for the common `items: {
... }` case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]