@@ -17,82 +17,6 @@ const op = marklogic.planBuilder;
1717
1818describe ( 'Nodejs Optic nodes json constructor test' , function ( ) {
1919
20- it ( 'TEST 1 - construct json from literals' , function ( done ) {
21- const plan1 =
22- op . fromLiterals ( [
23- { rowId : 1 , colorId : 1 , desc : 'ball' } ,
24- { rowId : 2 , colorId : 2 , desc : 'square' } ,
25- { rowId : 3 , colorId : 1 , desc : 'box' } ,
26- { rowId : 4 , colorId : 1 , desc : 'hoop' } ,
27- { rowId : 5 , colorId : 5 , desc : 'circle' }
28- ] , 'myItem' ) ;
29- const plan2 =
30- op . fromLiterals ( [
31- { colorId : 1 , colorDesc : 'red' } ,
32- { colorId : 2 , colorDesc : 'blue' } ,
33- { colorId : 3 , colorDesc : 'black' } ,
34- { colorId : 4 , colorDesc : 'yellow' }
35- ] , 'myColor' ) ;
36-
37- const output =
38- plan1 . joinInner ( plan2 , op . on ( op . viewCol ( 'myItem' , 'colorId' ) , op . viewCol ( 'myColor' , 'colorId' ) ) )
39- . select ( [
40- 'rowId' ,
41- op . as ( 'myJSON' , op . jsonDocument ( op . jsonObject ( [
42- op . prop ( 'str' , op . jsonString ( op . col ( 'desc' ) ) ) ,
43- op . prop ( 'strFunc' , op . jsonString ( op . fn . stringToCodepoints ( op . col ( 'desc' ) ) ) ) ,
44- op . prop ( 'mathFunc' , op . jsonNumber ( op . math . sqrt ( op . col ( 'rowId' ) ) ) ) ,
45- op . prop ( 'upper' , op . jsonString ( op . fn . upperCase ( op . viewCol ( 'myItem' , 'desc' ) ) ) ) ,
46- op . prop ( 'num' , op . jsonNumber ( op . col ( 'rowId' ) ) ) ,
47- op . prop ( 'bool' , op . jsonBoolean ( op . isDefined ( op . col ( 'rowId' ) ) ) ) ,
48- op . prop ( 'null' , op . jsonNull ( ) ) ,
49- op . prop ( 'array' , op . jsonArray ( [ op . jsonString ( op . col ( 'desc' ) ) , op . jsonNumber ( op . col ( 'rowId' ) ) ] ) )
50- ] ) ) ) ,
51- op . as ( 'node' , op . jsonString ( op . col ( 'desc' ) ) ) ,
52- op . as ( 'kind' , op . xdmp . nodeKind ( op . col ( 'node' ) ) ) ,
53- op . as ( 'xml' ,
54- op . xmlDocument (
55- op . xmlElement (
56- 'root' ,
57- op . xmlAttribute ( 'attrA' , op . col ( 'rowId' ) ) ,
58- [
59- op . xmlElement ( 'elemA' , null , op . viewCol ( 'myColor' , 'colorDesc' ) ) ,
60- op . xmlComment ( op . fn . concat ( 'this is a comment for ' , op . col ( 'desc' ) ) ) ,
61- op . xmlElement ( 'elemB' , null , op . col ( 'desc' ) )
62- ]
63- )
64- )
65- )
66- ] )
67- . orderBy ( 'rowId' ) ;
68- db . rows . query ( output , { format : 'json' , structure : 'object' , columnTypes : 'header' } )
69- . then ( function ( output ) {
70- //console.log(JSON.stringify(output, null, 2));
71- expect ( output . columns [ 1 ] . name ) . to . equal ( 'myJSON' ) ;
72- expect ( output . columns [ 1 ] . type ) . to . equal ( 'object' ) ;
73- expect ( output . columns [ 2 ] . name ) . to . equal ( 'node' ) ;
74- expect ( output . columns [ 2 ] . type ) . to . equal ( 'text' ) ;
75- expect ( output . columns [ 4 ] . name ) . to . equal ( 'xml' ) ;
76- expect ( output . columns [ 4 ] . type ) . to . equal ( 'element' ) ;
77- expect ( output . rows . length ) . to . equal ( 4 ) ;
78- expect ( output . rows [ 0 ] [ 'myItem.rowId' ] ) . to . equal ( 1 ) ;
79- expect ( output . rows [ 0 ] . myJSON . str ) . to . equal ( 'ball' ) ;
80- expect ( output . rows [ 0 ] . myJSON . upper ) . to . equal ( 'BALL' ) ;
81- expect ( output . rows [ 0 ] . myJSON . num ) . to . equal ( 1 ) ;
82- expect ( output . rows [ 0 ] . myJSON . bool ) . to . equal ( true ) ;
83- expect ( output . rows [ 0 ] . myJSON . null ) . to . equal ( null ) ;
84- expect ( output . rows [ 0 ] . myJSON . array . length ) . to . equal ( 2 ) ;
85- expect ( output . rows [ 0 ] . myJSON . array [ 0 ] ) . to . equal ( 'ball' ) ;
86- expect ( output . rows [ 0 ] . kind ) . to . equal ( 'text' ) ;
87- expect ( output . rows [ 1 ] . myJSON . strFunc ) . to . equal ( '115 113 117 97 114 101' ) ;
88- expect ( output . rows [ 1 ] . myJSON . mathFunc ) . to . equal ( 1.4142135623731 ) ;
89- expect ( output . rows [ 0 ] . xml ) . to . equal ( '<root attrA="1"><elemA>red</elemA><!--this is a comment for ball--><elemB>ball</elemB></root>' ) ;
90- expect ( output . rows [ 3 ] [ 'myItem.rowId' ] ) . to . equal ( 4 ) ;
91- expect ( output . rows [ 3 ] . xml ) . to . equal ( '<root attrA="4"><elemA>red</elemA><!--this is a comment for hoop--><elemB>hoop</elemB></root>' ) ;
92- done ( ) ;
93- } , done ) ;
94- } ) ;
95-
9620 it ( 'TEST 2 - construct json from views' , function ( done ) {
9721 const plan1 =
9822 op . fromView ( 'opticFunctionalTest2' , 'detail' )
0 commit comments