Added messagepack tests but they don't work

and i'm too burnt out to figure out why
This commit is contained in:
Matt C 2018-08-20 00:20:04 +01:00
parent 0c06e64051
commit 821dd9c48c
2 changed files with 71 additions and 11 deletions

View file

@ -36,7 +36,7 @@ class FromMessagePack extends Operation {
try { try {
return notepack.decode(input); return notepack.decode(input);
} catch (err) { } catch (err) {
throw new OperationError(`Could not decode MessagePack to JSON:MessagePack ${err}`); throw new OperationError(`Could not decode MessagePack to JSON: ${err}`);
} }
} }

View file

@ -9,7 +9,7 @@
*/ */
import TestRegister from "../../TestRegister"; import TestRegister from "../../TestRegister";
const JPATH_TEST_DATA = { const JSON_TEST_DATA = {
"store": { "store": {
"book": [{ "book": [{
"category": "reference", "category": "reference",
@ -184,7 +184,7 @@ TestRegister.addTests([
}, },
{ {
name: "JPath Expression: Empty expression", name: "JPath Expression: Empty expression",
input: JSON.stringify(JPATH_TEST_DATA), input: JSON.stringify(JSON_TEST_DATA),
expectedOutput: "Invalid JPath expression: we need a path", expectedOutput: "Invalid JPath expression: we need a path",
recipeConfig: [ recipeConfig: [
{ {
@ -195,7 +195,7 @@ TestRegister.addTests([
}, },
{ {
name: "JPath Expression: Fetch of values from specific object", name: "JPath Expression: Fetch of values from specific object",
input: JSON.stringify(JPATH_TEST_DATA), input: JSON.stringify(JSON_TEST_DATA),
expectedOutput: [ expectedOutput: [
"\"Nigel Rees\"", "\"Nigel Rees\"",
"\"Evelyn Waugh\"", "\"Evelyn Waugh\"",
@ -211,7 +211,7 @@ TestRegister.addTests([
}, },
{ {
name: "JPath Expression: Fetch of all values with matching key", name: "JPath Expression: Fetch of all values with matching key",
input: JSON.stringify(JPATH_TEST_DATA), input: JSON.stringify(JSON_TEST_DATA),
expectedOutput: [ expectedOutput: [
"\"Sayings of the Century\"", "\"Sayings of the Century\"",
"\"Sword of Honour\"", "\"Sword of Honour\"",
@ -229,7 +229,7 @@ TestRegister.addTests([
}, },
{ {
name: "JPath Expression: All data in object", name: "JPath Expression: All data in object",
input: JSON.stringify(JPATH_TEST_DATA), input: JSON.stringify(JSON_TEST_DATA),
expectedOutput: [ expectedOutput: [
"[{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":8.95},{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":12.99},{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99},{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":22.99}]", "[{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":8.95},{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":12.99},{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99},{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":22.99}]",
"{\"color\":\"red\",\"price\":19.95}", "{\"color\":\"red\",\"price\":19.95}",
@ -244,7 +244,7 @@ TestRegister.addTests([
}, },
{ {
name: "JPath Expression: Last element in array", name: "JPath Expression: Last element in array",
input: JSON.stringify(JPATH_TEST_DATA), input: JSON.stringify(JSON_TEST_DATA),
expectedOutput: "{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":22.99}", expectedOutput: "{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":22.99}",
recipeConfig: [ recipeConfig: [
{ {
@ -255,7 +255,7 @@ TestRegister.addTests([
}, },
{ {
name: "JPath Expression: First 2 elements in array", name: "JPath Expression: First 2 elements in array",
input: JSON.stringify(JPATH_TEST_DATA), input: JSON.stringify(JSON_TEST_DATA),
expectedOutput: [ expectedOutput: [
"{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":8.95}", "{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":8.95}",
"{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":12.99}" "{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":12.99}"
@ -269,7 +269,7 @@ TestRegister.addTests([
}, },
{ {
name: "JPath Expression: All elements in array with property", name: "JPath Expression: All elements in array with property",
input: JSON.stringify(JPATH_TEST_DATA), input: JSON.stringify(JSON_TEST_DATA),
expectedOutput: [ expectedOutput: [
"{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99}", "{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99}",
"{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":22.99}" "{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":22.99}"
@ -283,7 +283,7 @@ TestRegister.addTests([
}, },
{ {
name: "JPath Expression: All elements in array which meet condition", name: "JPath Expression: All elements in array which meet condition",
input: JSON.stringify(JPATH_TEST_DATA), input: JSON.stringify(JSON_TEST_DATA),
expectedOutput: [ expectedOutput: [
"{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":12.99}", "{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":12.99}",
"{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99}", "{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99}",
@ -298,7 +298,7 @@ TestRegister.addTests([
}, },
{ {
name: "JPath Expression: All elements in object", name: "JPath Expression: All elements in object",
input: JSON.stringify(JPATH_TEST_DATA), input: JSON.stringify(JSON_TEST_DATA),
expectedOutput: [ expectedOutput: [
"{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":8.95}", "{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":8.95}",
"{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99}" "{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99}"
@ -331,5 +331,65 @@ TestRegister.addTests([
"args": ["/div/p[@class=\"a\"]", "\\n"] "args": ["/div/p[@class=\"a\"]", "\\n"]
} }
] ]
},
{
name: "To MessagePack: no content",
input: "",
expectedError: true,
recipeConfig: [
{
"op": "To MessagePack",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
name: "From MessagePack: no content",
input: "",
expectedOutput: "Could not decode MessagePack to JSON: RangeError: offset is outside the bounds of the DataView",
recipeConfig: [
{
"op": "From Hex",
"args": ["Space"]
},
{
"op": "From MessagePack",
"args": []
}
]
},
{
name: "To MessagePack: valid json",
input: JSON.stringify(JSON_TEST_DATA),
expectedOutput: "81 a5 73 74 6f 72 65 83 a4 62 6f 6f 6b 94 84 a8 63 61 74 65 67 6f 72 79 a9 72 65 66 65 72 65 6e 63 65 a6 61 75 74 68 6f 72 aa 4e 69 67 65 6c 20 52 65 65 73 a5 74 69 74 6c 65 b6 53 61 79 69 6e 67 73 20 6f 66 20 74 68 65 20 43 65 6e 74 75 72 79 a5 70 72 69 63 65 cb 40 21 e6 66 66 66 66 66 84 a8 63 61 74 65 67 6f 72 79 a7 66 69 63 74 69 6f 6e a6 61 75 74 68 6f 72 ac 45 76 65 6c 79 6e 20 57 61 75 67 68 a5 74 69 74 6c 65 af 53 77 6f 72 64 20 6f 66 20 48 6f 6e 6f 75 72 a5 70 72 69 63 65 cb 40 29 fa e1 47 ae 14 7b 85 a8 63 61 74 65 67 6f 72 79 a7 66 69 63 74 69 6f 6e a6 61 75 74 68 6f 72 af 48 65 72 6d 61 6e 20 4d 65 6c 76 69 6c 6c 65 a5 74 69 74 6c 65 a9 4d 6f 62 79 20 44 69 63 6b a4 69 73 62 6e ad 30 2d 35 35 33 2d 32 31 33 31 31 2d 33 a5 70 72 69 63 65 cb 40 21 fa e1 47 ae 14 7b 85 a8 63 61 74 65 67 6f 72 79 a7 66 69 63 74 69 6f 6e a6 61 75 74 68 6f 72 b0 4a 2e 20 52 2e 20 52 2e 20 54 6f 6c 6b 69 65 6e a5 74 69 74 6c 65 b5 54 68 65 20 4c 6f 72 64 20 6f 66 20 74 68 65 20 52 69 6e 67 73 a4 69 73 62 6e ad 30 2d 33 39 35 2d 31 39 33 39 35 2d 38 a5 70 72 69 63 65 cb 40 36 fd 70 a3 d7 0a 3d a7 62 69 63 79 63 6c 65 82 a5 63 6f 6c 6f 72 a3 72 65 64 a5 70 72 69 63 65 cb 40 33 f3 33 33 33 33 33 a9 6e 65 77 73 70 61 70 65 72 92 83 a6 66 6f 72 6d 61 74 aa 62 72 6f 61 64 73 68 65 65 74 a5 74 69 74 6c 65 af 46 69 6e 61 6e 63 69 61 6c 20 54 69 6d 65 73 a5 70 72 69 63 65 cb 40 06 00 00 00 00 00 00 83 a6 66 6f 72 6d 61 74 a7 74 61 62 6c 6f 69 64 a5 74 69 74 6c 65 ac 54 68 65 20 47 75 61 72 64 69 61 6e a5 70 72 69 63 65 02",
recipeConfig: [
{
"op": "To MessagePack",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
name: "From MessagePack: valid msgpack",
input: "81 a5 73 74 6f 72 65 83 a4 62 6f 6f 6b 94 84 a8 63 61 74 65 67 6f 72 79 a9 72 65 66 65 72 65 6e 63 65 a6 61 75 74 68 6f 72 aa 4e 69 67 65 6c 20 52 65 65 73 a5 74 69 74 6c 65 b6 53 61 79 69 6e 67 73 20 6f 66 20 74 68 65 20 43 65 6e 74 75 72 79 a5 70 72 69 63 65 cb 40 21 e6 66 66 66 66 66 84 a8 63 61 74 65 67 6f 72 79 a7 66 69 63 74 69 6f 6e a6 61 75 74 68 6f 72 ac 45 76 65 6c 79 6e 20 57 61 75 67 68 a5 74 69 74 6c 65 af 53 77 6f 72 64 20 6f 66 20 48 6f 6e 6f 75 72 a5 70 72 69 63 65 cb 40 29 fa e1 47 ae 14 7b 85 a8 63 61 74 65 67 6f 72 79 a7 66 69 63 74 69 6f 6e a6 61 75 74 68 6f 72 af 48 65 72 6d 61 6e 20 4d 65 6c 76 69 6c 6c 65 a5 74 69 74 6c 65 a9 4d 6f 62 79 20 44 69 63 6b a4 69 73 62 6e ad 30 2d 35 35 33 2d 32 31 33 31 31 2d 33 a5 70 72 69 63 65 cb 40 21 fa e1 47 ae 14 7b 85 a8 63 61 74 65 67 6f 72 79 a7 66 69 63 74 69 6f 6e a6 61 75 74 68 6f 72 b0 4a 2e 20 52 2e 20 52 2e 20 54 6f 6c 6b 69 65 6e a5 74 69 74 6c 65 b5 54 68 65 20 4c 6f 72 64 20 6f 66 20 74 68 65 20 52 69 6e 67 73 a4 69 73 62 6e ad 30 2d 33 39 35 2d 31 39 33 39 35 2d 38 a5 70 72 69 63 65 cb 40 36 fd 70 a3 d7 0a 3d a7 62 69 63 79 63 6c 65 82 a5 63 6f 6c 6f 72 a3 72 65 64 a5 70 72 69 63 65 cb 40 33 f3 33 33 33 33 33 a9 6e 65 77 73 70 61 70 65 72 92 83 a6 66 6f 72 6d 61 74 aa 62 72 6f 61 64 73 68 65 65 74 a5 74 69 74 6c 65 af 46 69 6e 61 6e 63 69 61 6c 20 54 69 6d 65 73 a5 70 72 69 63 65 cb 40 06 00 00 00 00 00 00 83 a6 66 6f 72 6d 61 74 a7 74 61 62 6c 6f 69 64 a5 74 69 74 6c 65 ac 54 68 65 20 47 75 61 72 64 69 61 6e a5 70 72 69 63 65 02",
expectedOutput: JSON.stringify(JSON_TEST_DATA),
recipeConfig: [
{
"op": "From Hex",
"args": ["Space"]
},
{
"op": "From MessagePack",
"args": []
}
]
} }
]); ]);