-
Notifications
You must be signed in to change notification settings - Fork 6
/
VPRJTDR.m
286 lines (286 loc) · 9.58 KB
/
VPRJTDR.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
VPRJTDR ;SLC/KCM -- Integration tests for ODC RESTful queries
;
STARTUP ; Run once before all tests
N I,TAGS
F I=1:1:6 S TAGS(I)="TEST"_I_"^VPRJTD01"
D ODSBLD^VPRJTX(.TAGS)
Q
SHUTDOWN ; Run once after all tests
D ODSCLR^VPRJTX
Q
SETUP ; Run before each test
K HTTPREQ,HTTPERR,HTTPRSP
Q
TEARDOWN ; Run after each test
K HTTPREQ,HTTPERR,HTTPRSP
Q
ASSERT(EXPECT,ACTUAL) ; convenience
D EQ^VPRJT(EXPECT,ACTUAL)
Q
;
; POST data for POST query tests
POSTDATA1 ;; test POST query data for INDEX and LAST
;;{"range":"alpha..delta"}
;;zzzzz
POSTDATA2 ;; test POST query data for ORDASC
;;{"order":"name asc"}
;;zzzzz
POSTDATA3 ;; test POST query data for ORDDESC
;;{"order":"name DESC"}
;;zzzzz
POSTDATA4 ;; test POST query data for ORDEMPTY
;;{"order":"type DESC"}
;;zzzzz
POSTDATA5 ;; test POST query data for FILTER
;;{"filter":"eq(\"color\",\"orange\")"}
;;zzzzz
POSTDATA6 ;; test POST query data for EVERY
;;{"start":3,"limit":3}
;;zzzzz
POSTDATA7 ;; test POST query data for FINDPAR
;;{"filter":"eq(\"color\",\"orange\")","order":"name"}
;;zzzzz
;
INDEX ;; @TEST query using an index
N ROOT,JSON,ERR,HTTPERR
D SETGET^VPRJTX("/data/index/test-name?range=alpha..delta")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(4,JSON("data","totalItems"))
D ASSERT(201110201857,JSON("data","items",4,"updated")) ; sorted reverse updated date
; test POST query version
K ROOT,JSON,ERR,HTTPERR
D SETPOST^VPRJTX("/data/index/test-name?query=true","POSTDATA1","VPRJTDR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(4,JSON("data","totalItems"))
D ASSERT(201110201857,JSON("data","items",4,"updated")) ; sorted reverse updated date
Q
LAST ;; @TEST query for last instance of items in list
N ROOT,JSON,ERR,HTTPERR
D SETGET^VPRJTX("/data/last/test-name?range=alpha..delta")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(3,JSON("data","totalItems"))
D ASSERT("urn:va:test:6",JSON("data","items",1,"uid"))
; test POST query version
K ROOT,JSON,ERR,HTTPERR
D SETPOST^VPRJTX("/data/last/test-name?query=true","POSTDATA1","VPRJTDR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(3,JSON("data","totalItems"))
D ASSERT("urn:va:test:6",JSON("data","items",1,"uid"))
Q
ORDASC ;; @TEST query to return in different order
N ROOT,JSON,ERR,HTTPERR
D SETGET^VPRJTX("/data/index/test-name?order=name asc")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("gamma",JSON("data","items",6,"name"))
; test POST query version
K ROOT,JSON,ERR,HTTPERR
D SETPOST^VPRJTX("/data/index/test-name?query=true","POSTDATA2","VPRJTDR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("gamma",JSON("data","items",6,"name"))
Q
ORDDESC ;; @TEST query to return in different order
N ROOT,JSON,ERR,HTTPERR
D SETGET^VPRJTX("/data/index/test-name?order=name DESC")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("gamma",JSON("data","items",1,"name"))
; test POST query version
K ROOT,JSON,ERR,HTTPERR
D SETPOST^VPRJTX("/data/index/test-name?query=true","POSTDATA3","VPRJTDR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("gamma",JSON("data","items",1,"name"))
Q
ORDEMPTY ;; @TEST query where 'order by' field contains empty string
N ROOT,JSON,ERR,HTTPERR
D SETGET^VPRJTX("/data/index/test-name?order=type DESC")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("vegatable",JSON("data","items",1,"type"))
; test POST query version
K ROOT,JSON,ERR,HTTPERR
D SETPOST^VPRJTX("/data/index/test-name?query=true","POSTDATA4","VPRJTDR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("vegatable",JSON("data","items",1,"type"))
Q
FILTER ;; @TEST filter to return based on criteria
N ROOT,JSON,ERR,HTTPERR
D SETGET^VPRJTX("/data/index/test-name?filter=eq(""color"",""orange"")")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(2,JSON("data","totalItems"))
D ASSERT("epsilon",JSON("data","items",1,"name"))
; test POST query version
K ROOT,JSON,ERR,HTTPERR
D SETPOST^VPRJTX("/data/index/test-name?query=true","POSTDATA5","VPRJTDR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(2,JSON("data","totalItems"))
D ASSERT("epsilon",JSON("data","items",1,"name"))
Q
GETUID ;; @TEST getting an object by UID only
N JSON,ERR,HTTPERR
D SETGET^VPRJTX("/data/urn:va:test:5")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT("epsilon",JSON("data","items",1,"name"))
Q
GETNONE ;; @TEST getting an object that does not exist
N JSON,ERR,HTTPERR
D SETGET^VPRJTX("/data/urn:test:bogus:54321")
D RESPOND^VPRJRSP
D ASSERT(1,$G(HTTPERR)>0)
D ASSERT(404,$G(^TMP("HTTPERR",$J,1,"error","code")))
K ^TMP("HTTPERR",$J)
Q
EVERY ;; TEST retrieving every object in a collection
N JSON,ERR,HTTPERR
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/index/every")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(6,JSON("data","totalItems"))
D ASSERT(0,$D(^TMP($J,$J)))
D ASSERT(10,$D(^VPRTMP($$HASH^VPRJRUT("vpr/index/"_VPRJTPID_"/every////"))))
D ASSERT(0,$D(^VPRTMP($$HASH^VPRJRUT("vpr/index/"_VPRJTPID_"/every////"),$J)))
K JSON
D SETGET^VPRJTX("/vpr/"_VPRJTPID_"/index/every?start=3&limit=3")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(3,JSON("data","currentItemCount"))
D ASSERT(10,$D(^VPRTMP($$HASH^VPRJRUT("vpr/index/"_VPRJTPID_"/every////"))))
D ASSERT(0,$D(^VPRTMP($$HASH^VPRJRUT("vpr/index/"_VPRJTPID_"/every////"),$J)))
; test POST query version
K JSON
D SETPOST^VPRJTX("/vpr/"_VPRJTPID_"/index/every?query=true","POSTDATA6","VPRJTDR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(3,JSON("data","currentItemCount"))
D ASSERT(10,$D(^VPRTMP($$HASH^VPRJRUT("vpr/index/"_VPRJTPID_"/every////"))))
D ASSERT(0,$D(^VPRTMP($$HASH^VPRJRUT("vpr/index/"_VPRJTPID_"/every////"),$J)))
Q
FINDALL ;; @TEST finding every object in collection
N JSON,ERR,HTTPERR
D SETGET^VPRJTX("/data/find/test")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(6,JSON("data","totalItems"))
Q
FINDPAR ;; @TEST finding with parameters
N JSON,ERR,HTTPERR
D SETGET^VPRJTX("/data/find/test?filter=eq(""color"",""orange"")&order=name")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(2,JSON("data","totalItems"))
D ASSERT("urn:va:test:5",JSON("data","items",1,"uid"))
; test POST query version
K JSON,ERR,HTTPERR
D SETPOST^VPRJTX("/data/find/test?query=true","POSTDATA7","VPRJTDR")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(2,JSON("data","totalItems"))
D ASSERT("urn:va:test:5",JSON("data","items",1,"uid"))
Q
FINDTLT ;; @TEST finding with template (applyOnSave)
N JSON,ERR,HTTPERR
D ASSERT(10,$D(^VPRJDJ("TEMPLATE","urn:va:test:5","unit-test-ods-summary")))
D SETGET^VPRJTX("/data/find/test/unit-test-ods-summary")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D DATA2ARY^VPRJTX(.JSON)
D ASSERT(6,JSON("data","totalItems"))
D ASSERT("epsilon",JSON("data","items",5,"name"))
D ASSERT("urn:va:test:5",JSON("data","items",5,"uid"))
D ASSERT(0,$D(JSON("data","items",5,"color")))
Q
ADDOBJ ;; @TEST adding object to store
N HTTPERR
D SETPUT^VPRJTX("/data","TEST7","VPRJTD01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT("/data/urn:va:test:7",HTTPREQ("location"))
D ASSERT(10,$D(^VPRJD("urn:va:test:7")))
D ASSERT(7,$G(^VPRJDX("count","collection","test")))
D ASSERT(1,$D(^VPRJDX("attr","test-name","omega ","798789768244=","urn:va:test:7",1)))
Q
DELOBJ ;; @TEST remove object from store
N HTTPERR
D SETDEL^VPRJTX("/data/urn:va:test:7")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT(0,$D(^VPRJD("urn:va:test:7")))
D ASSERT(6,$G(^VPRJDX("count","collection","test")))
D ASSERT(0,$D(^VPRJDX("attr","test-name","omega ","798789768244=","urn:va:test:7",0)))
Q
;
NEWOBJ ;; @TEST add a new object, returning a new UID
N HTTPERR,LASTID
S LASTID=$G(^VPRJD("COLLECTION","testb"))
D SETPUT^VPRJTX("/data/testb","NOUID1","VPRJTD01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT("/data/urn:va:testb:"_$G(^VPRMETA("system"))_":"_(LASTID+1),HTTPREQ("location"))
D SETPUT^VPRJTX("/data/testb","NOUID2","VPRJTD01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT("/data/urn:va:testb:"_$G(^VPRMETA("system"))_":"_(LASTID+2),HTTPREQ("location"))
D SETPUT^VPRJTX("/data/testb","HASUID","VPRJTD01")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT("/data/urn:va:testb:42",HTTPREQ("location"))
Q
DELCTN ;; @TEST delete collection
N HTTPERR
D SETPUT^VPRJTX("/data","OTHER","VPRJTD01") ; add something from another collection
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT(4,$G(^VPRJDX("count","collection","testb")))
D ASSERT(6,$G(^VPRJDX("count","collection","test")))
D SETDEL^VPRJTX("/data/collection/test")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT(4,$G(^VPRJDX("count","collection","testb")))
D ASSERT(10,$D(^VPRJD("urn:va:testb:29")))
D ASSERT(0,+$G(^VPRJDX("count","collection","test")))
Q
DELSITE ;; @TEST REST endpoint to delete all objects for a site
N HTTPERR
D SETPUT^VPRJTX("/data","OTHER1","VPRJTD01") ; add something from another collection
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT(0,$D(^VPRJD("urn:va:testb:29"))#2)
D ASSERT(5,$G(^VPRJDX("count","collection","testb")))
D SETDEL^VPRJTX("/data/site/29")
D RESPOND^VPRJRSP
D ASSERT(0,$G(HTTPERR))
D ASSERT(0,$D(^VPRJD("urn:va:testb:29"))#2)
D ASSERT(4,$G(^VPRJDX("count","collection","testb")))
Q
1 ; run just one test
D STARTUP,SETUP,GETNONE,TEARDOWN,SHUTDOWN
Q