Skip to content

Commit 307eb8a

Browse files
closes #173 (#174)
* import is fixed * closes #173
1 parent 023ada3 commit 307eb8a

File tree

12 files changed

+220
-119
lines changed

12 files changed

+220
-119
lines changed

java/Coded-Json/src/main/java/com/codedjson/utils/Decode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.codedjson.utils;
22

3-
import com.codedjson.Json;
3+
import com.codedjson.*;
44
import com.codedjson.exceptions.AbsolutePathConstraintError;
55
import com.codedjson.exceptions.IllegalJsonType;
66
import com.codedjson.exceptions.UndeserializedCJSON;

npm/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"main": "out/cjson.js",
99
"types": "out/cjson.d.ts",
1010
"scripts": {
11+
"compile": "npx tsc",
1112
"build": "npx tsc && npm pack",
13+
"test": "npx jasmine",
1214
"clean": "echo Y | rmdir out /S && del coded-json-*.tgz",
1315
"document": "npx tsc && npx jsdoc out/ -r -d ../docs/npm -c jsdoc.config.json"
1416
},
@@ -30,6 +32,8 @@
3032
"typescript": "^4.9.5"
3133
},
3234
"dependencies": {
35+
"jasmine": "^4.5.0",
36+
"jasmine-spec-reporter": "^7.0.0",
3337
"jsdoc": "^4.0.2",
3438
"ts-node": "^10.9.1"
3539
}
File renamed without changes.

