@aml-org/amf-custom-validator 1.8.0-SNAPSHOT.4 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/simple.js DELETED
@@ -1,124 +0,0 @@
1
- const fs = require("fs");
2
- var assert = require('assert');
3
-
4
- function invalidReport(report) {
5
- return report[0]["doc:encodes"][0]["conforms"] === false
6
- }
7
-
8
- describe('validator', () => {
9
-
10
- describe('validate', () => {
11
-
12
- it("should load the WASM code, validate a profile, exit", (done) => {
13
- const profile = fs.readFileSync(__dirname + "/../../../test/data/integration/profile10/profile.yaml").toString()
14
- const data = fs.readFileSync(__dirname + "/../../../test/data/integration/profile10/negative.data.jsonld").toString()
15
- const validator = require(__dirname + "/../index")
16
- validator.initialize(() => {
17
- validator.validate(profile, data, false, (r, err) => {
18
- if (err) {
19
- done(err);
20
- } else {
21
- let report = JSON.parse(r)
22
- assert.ok(invalidReport(report))
23
- validator.validate(profile, data, false, (r, err) => {
24
- if (err) {
25
- done(err)
26
- } else {
27
- let report = JSON.parse(r)
28
- assert.ok(invalidReport(report))
29
- validator.exit();
30
- done();
31
- }
32
- });
33
- }
34
- });
35
- })
36
- });
37
-
38
- it ("should generate the Rego code for a profile and exit", (done) => {
39
- const profile = fs.readFileSync(__dirname + "/../../../test/data/integration/profile10/profile.yaml").toString()
40
-
41
- const validator = require(__dirname + "/../index")
42
-
43
- validator.initialize(() => {
44
- validator.generateRego(profile, (r, err) => {
45
- if (err) {
46
- done(err);
47
- } else {
48
- assert.ok(r.indexOf("package profile_kiali") > -1)
49
- validator.exit();
50
- done();
51
- }
52
- });
53
- })
54
- })
55
-
56
- it ("should normalize input data", (done) => {
57
- const data = fs.readFileSync(__dirname + "/../../../test/data/integration/profile10/negative.data.jsonld").toString()
58
-
59
- const validator = require(__dirname + "/../index")
60
-
61
- validator.initialize(() => {
62
- validator.normalizeInput(data, (r, err) => {
63
- if (err) {
64
- done(err);
65
- } else {
66
- assert.ok(r.indexOf("@ids") > -1)
67
- validator.exit();
68
- done();
69
- }
70
- });
71
- })
72
- })
73
-
74
- })
75
-
76
- describe('validate with message expressions', () => {
77
-
78
- it("validate and compute message expression value", (done) => {
79
- const profile = fs.readFileSync(__dirname + "/../../../test/data/integration/profile26/profile.yaml").toString()
80
- const data = fs.readFileSync(__dirname + "/../../../test/data/integration/profile26/negative.data.jsonld").toString()
81
- const validator = require(__dirname + "/../index")
82
- validator.initialize(() => {
83
- validator.validate(profile, data, false, (r, err) => {
84
- if (err) {
85
- done(err);
86
- } else {
87
- let report = JSON.parse(r)
88
- assert.ok(report[0]["doc:encodes"][0]["result"][0]["resultMessage"] === "Movie 'Disaster Movie' has a rating of 1.9 but it does not have at least 10 reviews (actual reviews: 5) to support that rating")
89
- validator.exit();
90
- done();
91
- }
92
- });
93
- })
94
- });
95
- })
96
-
97
- describe('validate with configuration', () => {
98
-
99
- it("must match expected report output", (done) => {
100
- const profile = fs.readFileSync(__dirname + "/../../../test/data/integration/profile26/profile.yaml").toString()
101
- const data = fs.readFileSync(__dirname + "/../../../test/data/integration/profile26/negative.data.jsonld").toString()
102
- const validator = require(__dirname + "/../index")
103
- validator.initialize(() => {
104
- const reportConfig = {
105
- "IncludeReportCreationTime": false,
106
- "ReportSchemaIri": "http://a.ml/report",
107
- "LexicalSchemaIri": "http://a.ml/lexical"
108
- }
109
- validator.validateWithReportConfiguration(profile, data, false, reportConfig, (r, err) => {
110
- if (err) {
111
- done(err);
112
- } else {
113
- let report = JSON.parse(r)
114
- assert.ok(report[0]["doc:encodes"][0]["dateCreated"] === undefined)
115
- assert.strictEqual(report[0]["@context"]["reportSchema"], "http://a.ml/report#/declarations/")
116
- assert.strictEqual(report[0]["@context"]["lexicalSchema"], "http://a.ml/lexical#/declarations/")
117
- validator.exit();
118
- done();
119
- }
120
- });
121
- })
122
- });
123
- })
124
- })