-
Notifications
You must be signed in to change notification settings - Fork 6
/
VPRJTGDS.m
2242 lines (2242 loc) · 107 KB
/
VPRJTGDS.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
VPRJTGDS ;KRM/CJE -- Unit Tests for CRUD operations for Generic Data Stores
;
; Endpoints tested
; GET <store>/{uid} GET^VPRJGDS
; PUT <store/{uid} SET^VPRJGDS
; DELETE <store>/{uid} DEL^VPRJGDS
; GET <store> INFO^VPRJGDS
; POST <store> SET^VPRJGDS
; POST <store>/index CINDEX^VPRJGDS
; GET <store>/index/{indexName} INDEX^VPRJGDS
; POST <store>/template CTEMPLATE^VPRJGDS
; GET <store>/index/{indexName}/{template} INDEX^VPRJGDS
; GET <store>/lock
; PUT <store>/lock/{uid}
; DELETE <store>/lock/{uid}
; DELETE <store> CLR^VPRJGDS
Q
STARTUP ; Run once before all tests
; ensure that we have a store for the unit tests
N HTTPREQ,HTTPERR
; OSE/SMH: Must kill existing data in store
K ^VPRJUT
K ^VPRJUTX
K ^VPRJUTJ
K ^VPRCONFIG("store","ut")
D SHUTDOWN
D ADDSTORE^VPRJCONFIG("ut")
K ^TMP("HTTPERR",$J)
Q
SHUTDOWN ; Run once after all tests
; DELETE database test will remove the store from the database and route map
K HTTPREQ
K ^VPRMETA("collection","ut"),^VPRMETA("index","gdsutest"),^VPRMETA("index","gdsutest2"),^VPRMETA("index","gdsutest3")
K ^VPRMETA("template","gdsutest"),^VPRMETA("template","gdsutest2"),^VPRMETA("template","gdsutest3")
Q
TEARDOWN ; Run after each test
K ^TMP($J)
K ^TMP("HTTPERR",$J)
Q
ASSERT(EXPECT,ACTUAL,MSG) ; for convenience
D EQ^VPRJT(EXPECT,ACTUAL,$G(MSG))
Q
;
SAMPLEDATA(ROLES,UID) ; Setup Session Data JSON for set
; special case to remove uid attribute from JSON
Q:$G(UID)="null" "{""createDate"": {""date"": ""20000101120000000""},""lastLogin"": {""date"": ""20130526050000000""},""roles"": ["_ROLES_"]}"
Q "{""createDate"": {""date"": ""20000101120000000""},""lastLogin"": {""date"": ""20130526050000000""},""roles"": ["_ROLES_"],""uid"": """_UID_"""}"
;
SAMPLEINDEX(NAME,FIELDS,SORT,TYPE) ; Setup Index data JSON for Create Index
Q:$G(NAME)="null" "{""fields"": """_FIELDS_""",""sort"": """_SORT_""",""type"": """_TYPE_"""}"
Q:$G(FIELDS)="null" "{""indexName"": """_NAME_""",""sort"": """_SORT_""",""type"": """_TYPE_"""}"
Q:$G(SORT)="null" "{""indexName"": """_NAME_""",""fields"": """_FIELDS_""",""type"": """_TYPE_"""}"
Q:$G(TYPE)="null" "{""indexName"": """_NAME_""",""fields"": """_FIELDS_""",""sort"": """_SORT_"""}"
Q "{""indexName"": """_NAME_""",""fields"": """_FIELDS_""",""sort"": """_SORT_""",""type"": """_TYPE_"""}"
;
; Setup Template data JSON for Create Template
SAMPLETEMPLATE(NAME,DIRECTIVES,FIELDS)
Q:$G(NAME)="null" "{""fields"": """_FIELDS_""",""directives"": """_DIRECTIVES_"""}"
Q:$G(FIELDS)="null" "{""name"": """_NAME_""",""directives"": """_DIRECTIVES_"""}"
Q:$G(DIRECTIVES)="null" "{""name"": """_NAME_""",""fields"": """_FIELDS_"""}"
Q "{""name"": """_NAME_""",""fields"": """_FIELDS_""",""directives"": """_DIRECTIVES_"""}"
;
; Parse return type=3 responses (paged responses)
; @param {array} RAW - (passed by reference) RAW response
; @param {array} PARSED - (passed by reference) M array representation of JSON
; @param {string} PARSE - boolean to control parsing of data
PARSE(RAW,PARSED,PARSE)
; Assumes HTTPREQ is newed by caller
;
; QUIT early if there is nothing to do
I '$D(RAW) QUIT
;
N START,LIMIT,SIZE,PREAMBLE,RSP,DATA,I,J,RETCNTS
S PARSE=$G(PARSE,1)
; Setup paging info for PAGE^VPRJRUT
S HTTPREQ("paging")=$G(ARGS("start"),0)_":"_$G(ARGS("limit"),999999)
S START=$P(HTTPREQ("paging"),":"),LIMIT=$P(HTTPREQ("paging"),":",2),STARTID=$G(RAW("startid"))
S RETCNTS=$S($G(RAW("returncounts"))="true":1,1:0)
I STARTID'="" F I=1:1:$G(@RAW@("total")) I $D(@RAW@("data",I,STARTID)) S START=START+I Q
D PAGE^VPRJRUT(.RAW,START,LIMIT,.SIZE,.PREAMBLE,RETCNTS)
; Emulate RESPOND^VPRJRSP to get a real JSON response
S DATA(0)=PREAMBLE
F I=START:1:(START+LIMIT-1) Q:'$D(@RAW@($J,I)) D
. I I>START S DATA(I)="," ; separate items with a comma
. S J="" F S J=$O(@RAW@($J,I,J)) Q:'J S DATA(I)=$G(DATA(I))_@RAW@($J,I,J)
S DATA(I)=$G(DATA(I))_"]}"
D:$D(DATA)&PARSE DECODE^VPRJSON("DATA","PARSED","ERR")
D:PARSE ASSERT(0,$D(ERR),"ERROR Decoding JSON (IN PARSE^VPRJTGDS)")
M:'PARSE PARSED=DATA
QUIT
;
; Begin Test Suite
;
SETNOSTORE ;; @TEST Error code is set if no store in HTTPREQ
N RETURN,BODY,ARG,HTTPERR
; Create sample JSON
S BODY(1)=$$SAMPLEDATA("""ehmp-proxy""","urn:va:user:SITE:10000000265")
; Send it to the URL
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUT("urn:va:user:SITE:10000000265")),"Data stored when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
SETNOGLOBAL ;; @TEST Error code is set if no global is in VPRCONFIG
N RETURN,BODY,ARG,HTTPERR,GLOBALSAVE
; Create sample JSON
S BODY(1)=$$SAMPLEDATA("""ehmp-proxy""","urn:va:user:SITE:10000000265")
; Kill off the global area for the test
S GLOBALSAVE=^VPRCONFIG("store","ut","global")
K ^VPRCONFIG("store","ut","global")
; Send it to the URL
S HTTPREQ("store")="ut"
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRCONFIG("store","ut","global")),"VPRCONFIG global storage area exists and it shouldn't")
D ASSERT(0,$D(^VPRJUT("urn:va:user:SITE:10000000265")),"Data stored when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Restore the global area for the rest of the tests
S ^VPRCONFIG("store","ut","global")=GLOBALSAVE
Q
;
SETNOJSON ;; @TEST Error code is set if no JSON in body
N RETURN,BODY,ARG,HTTPERR,GLOBALSAVE
; Send it to the URL
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUT),"Data stored when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(255,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 255 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
SETJSONERR ;; @TEST Error code is set if JSON is mangled in PUT/POST
N RETURN,BODY,ARG,HTTPERR
; Create bad JSON
S BODY(1)=$$SAMPLEDATA("""ehmp-proxy""","urn:va:user:SITE:10000000265")
S BODY(1)=BODY(1)_":"
; Send it to the URL
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUT("urn:va:user:SITE:10000000265")),"Data stored when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(202,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 202 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
SETNOUID ;; @TEST POST with no UID
N RETURN,BODY,ARG,HTTPERR
; Try with an empty string for the uid field
S BODY(1)=$$SAMPLEDATA("""ehmp-proxy""","")
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(10,$D(^VPRJUT("urn:va:ut:"_$G(^VPRJUT(0)))),"Data NOT stored when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:"_$G(^VPRJUT(0)),$G(^VPRJUT("urn:va:ut:"_$G(^VPRJUT(0)),"uid")),"The uid field was not stored correctly")
D ASSERT("20130526050000000",$G(^VPRJUT("urn:va:ut:"_$G(^VPRJUT(0)),"lastLogin","date")),"The lastLogin.date attribute was not stored correctly")
D ASSERT($G(RETURN),"/ut/"_"urn:va:ut:"_$G(^VPRJUT(0)),"The UID wasn't returned")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K BODY,RETURN,ARG
; Try with a non existent uid field
; "null" is a magic string to the SAMPLEDATA generator to prevent the uid field from even being passed
S BODY(1)=$$SAMPLEDATA("""ehmp-proxy""","null")
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(10,$D(^VPRJUT("urn:va:ut:"_$G(^VPRJUT(0)))),"Data NOT stored when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:"_$G(^VPRJUT(0)),$G(^VPRJUT("urn:va:ut:"_$G(^VPRJUT(0)),"uid")),"The uid field was not stored correctly")
D ASSERT("20130526050000000",$G(^VPRJUT("urn:va:ut:"_$G(^VPRJUT(0)),"lastLogin","date")),"The lastLogin.date attribute was not stored correctly")
D ASSERT($G(RETURN),"/ut/"_"urn:va:ut:"_$G(^VPRJUT(0)),"The UID wasn't returned")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
SET1 ;; @TEST PUT with UID
N RETURN,BODY,ARG,HTTPERR
S BODY(1)=$$SAMPLEDATA("""ehmp-proxy""","urn:va:ut:23")
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(10,$D(^VPRJUT("urn:va:ut:23")),"Data NOT stored when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:23",$G(^VPRJUT("urn:va:ut:23","uid")),"The uid field was not stored correctly")
D ASSERT("20130526050000000",$G(^VPRJUT("urn:va:ut:23","lastLogin","date")),"The lastLogin.date attribute was not stored correctly")
D ASSERT($G(RETURN),"/ut/"_"urn:va:ut:23","The UID wasn't returned")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
SET2 ;; @TEST PUTing 2 items with UID
N RETURN,BODY,ARG,HTTPERR
S BODY(1)=$$SAMPLEDATA("""ehmp-proxy""","urn:va:ut:23")
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(10,$D(^VPRJUT("urn:va:ut:23")),"Data NOT stored when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:23",$G(^VPRJUT("urn:va:ut:23","uid")),"The uid field was not stored correctly")
D ASSERT("20130526050000000",$G(^VPRJUT("urn:va:ut:23","lastLogin","date")),"The lastLogin.date attribute was not stored correctly")
D ASSERT("ehmp-proxy",$G(^VPRJUT("urn:va:ut:23","roles",1)),"The roles array (1) was not stored correctly")
D ASSERT($G(RETURN),"/ut/"_"urn:va:ut:23","The UID wasn't returned")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K RETURN,BODY,ARG
; Update the record
S BODY(1)=$$SAMPLEDATA("""ehmp-proxy"",""ehmp-test""","urn:va:ut:23")
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(10,$D(^VPRJUT("urn:va:ut:23")),"Data NOT stored when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:23",$G(^VPRJUT("urn:va:ut:23","uid")),"The uid field was not stored correctly")
D ASSERT("20130526050000000",$G(^VPRJUT("urn:va:ut:23","lastLogin","date")),"The lastLogin.date attribute was not stored correctly")
D ASSERT("ehmp-proxy",$G(^VPRJUT("urn:va:ut:23","roles",1)),"The roles array (1) was not stored correctly")
D ASSERT("ehmp-test",$G(^VPRJUT("urn:va:ut:23","roles",2)),"The roles array (2) was not stored correctly")
D ASSERT($G(RETURN),"/ut/"_"urn:va:ut:23","The UID wasn't returned")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K RETURN,BODY,ARG
; Add a second one
S BODY(1)=$$SAMPLEDATA("""ehmp-proxy"",""ehmp-test""","urn:va:ut:5")
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(10,$D(^VPRJUT("urn:va:ut:5")),"Data NOT stored when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:5",$G(^VPRJUT("urn:va:ut:5","uid")),"The uid field was not stored correctly")
D ASSERT("20130526050000000",$G(^VPRJUT("urn:va:ut:5","lastLogin","date")),"The lastLogin.date attribute was not stored correctly")
D ASSERT("ehmp-proxy",$G(^VPRJUT("urn:va:ut:5","roles",1)),"The roles array (1) was not stored correctly")
D ASSERT("ehmp-test",$G(^VPRJUT("urn:va:ut:5","roles",2)),"The roles array (2) was not stored correctly")
D ASSERT($G(RETURN),"/ut/"_"urn:va:ut:5","The UID wasn't returned")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
SETCOLLISION ;; cause a collision and ensure everything works as intended
Q
;
;
DELNOSTORE ;; @TEST Error code is set if no store in HTTPREQ
N DATA,OBJECT,ERR,ARGS,HTTPERR
; Send it to the URL
K HTTPREQ("store")
D DEL^VPRJGDS(.DATA,.ARGS)
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
DELNOGLOBAL ;; @TEST Error code is set if no global is in VPRCONFIG
N DATA,OBJECT,ERR,ARGS,HTTPERR,GLOBALSAVE
; Kill off the global area for the test
S GLOBALSAVE=^VPRCONFIG("store","ut","global")
K ^VPRCONFIG("store","ut","global")
; Send it to the URL
S HTTPREQ("store")="ut"
D DEL^VPRJGDS(.DATA,.ARGS)
D ASSERT(0,$D(^VPRCONFIG("store","ut","global")),"VPRCONFIG global storage area exists and it shouldn't")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Restore the global area for the rest of the tests
S ^VPRCONFIG("store","ut","global")=GLOBALSAVE
Q
;
DELIDERR ;; @TEST Error code is set if no uid
N DATA,OBJECT,ERR,ARGS,HTTPERR
; Try with a non existent uid
D DEL^VPRJGDS(.DATA,.ARGS)
D ASSERT(0,$D(DATA),"No DATA should be returned")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(111,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 111 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup vars
K DATA,OBJECT,ERR,ARGS
; Try with a blank uid
S ARGS("uid")=""
D DEL^VPRJGDS(.DATA,.ARGS)
D ASSERT(0,$D(DATA),"No DATA should be returned")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(111,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 111 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
DEL ;; @TEST Delete Data
N RETURN,BODY,ARG,DATA,ARGS,OBJECT,ERR,HTTPERR
; delete it
S ARGS("uid")="urn:va:ut:23"
D DEL^VPRJGDS(.DATA,.ARGS)
D DECODE^VPRJSON("DATA","OBJECT","ERR")
D ASSERT(0,$D(^VPRJUT("urn:va:ut:23")),"Data exists and it should not")
D ASSERT(0,$D(^VPRJUTJ("JSON","urn:va:ut:23")),"Data exists and it should not")
D ASSERT(0,$D(^VPRJUTJ("TEMPLATE","urn:va:ut:23")),"Data exists and it should not")
D ASSERT("{""ok"": true}",$G(DATA),"DATA returned from a DELETE call (should not happen)")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
;
INFONOSTORE ;; @TEST Error code is set if no store in HTTPREQ
N DATA,OBJECT,ERR,ARGS,HTTPERR
; Send it to the URL
K HTTPREQ("store")
D INFO^VPRJGDS(.DATA,.ARGS)
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
INFONOGLOBAL ;; @TEST Error code is set if no global is in VPRCONFIG
N DATA,OBJECT,ERR,ARGS,HTTPERR,GLOBALSAVE
; Kill off the global area for the test
S GLOBALSAVE=^VPRCONFIG("store","ut","global")
K ^VPRCONFIG("store","ut","global")
; Send it to the URL
S HTTPREQ("store")="ut"
D INFO^VPRJGDS(.DATA,.ARGS)
D ASSERT(0,$D(^VPRCONFIG("store","ut","global")),"VPRCONFIG global storage area exists and it shouldn't")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Restore the global area for the rest of the tests
S ^VPRCONFIG("store","ut","global")=GLOBALSAVE
Q
;
INFO ;; @TEST Get database information
N RETURN,BODY,ARG,DATA,ARGS,OBJECT,ERR,HTTPERR,COUNT
; GET the database info
D INFO^VPRJGDS(.DATA,.ARGS)
D DECODE^VPRJSON("DATA","OBJECT","ERR")
D ASSERT(0,$D(^TMP("HTTPERR",$J)),"An HTTP Error Occured")
D ASSERT(0,$D(ERR),"A JSON Decode Error Occured")
; only test the info that is supported
D ASSERT("ut",$G(OBJECT("db_name")),"The db_name doesn't match")
D ASSERT(1,$G(OBJECT("disk_format_version")),"The disk_format_version doesn't match")
D ASSERT(1,$D(OBJECT("doc_count")),"The doc_count doesn't match")
; save off the count so we can prove it works
S COUNT=$G(OBJECT("doc_count"))
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K OBJECT,DATA,ERR,ARGS
; Create more data to test count
S BODY(1)=$$SAMPLEDATA("""ehmp-proxy""","")
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(10,$D(^VPRJUT("urn:va:ut:"_$G(^VPRJUT(0)))),"Data NOT stored when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:"_$G(^VPRJUT(0)),$G(^VPRJUT("urn:va:ut:"_$G(^VPRJUT(0)),"uid")),"The uid field was not stored correctly")
D ASSERT("20130526050000000",$G(^VPRJUT("urn:va:ut:"_$G(^VPRJUT(0)),"lastLogin","date")),"The lastLogin.date attribute was not stored correctly")
D ASSERT($G(RETURN),"/ut/"_"urn:va:ut:"_$G(^VPRJUT(0)),"The UID wasn't returned")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K BODY,RETURN,ARG
; Now get the database info, we only have to test count
D INFO^VPRJGDS(.DATA,.ARGS)
D DECODE^VPRJSON("DATA","OBJECT","ERR")
D ASSERT(0,$D(^TMP("HTTPERR",$J)),"An HTTP Error Occured")
D ASSERT(0,$D(ERR),"A JSON Decode Error Occured")
; ensure the count is one more than last time
D ASSERT(COUNT+1,$G(OBJECT("doc_count")),"The doc_count doesn't match")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
;
GETNOSTORE ;; @TEST Error code is set if no store in HTTPREQ
N DATA,OBJECT,ERR,ARGS,HTTPERR
; Send it to the URL
K HTTPREQ("store")
D GET^VPRJGDS(.DATA,.ARGS)
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
GETNOGLOBAL ;; @TEST Error code is set if no global is in VPRCONFIG
N DATA,OBJECT,ERR,ARGS,HTTPERR,GLOBALSAVE
; Kill off the global area for the test
S GLOBALSAVE=^VPRCONFIG("store","ut","global")
K ^VPRCONFIG("store","ut","global")
; Send it to the URL
S HTTPREQ("store")="ut"
D GET^VPRJGDS(.DATA,.ARGS)
D ASSERT(0,$D(^VPRCONFIG("store","ut","global")),"VPRCONFIG global storage area exists and it shouldn't")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Restore the global area for the rest of the tests
S ^VPRCONFIG("store","ut","global")=GLOBALSAVE
Q
;
GETNOID ;; @TEST Data is returned if no uid passed
N DATA,ARGS,OBJECT,HTTPERR
; Try with a non existent uid attribute
D GET^VPRJGDS(.DATA,.ARGS)
;
; Parse the paged response
D PARSE(.DATA,.OBJECT)
;
D ASSERT(11,$D(DATA),"DATA should be returned")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:7",$G(OBJECT("items",4,"uid")),"The uid field was not returned correctly")
D ASSERT(0,$D(OBJECT("totalItems")),"totalItems attribute returned, and it should not be")
D ASSERT(0,$D(OBJECT("currentItemCount")),"currentItemCount attribute returned, and it should not be")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K DATA,OBJECT,ARGS,ERR
; Try with a null uid
S ARGS("uid")=""
D GET^VPRJGDS(.DATA,.ARGS)
;
; Parse the paged response
D PARSE(.DATA,.OBJECT)
;
D ASSERT(11,$D(DATA),"DATA should be returned")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:7",$G(OBJECT("items",4,"uid")),"The uid field was not returned correctly")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
;
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K DATA,OBJECT,ARGS,ERR
;
D GET^VPRJGDS(.DATA,.ARGS)
;
; Need to pass this in to DATA directly, because RESPOND^VPRJRSP is not run here
; Try with counts returned
S DATA("returncounts")="true"
;
; Parse the paged response
D PARSE(.DATA,.OBJECT)
;
D ASSERT(11,$D(DATA),"DATA should be returned")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:7",$G(OBJECT("items",4,"uid")),"The uid field was not returned correctly")
D ASSERT(1,$D(OBJECT("totalItems")),"totalItems attribute not returned")
D ASSERT($O(OBJECT("items",""),-1),$G(OBJECT("totalItems")),"totalItems attribute did not match total items returned")
D ASSERT(1,$D(OBJECT("currentItemCount")),"currentItemCount attribute not returned")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
QUIT
;
GETUIDUNK ;; @TEST Error code if uid doesn't exist
N DATA,ARGS,OBJECT,HTTPERR
; Try with a non existent uid attribute
S ARGS("uid")="urn:va:ut:1337"
D GET^VPRJGDS(.DATA,.ARGS)
D ASSERT(0,$D(DATA),"No DATA should be returned")
D ASSERT(404,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 404 error should have occured")
D ASSERT(229,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 229 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
GET ;; @TEST Get Single object
N RETURN,ARG,BODY,DATA,ARGS,OBJECT,ERR,HTTPERR
; Get the data we've stored so far
S ARGS("uid")="urn:va:ut:7"
D GET^VPRJGDS(.DATA,.ARGS)
D:$D(DATA) DECODE^VPRJSON("DATA","OBJECT","ERR")
D ASSERT(10,$D(^VPRJUT("urn:va:ut:7")),"Data does not exist and it should")
D ASSERT(0,$D(ERR),"A JSON Decode Error Occured")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:7",$G(OBJECT("uid")),"The uid field was not returned correctly")
D ASSERT("20130526050000000",$G(OBJECT("lastLogin","date")),"The lastLogin.date attribute was not returned correctly")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K DATA,ARGS,OBJECT,ERR
; Get another object
S ARGS("uid")="urn:va:ut:5"
D GET^VPRJGDS(.DATA,.ARGS)
D:$D(DATA) DECODE^VPRJSON("DATA","OBJECT","ERR")
D ASSERT(10,$D(^VPRJUT("urn:va:ut:5")),"Data does not exist and it should")
D ASSERT(0,$D(ERR),"A JSON Decode Error Occured")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:5",$G(OBJECT("uid")),"The uid field was not returned correctly")
D ASSERT("20130526050000000",$G(OBJECT("lastLogin","date")),"The lastLogin.date attribute was not returned correctly")
D ASSERT("ehmp-proxy",$G(OBJECT("roles",1)),"The roles array (1) was not returned correctly")
D ASSERT("ehmp-test",$G(OBJECT("roles",2)),"The roles array (2) was not returned correctly")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
QUIT
;
GETSTARTID ;; @TEST Get objects beginning with a selected id
N RETURN,ARGS,BODY,DATA,ARGS,OBJECT,ERR,HTTPERR
S ARGS("startid")="urn:va:ut:2"
D GET^VPRJGDS(.DATA,.ARGS)
D PARSE(.DATA,.OBJECT)
D ASSERT(11,$D(DATA),"DATA should be returned")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:2",$G(OBJECT("items",1,"uid")),"Returned list should have started with urn:va:ut:2")
D ASSERT("urn:va:ut:7",$G(OBJECT("items",3,"uid")),"urn:va:ut:7 should have been third item in list")
K ^TMP("HTTPERR",$J),@DATA
QUIT
;
GETSTART ;; @TEST Get objects beginning at an offset
N RETURN,ARGS,BODY,DATA,ARGS,OBJECT,ERR,HTTPERR
S ARGS("start")="2"
D GET^VPRJGDS(.DATA,.ARGS)
D PARSE(.DATA,.OBJECT)
D ASSERT(11,$D(DATA),"DATA should be returned")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:5",$G(OBJECT("items",1,"uid")),"Returned list should have started with urn:va:ut:2")
D ASSERT("",$G(OBJECT("items",3,"uid")),"There should not have been a third item in the list")
K ^TMP("HTTPERR",$J),@DATA
Q
;
GETLIMIT ;; @TEST Get objects up to a limit
N RETURN,ARGS,BODY,DATA,ARGS,OBJECT,ERR,HTTPERR
S ARGS("limit")="3"
D GET^VPRJGDS(.DATA,.ARGS)
D PARSE(.DATA,.OBJECT)
D ASSERT(11,$D(DATA),"DATA should be returned")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:1",$G(OBJECT("items",1,"uid")),"Returned list should have started with urn:va:ut:1")
D ASSERT("urn:va:ut:5",$G(OBJECT("items",3,"uid")),"urn:va:ut:5 should have been third item in list")
D ASSERT(0,$D(OBJECT("items",4)),"There should not be a fouth item returned")
K ^TMP("HTTPERR",$J),@DATA
Q
;
UPDATE ;; @TEST Update a record
N RETURN,BODY,ARG,HTTPERR
; Store a record with more data first
S BODY(1)=$$SAMPLEDATA("""ehmp-proxy"",""ehmp-test""","urn:va:ut:99")
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(10,$D(^VPRJUT("urn:va:ut:99")),"Data NOT stored when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:99",$G(^VPRJUT("urn:va:ut:99","uid")),"The uid field was not stored correctly")
D ASSERT("ehmp-proxy",$G(^VPRJUT("urn:va:ut:99","roles","1")),"The first role attribute in the array was not stored correctly")
D ASSERT("ehmp-test",$G(^VPRJUT("urn:va:ut:99","roles","2")),"The second role attribute in the array was not stored correctly")
D ASSERT($G(RETURN),"/ut/"_"urn:va:ut:99","The UID wasn't returned")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
K RETURN,BODY,ARG,HTTPERR
; Store a record with less data
S BODY(1)=$$SAMPLEDATA("""ehmp-test""","urn:va:ut:99")
S RETURN=$$SET^VPRJGDS(.ARG,.BODY)
D ASSERT(10,$D(^VPRJUT("urn:va:ut:99")),"Data NOT stored when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:99",$G(^VPRJUT("urn:va:ut:99","uid")),"The uid field was not stored correctly")
D ASSERT("ehmp-test",$G(^VPRJUT("urn:va:ut:99","roles","1")),"The first role attribute in the array was not stored correctly")
D ASSERT("",$G(^VPRJUT("urn:va:ut:99","roles","2")),"The second role attribute in the array was not stored correctly")
D ASSERT($G(RETURN),"/ut/"_"urn:va:ut:99","The UID wasn't returned")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
GETFILTER ;; @TEST Get object with filter
N RETURN,ARG,BODY,DATA,ARGS,OBJECT,ERR,HTTPERR
; Get with eq filter an exact match
S ARGS("filter")="eq(""uid"",""urn:va:ut:7"")"
D GET^VPRJGDS(.DATA,.ARGS)
;
; Parse the paged response
D PARSE(.DATA,.OBJECT)
;
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:7",$G(OBJECT("items",1,"uid")),"The uid field was not returned correctly")
D ASSERT("20130526050000000",$G(OBJECT("items",1,"lastLogin","date")),"The lastLogin.date attribute was not returned correctly")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K @DATA,ARGS,OBJECT,ERR
; Get with eq filter a value in an array
S ARGS("filter")="eq(""roles[]"",""ehmp-proxy"")"
D GET^VPRJGDS(.DATA,.ARGS)
;
; Parse the paged response
D PARSE(.DATA,.OBJECT)
;
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:1",$G(OBJECT("items",1,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-proxy",$G(OBJECT("items",1,"roles",1)),"The roles array (1) was not returned correctly")
D ASSERT("urn:va:ut:2",$G(OBJECT("items",2,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-proxy",$G(OBJECT("items",2,"roles",1)),"The roles array (1) was not returned correctly")
D ASSERT("urn:va:ut:5",$G(OBJECT("items",3,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-proxy",$G(OBJECT("items",3,"roles",1)),"The roles array (1) was not returned correctly")
D ASSERT("ehmp-test",$G(OBJECT("items",3,"roles",2)),"The roles array (2) was not returned correctly")
D ASSERT("urn:va:ut:7",$G(OBJECT("items",4,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-proxy",$G(OBJECT("items",4,"roles",1)),"The roles array (1) was not returned correctly")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K @DATA,ARGS,OBJECT,ERR
; Get with eq filter a value in an array (two matches)
S ARGS("filter")="eq(""roles[]"",""ehmp-test"")"
D GET^VPRJGDS(.DATA,.ARGS)
;
; Parse the paged response
D PARSE(.DATA,.OBJECT)
;
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:5",$G(OBJECT("items",1,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-proxy",$G(OBJECT("items",1,"roles",1)),"The roles array (1) was not returned correctly")
D ASSERT("ehmp-test",$G(OBJECT("items",1,"roles",2)),"The roles array (2) was not returned correctly")
D ASSERT("urn:va:ut:99",$G(OBJECT("items",2,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-test",$G(OBJECT("items",2,"roles",1)),"The roles array (2) was not returned correctly")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K @DATA,ARGS,OBJECT,ERR
; Get with complex filter (only one match)
; This is an implicit and
S ARGS("filter")="eq(""roles[]"",""ehmp-test""),eq(""uid"",""urn:va:ut:99"")"
D GET^VPRJGDS(.DATA,.ARGS)
;
; Parse the paged response
D PARSE(.DATA,.OBJECT)
;
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:99",$G(OBJECT("items",1,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-test",$G(OBJECT("items",1,"roles",1)),"The roles array (2) was not returned correctly")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K @DATA,ARGS,OBJECT,ERR
; Get with complex filter (multiple matches)
; This is an implicit and
S ARGS("filter")="or(eq(""roles[]"",""ehmp-proxy""),eq(""uid"",""urn:va:ut:99""))"
D GET^VPRJGDS(.DATA,.ARGS)
;
; Parse the paged response
D PARSE(.DATA,.OBJECT)
;
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:1",$G(OBJECT("items",1,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-proxy",$G(OBJECT("items",1,"roles",1)),"The roles array (2) was not returned correctly")
D ASSERT("urn:va:ut:2",$G(OBJECT("items",2,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-proxy",$G(OBJECT("items",2,"roles",1)),"The roles array (2) was not returned correctly")
D ASSERT("urn:va:ut:5",$G(OBJECT("items",3,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-proxy",$G(OBJECT("items",3,"roles",1)),"The roles array (2) was not returned correctly")
D ASSERT("urn:va:ut:7",$G(OBJECT("items",4,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-proxy",$G(OBJECT("items",4,"roles",1)),"The roles array (2) was not returned correctly")
D ASSERT("urn:va:ut:99",$G(OBJECT("items",5,"uid")),"The uid field was not returned correctly")
D ASSERT("ehmp-test",$G(OBJECT("items",5,"roles",1)),"The roles array (2) was not returned correctly")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
QUIT
;
;
CINDEXNOSTORE ;; @TEST Create Index - Error code is set if no store in HTTPREQ
K ^VPRJUTX ; *** NB
N RETURN,BODY,ARG,HTTPERR
K HTTPREQ
; Create sample JSON
S BODY(1)=$$SAMPLEINDEX("gdsutest","roles[]","roles asc","attr")
; Send it to the URL
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest89")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
S HTTPREQ("store")="ut"
Q
;
CINDEXNOGLOBAL ;; @TEST Error code is set if no global is in VPRCONFIG
N RETURN,BODY,ARG,HTTPERR,GLOBALSAVE
; Create sample JSON
S BODY(1)=$$SAMPLEINDEX("gdsutest","roles[]","roles asc","attr")
; Kill off the global area for the test
S GLOBALSAVE=^VPRCONFIG("store","ut","global")
K ^VPRCONFIG("store","ut","global")
; Send it to the URL
S HTTPREQ("store")="ut"
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRCONFIG("store","ut","global")),"VPRCONFIG global storage area exists and it shouldn't")
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest100")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Restore the global area for the rest of the tests
S ^VPRCONFIG("store","ut","global")=GLOBALSAVE
Q
;
CINDEXNOJSON ;; @TEST Error code is set if no JSON in body
N RETURN,BODY,ARG,HTTPERR,GLOBALSAVE
; Send it to the URL
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(255,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 255 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
CINDEXJSONERR ;; @TEST Error code is set if JSON is mangled in PUT/POST
N RETURN,BODY,ARG,HTTPERR
; Create bad JSON
S BODY(1)=$$SAMPLEINDEX("gdsutest","roles[]","roles asc","attr")
S BODY(1)=BODY(1)_":"
; Send it to the URL
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(202,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 202 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
CINDEXMFIELDS ;; @TEST POST without required fields
N RETURN,BODY,ARG,HTTPERR
; Try with an empty string for the name
S BODY(1)=$$SAMPLEINDEX("","roles[]","roles asc","attr")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should have occured")
D ASSERT(273,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 273 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K BODY,RETURN,ARG
;
; Try with an empty string for the fields
S BODY(1)=$$SAMPLEINDEX("gdsutest","","roles asc","attr")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should have occured")
D ASSERT(273,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 273 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K BODY,RETURN,ARG
;
; Try with an empty string for the sort
S BODY(1)=$$SAMPLEINDEX("gdsutest","roles[]","","attr")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should have occured")
D ASSERT(273,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 273 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K BODY,RETURN,ARG
;
; Try with an empty string for the type
S BODY(1)=$$SAMPLEINDEX("gdsutest","roles[]","roles asc","")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should have occured")
D ASSERT(273,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 273 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K BODY,RETURN,ARG
;
; Try with an empty string for all
S BODY(1)=$$SAMPLEINDEX("","","","")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should have occured")
D ASSERT(273,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 273 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K BODY,RETURN,ARG
;
; Try with a non existent name
; "null" is a magic string to the SAMPLEINDEX generator to prevent the field from even being passed
S BODY(1)=$$SAMPLEINDEX("null","roles[]","roles asc","attr")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should have occured")
D ASSERT(273,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 273 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
;
; Try with a non existent fields
; "null" is a magic string to the SAMPLEINDEX generator to prevent the field from even being passed
S BODY(1)=$$SAMPLEINDEX("gdsutest","null","roles asc","attr")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should have occured")
D ASSERT(273,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 273 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
;
; Try with a non existent sort
; "null" is a magic string to the SAMPLEINDEX generator to prevent the field from even being passed
S BODY(1)=$$SAMPLEINDEX("gdsutest","roles[]","null","attr")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should have occured")
D ASSERT(273,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 273 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
;
; Try with a non existent type
; "null" is a magic string to the SAMPLEINDEX generator to prevent the field from even being passed
S BODY(1)=$$SAMPLEINDEX("gdsutest","roles[]","roles asc","null")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(0,$D(^VPRJUTX("attr","gdsutest")),"Index created when it shouldn't be")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should have occured")
D ASSERT(273,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 273 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
CINDEX1 ;; @TEST Create 1 index (happy path)
N RETURN,BODY,ARG,HTTPERR
S BODY(1)=$$SAMPLEINDEX("gdsutest","roles[]","roles asc","attr")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(11,$D(^VPRJUTX("attr","gdsutest")),"Index NOT created when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT(1,$D(^VPRJUTX("attr","gdsutest","ehmp-proxy ","urn:va:ut:1","roles#1")),"The first role type is not as expected")
D ASSERT(1,$D(^VPRJUTX("attr","gdsutest","ehmp-test ","urn:va:ut:5","roles#2")),"The second role type is not as expected")
D ASSERT(10,$D(^VPRCONFIG("store","ut","index","gdsutest")),"Index Not stored in VPRJCONFIG")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
CINDEX2 ;; @TEST Creating 2 (additional) indexes
N RETURN,BODY,ARG,HTTPERR
S BODY(1)=$$SAMPLEINDEX("gdsutest2","lastLogin.date","date asc","attr")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(11,$D(^VPRJUTX("attr","gdsutest2")),"Index NOT created when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT(1,$D(^VPRJUTX("attr","gdsutest2","20130526050000000 ","urn:va:ut:1",1)),"The first lastLogin.date index is not as expected")
D ASSERT(1,$D(^VPRJUTX("attr","gdsutest2","20130526050000000 ","urn:va:ut:2",1)),"The second lastLogin.date index is not as expected")
D ASSERT(10,$D(^VPRCONFIG("store","ut","index","gdsutest2")),"Index Not stored in VPRJCONFIG")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K RETURN,BODY,ARG
; Update the record
S BODY(1)=$$SAMPLEINDEX("gdsutest3","createDate.date","date asc","attr")
S RETURN=$$CINDEX^VPRJGDS(.ARG,.BODY)
D ASSERT(11,$D(^VPRJUTX("attr","gdsutest3")),"Index NOT created when it should be")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT(1,$D(^VPRJUTX("attr","gdsutest3","20000101120000000 ","urn:va:ut:1",1)),"The first createDate.date index is not as expected")
D ASSERT(1,$D(^VPRJUTX("attr","gdsutest3","20000101120000000 ","urn:va:ut:2",1)),"The second createDate.date index is not as expected")
D ASSERT(10,$D(^VPRCONFIG("store","ut","index","gdsutest3")),"Index Not stored in VPRJCONFIG")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
;
INDEXNOSTORE ;; @TEST Error code is set if no store in HTTPREQ
N DATA,OBJECT,ERR,ARGS,HTTPERR
; Send it to the URL
K HTTPREQ("store")
D INDEX^VPRJGDS(.DATA,.ARGS)
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
INDEXNOGLOBAL ;; @TEST Error code is set if no global is in VPRCONFIG
N DATA,OBJECT,ERR,ARGS,HTTPERR,GLOBALSAVE
; Kill off the global area for the test
S GLOBALSAVE=^VPRCONFIG("store","ut","global")
K ^VPRCONFIG("store","ut","global")
; Send it to the URL
S HTTPREQ("store")="ut"
D INDEX^VPRJGDS(.DATA,.ARGS)
D ASSERT(0,$D(^VPRCONFIG("store","ut","global")),"VPRCONFIG global storage area exists and it shouldn't")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(253,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 253 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Restore the global area for the rest of the tests
S ^VPRCONFIG("store","ut","global")=GLOBALSAVE
Q
;
INDEXNOINDEX ;; @TEST Error code is set if no index specified
N DATA,OBJECT,ERR,ARGS,HTTPERR,GLOBALSAVE
; Try with non-existent indexName
; Send it to the URL
D INDEX^VPRJGDS(.DATA,.ARGS)
D ASSERT(0,$D(DATA),"DATA returned and there shouldn't be any")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(102,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 102 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Try with null indexName
; Send it to the URL
S ARGS("indexName")=""
D INDEX^VPRJGDS(.DATA,.ARGS)
D ASSERT(0,$D(DATA),"DATA returned and there shouldn't be any")
D ASSERT(400,$G(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP 400 error should have occured")
D ASSERT(102,$G(^TMP("HTTPERR",$J,1,"error","errors",1,"reason")),"An 102 reason code should have occurred")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
INDEX ;; @TEST Get via Index
N RETURN,ARG,BODY,DATA,ARGS,OBJECT,ERR,HTTPERR
;
; Get the data we've stored so far
S ARGS("indexName")="gdsutest"
D INDEX^VPRJGDS(.RSP,.ARGS)
;
; Parse the paged response
D PARSE(.RSP,.OBJECT)
;
D ASSERT(10,$D(OBJECT("items")),"Data does not exist and it should")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:1",$G(OBJECT("items",1,"uid")),"The uid field was not returned correctly")
D ASSERT("urn:va:ut:2",$G(OBJECT("items",2,"uid")),"The uid field was not returned correctly")
D ASSERT("urn:va:ut:99",$G(OBJECT("items",5,"uid")),"The uid field was not returned correctly")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
K ^TMP($J)
; Cleanup Vars
K DATA,ARGS,OBJECT,ERR,RSP
; Get another object
S ARGS("indexName")="gdsutest2"
D INDEX^VPRJGDS(.RSP,.ARGS)
;
; Parse the paged response
D PARSE(.RSP,.OBJECT)
;
D ASSERT(10,$D(OBJECT("items")),"Data does not exist and it should")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:1",$G(OBJECT("items",1,"uid")),"The uid field was not returned correctly")
D ASSERT("urn:va:ut:2",$G(OBJECT("items",2,"uid")),"The uid field was not returned correctly")
D ASSERT("urn:va:ut:99",$G(OBJECT("items",5,"uid")),"The uid field was not returned correctly")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K DATA,ARGS,OBJECT,ERR,RSP
;
; make sure that returncounts is a recognized query parameter and it returns the data as expected
S (ARGS("returncounts"),RSP("returncounts"))="true"
S ARGS("indexName")="gdsutest2"
D INDEX^VPRJGDS(.RSP,.ARGS)
;
; Parse the paged response
D PARSE(.RSP,.OBJECT)
;
D ASSERT(11,$D(RSP),"RSP should be returned")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:7",$G(OBJECT("items",4,"uid")),"The uid field was not returned correctly")
D ASSERT(1,$D(OBJECT("totalItems")),"totalItems attribute not returned")
D ASSERT($O(OBJECT("items",""),-1),$G(OBJECT("totalItems")),"totalItems attribute did not match total items returned")
D ASSERT(1,$D(OBJECT("currentItemCount")),"currentItemCount attribute not returned")
;
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
Q
;
INDEXLOCK ;; @TEST Get via Index and a locked record
N RETURN,BODY,DATA,ARGS,OBJECT,ERR,HTTPERR,TIMEOUT,RSP
;
; Get the data we've stored so far
; lock uid: urn:va:ut:2
S ARGS("uid")="urn:va:ut:2"
S RETURN=$$SETLOCK^VPRJGDS(.ARGS,.BODY)
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error","code")),"An HTTP error should NOT have occured")
D ASSERT("/ut/lock/urn:va:ut:2",$G(RETURN),"The returned location header isn't as expected")
K ARGS,BODY,RETURN
;
S ARGS("indexName")="gdsutest"
S ARGS("skiplocked")="true"
D INDEX^VPRJGDS(.RSP,.ARGS)
;
; Parse the paged response
D PARSE(.RSP,.OBJECT)
;
D ASSERT(10,$D(OBJECT("items")),"Data does not exist and it should")
D ASSERT(0,$D(ERR),"A JSON Decode Error Occured")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:1",$G(OBJECT("items",1,"uid")),"The uid field was not returned correctly")
D ASSERT("urn:va:ut:5",$G(OBJECT("items",2,"uid")),"The uid field was not returned correctly")
D ASSERT("urn:va:ut:99",$G(OBJECT("items",4,"uid")),"The uid field was not returned correctly")
D ASSERT(0,$D(OBJECT("items",5)),"Too many items were returned")
; Cleanup HTTPERR
K ^TMP("HTTPERR",$J)
; Cleanup Vars
K DATA,ARGS,OBJECT,ERR,RSP
K ^TMP($J)
;
; expire the lock
; Set the timeout value to something smaller so the tests don't take forever
S TIMEOUT=$G(^VPRCONFIG("store","ut","lockTimeout"))
S ^VPRCONFIG("store","ut","lockTimeout")=1
H 2
S ARGS("indexName")="gdsutest"
S ARGS("skiplocked")="true"
D INDEX^VPRJGDS(.RSP,.ARGS)
;
; Parse the paged response
D PARSE(.RSP,.OBJECT)
;
D ASSERT(10,$D(OBJECT("items")),"Data does not exist and it should")
D ASSERT(0,$D(ERR),"A JSON Decode Error Occured")
D ASSERT(0,$D(^TMP("HTTPERR",$J,1,"error")),"An HTTP error should NOT have occured")
D ASSERT("urn:va:ut:1",$G(OBJECT("items",1,"uid")),"The uid field was not returned correctly")