tests/npm/spec/support/jasmine.json npm/spec/support/jasmine.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"spec_dir": "spec",
33
"spec_files": [
4-
"./tests/*.js"
4+
"tests/*[tT]ests.?(m)js"
55
],
6-
"helpers": ["helpers/*.js"],
6+
"helpers": ["spec/helpers/*.js"],
77
"env": {
88
"stopSpecOnExpectationFailure": false,
99
"random": true

tests/npm/spec/tests/codedJsonTests.js npm/spec/tests/codedJsonTests.js

+26-41
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
const Cjson = require('coded-json').Cjson;
21
const assert = require('assert');
32
const fs = require('fs');
43
const path = require('path');
4+
const Cjson = require("../../out/cjson").Cjson;
5+
const jasmine = require("jasmine");
56

7+
const basePath = path.join(__dirname, "..", "..", "..", "tests", "test-files");
68
/** Path to target.cjson */
7-
const cjsonfilePath = path.join(__dirname, "..", "..", "..", "\\test-files\\target.cjson");
9+
const cjsonfilePath = path.join(basePath, "target.cjson");
810
/** Path to source.json */
9-
const jsonfilePath = path.join(__dirname, "..", "..", "..", "\\test-files\\source.json");
11+
const jsonfilePath = path.join(basePath, "source.json");
1012
/** Path to pure.json */
11-
const pureJsonfilePath = path.join(__dirname, "..", "..", "..", "\\test-files\\pure.json");
13+
const pureJsonfilePath = path.join(basePath, "pure.json");
1214
/** Path to relativeTargetCjson.json */
13-
const relativeTargetCjson = path.join(__dirname, "..", "..", "..", "\\test-files\\targetRelativeCalls.cjson");
15+
const relativeTargetCjson = path.join(basePath, "targetRelativeCalls.cjson");
1416
/** Path to relativeTargetCjson.json */
15-
const VariableInjection = path.join(__dirname, "..", "..", "..", "\\test-files\\VariableInjection.cjson");
17+
const VariableInjection = path.join(basePath, "VariableInjection.cjson");
1618

1719
/**
1820
* Tests related to CJSON files
1921
*/
2022
describe("CJSON Test 1", () => {
21-
2223
it("I should be able to import pure JSON files", () => {
2324
var cjson = new Cjson(pureJsonfilePath);
2425
var pureJSONContent = cjson.deserialize();
@@ -48,10 +49,7 @@ describe("CJSON Test 1", () => {
4849

4950
it("I should be able to deserialize relative path to local variable", () => {
5051
var cjson = new Cjson(relativeTargetCjson);
51-
5252
var decodedJSON = cjson.deserialize();
53-
54-
console.log(decodedJSON);
5553

5654
assert.equal(decodedJSON.target.digitCheck, cjson.json.parse("target.digitCheck"));
5755
assert.equal(decodedJSON.target.digitImport, cjson.json.parse("target.digitImport"));
@@ -70,9 +68,8 @@ describe("CJSON Test 1", () => {
7068
injectedData: "jsonInjectionValue"
7169
}
7270
};
73-
var deserializedVal = cjson.inject(injectObj);
71+
var deserializedVal = cjson.inject(injectObj).deserialize();
7472

75-
console.log(deserializedVal);
7673
assert.equal(deserializedVal.target.fruit, injectObj.fruit);
7774
assert.equal(JSON.stringify(deserializedVal.jsonInjection), JSON.stringify(injectObj.jsonTypeData))
7875
});
@@ -115,44 +112,32 @@ describe("CJSON Test 1", () => {
115112
assert.equal(cjson.deserialize().quiz.sport.q1, undefined);
116113
});
117114

118-
it("I should be able to stringify JSON object using toString function", ()=> {
115+
it("I should be able to stringify JSON object using toString()", ()=> {
119116
var fileContent = fs.readFileSync(pureJsonfilePath).toJSON();
120117
var stringContent = Cjson.toString(fileContent);
121118
assert.equal(JSON.stringify(fileContent), stringContent);
122119
});
123-
});
124-
125-
/**
126-
* Tests related to native JSON files
127-
*/
128-
describe("JSON Test 2", () => {
129-
130-
it("I should be able to use isContentJson()", () => {
131-
var cjson = new Cjson(pureJsonfilePath);
132-
assert.equal(cjson.isContentJson(), true);
133-
});
134120

135-
it("I should be able to parse jpath using `obj< Cjson >.json.parse(\"Valid.JPATH\")`", () => {
121+
it("I should be able to replace a value in JSON context using replace()", () => {
136122
var cjson = new Cjson(cjsonfilePath);
137-
cjson.deserialize();
138-
139-
var value = cjson.json.parse("$.source.pure.quiz.sport.q1.question");
140-
assert.equal(value, "Which one is correct team name in NBA?");
141-
});
123+
cjson = cjson.replace("$.source.pure.quiz.sport.q1.answer", "Los Angeles Kings");
142124

143-
it("I should be able to parse full json using `obj< Cjson >.json.parse()`", () => {
144-
var cjson = new Cjson(cjsonfilePath);
145-
cjson.deserialize();
125+
assert.equal(cjson.json.parse("$.source.pure.quiz.sport.q1.answer"), "Los Angeles Kings");
126+
});
146127

147-
var value = JSON.stringify(cjson.json.parse());
148-
assert.equal(value, JSON.stringify(cjson.deserialize()));
128+
it("I should be able to inject null value during runtime", () => {
129+
var cjson = new Cjson(VariableInjection);
130+
cjson = cjson.inject({
131+
"fruit": null
132+
});
133+
assert.equal(cjson.deserialize().target.fruit, null, "Null value injection is successfull");
149134
});
150135

151-
it("I should be able to replace a value using replace()", () => {
152-
var cjson = new Cjson(cjsonfilePath);
153-
cjson.deserialize();
154-
var jPath = "$.source.pure.quiz.sport.q1.question"
155-
cjson = cjson.replace(jPath, "New question");
156-
assert.equal(cjson.json.parse(jPath), "New question");
136+
it("I should be able to inject array", () => {
137+
var cjson = new Cjson(VariableInjection);
138+
cjson = cjson.inject({
139+
"fruit": ["Orange", "Apple", "Banana"]
140+
});
141+
assert.equal(cjson.deserialize().target.fruit.length, 3, "Null value injection is successfull");
157142
});
158143
});

npm/spec/tests/jsonNativeTests.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const assert = require('assert');
2+
const fs = require('fs');
3+
const path = require('path');
4+
const Cjson = require("../../out/cjson").Cjson;
5+
const jasmine = require("jasmine");
6+
7+
const basePath = path.join(__dirname, "..", "..", "..", "tests", "test-files");
8+
/** Path to target.cjson */
9+
const cjsonfilePath = path.join(basePath, "target.cjson");
10+
/** Path to source.json */
11+
const jsonfilePath = path.join(basePath, "source.json");
12+
/** Path to pure.json */
13+
const pureJsonfilePath = path.join(basePath, "pure.json");
14+
/** Path to relativeTargetCjson.json */
15+
const relativeTargetCjson = path.join(basePath, "targetRelativeCalls.cjson");
16+
/** Path to relativeTargetCjson.json */
17+
const VariableInjection = path.join(basePath, "VariableInjection.cjson");
18+
19+
/**
20+
* Tests related to native JSON files
21+
*/
22+
describe("JSON Test 2", () => {
23+
24+
it("I should be able to use isContentJson()", () => {
25+
var cjson = new Cjson(pureJsonfilePath);
26+
assert.equal(cjson.isContentJson(), true);
27+
});
28+
29+
it("I should be able to parse jpath using `obj< Cjson >.json.parse(\"Valid.JPATH\")`", () => {
30+
var cjson = new Cjson(cjsonfilePath);
31+
cjson.deserialize();
32+
33+
var value = cjson.json.parse("$.source.pure.quiz.sport.q1.question");
34+
assert.equal(value, "Which one is correct team name in NBA?");
35+
});
36+
37+
it("I should be able to parse full json using `obj< Cjson >.json.parse()`", () => {
38+
var cjson = new Cjson(cjsonfilePath);
39+
40+
var value = JSON.stringify(cjson.json.parse());
41+
var actual = cjson.deserializeAsString();
42+
assert.equal(value, JSON.stringify(JSON.parse(actual)));
43+
});
44+
45+
it("I should be able to replace a value using replace()", () => {
46+
var cjson = new Cjson(cjsonfilePath);
47+
cjson.deserialize();
48+
var jPath = "$.source.pure.quiz.sport.q1.question"
49+
cjson = cjson.replace(jPath, "New question");
50+
assert.equal(cjson.json.parse(jPath), "New question");
51+
});
52+
53+
it("I should be able to get all keys after deserialization", () => {
54+
var cjson = new Cjson(VariableInjection);
55+
cjson.deserialize();
56+
57+
assert.notEqual(cjson.json.getAllKeys().length, 0, "getAllKeys() test passed");
58+
})
59+
60+
it("I should be able to get all values after deserialization", () => {
61+
var cjson = new Cjson(VariableInjection);
62+
cjson.deserialize();
63+
64+
assert.notEqual(cjson.json.getAllValues().length, 0, "getAllValues() test passed");
65+
})
66+
});

0 commit comments

Comments
 (0)