Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/services/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,22 +401,43 @@ describe("processConversionTMtoTD", () => {
});

test("removes TM-specific fields", () => {
const tmContent = `{
const stringTypeContent = `{
"@type": "tm:ThingModel",
"tm:required": ["#properties/prop1"],
"properties": { "prop1": {} }
}`;

const result = processConversionTMtoTD(
tmContent,
const stringResult = processConversionTMtoTD(
stringTypeContent,
{},
["prop1"],
[],
[],
""
);

expect(result).not.toHaveProperty("tm:required");
expect(stringResult).not.toHaveProperty("tm:required");
expect(stringResult).not.toHaveProperty("@type");

const arrayTypeContent = `{
"@type": ["tm:ThingModel","example_key:example_val"],
"tm:required": ["#properties/prop1"],
"properties": { "prop1": {} }
}`;

const arrayResult = processConversionTMtoTD(
arrayTypeContent,
{},
["prop1"],
[],
[],
""
);

expect(Array.isArray(arrayResult["@type"])).toBe(true);
expect(arrayResult["@type"]).toContain("example_key:example_val");
expect(arrayResult["@type"]).not.toContain("tm:ThingModel");
expect(arrayResult).not.toHaveProperty("tm:required");
});

test("handles complex TM to TD conversion", () => {
Expand Down
14 changes: 12 additions & 2 deletions src/services/operations.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Rohithgvmg for this PR. You need to run the prettier --write src/services/operations.ts in order to the code being formatted according to the prettier rules.
Another thing is the unit tests also need to be changed in operations.test.ts file. You can see them failing when you run yarn test
The comment on line 144 is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for detailed review, fixed the code , kindly review

Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,19 @@ export function processConversionTMtoTD(
};
}

delete parsed["@type"];
if (parsed["@type"]) {
if (Array.isArray(parsed["@type"])) {
parsed["@type"] = parsed["@type"].filter(
(x: String) => x != "tm:ThingModel"
);
if (parsed["@type"].length == 0) {
delete parsed["@type"];
}
} else {
delete parsed["@type"];
}
}
delete parsed["tm:required"];

return parsed;
} catch (error) {
console.error("Error processing TM:", error);
Expand Down