Skip to content

Commit

Permalink
Test log transformation to hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Mar 20, 2024
1 parent d944a32 commit a0fe066
Showing 1 changed file with 143 additions and 0 deletions.
143 changes: 143 additions & 0 deletions src/ILICheck.Web/ClientApp/src/logHierarchy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { describe, expect, test } from "@jest/globals";
import { createLogHierarchy } from "./logHierarchy";

describe("transform log data to hierarchy", () => {
test("constraint pass", () => {
const data = [
{
tid: "o1",
message: "validate set constraint ModelA.TopicA.ClassA.ConstraintName...",
type: "Info",
},
];

const expected = [
{
message: "ModelA",
type: "Info",
values: [
{
message: "TopicA.ClassA",
type: "Info",
values: [{ message: "Set Constraint ConstraintName", type: "Info" }],
},
],
},
];

const hierarchy = createLogHierarchy(data);

expect(hierarchy).toStrictEqual(expected);
});

test("constraint fail", () => {
const data = [
{
tid: "o1",
message: "validate existence constraint ModelA.TopicA.ClassA.ConstraintName...",
type: "Info",
},
{
tid: "o2",
message: "Some other message",
type: "Info",
},
{
tid: "o3",
message:
"Existence constraint ModelA.TopicA.ClassA.ConstraintName is violated! The value of the attribute Test of t1 was not found in the condition class.",
type: "Error",
},
];

const expected = [
{
message: "ModelA",
type: "Error",
values: [
{
message: "TopicA.ClassA",
type: "Error",
values: [
{
message:
"Existence constraint ConstraintName is violated! The value of the attribute Test of t1 was not found in the condition class.",
type: "Error",
},
],
},
],
},
];

const hierarchy = createLogHierarchy(data);

expect(hierarchy).toStrictEqual(expected);
});

test("mixed log types", () => {
const data = [
{
tid: "o1",
message: "validate data...",
type: "Info",
},
{
tid: "o2",
message: "lookup model <Base> 2.3 in repository <http://models.geo.admin.ch/>",
type: "Info",
},
{
tid: "o3",
message: "validate mandatory constraint ModelA.TopicA.ClassA.ConstraintName...",
type: "Info",
},
{
tid: "o4",
message:
"MandatoryConstraint ModelA.TopicA.ClassA.ConstraintName of ModelA.TopicA.ClassA is not yet implemented.",
type: "Warning",
},
{
tid: "o5",
message: "validate mandatory constraint ModelA.TopicA.ClassA.Constraint1...",
type: "Info",
},
{
tid: "o6",
message: "validate mandatory constraint ModelA.TopicA.ClassA.Constraint2...",
type: "Info",
},
{
tid: "o7",
message: "Custom message for constraint. ModelA.TopicA.ClassA.Constraint1 (MANDATORY CONSTRAINT DEFINED(Abc);)",
type: "Error",
},
];

const expected = [
{
message: "ModelA",
type: "Error",
values: [
{
message: "TopicA.ClassA",
type: "Error",
values: [
{
message: "MandatoryConstraint ConstraintName of ModelA.TopicA.ClassA is not yet implemented.",
type: "Warning",
},
{ message: "Custom message for constraint.", type: "Error" },
{ message: "Mandatory Constraint Constraint2", type: "Info" },
],
},
],
},
];

const hierarchy = createLogHierarchy(data);

expect(hierarchy).toStrictEqual(expected);
});
});

0 comments on commit a0fe066

Please sign in to comment.