-
Notifications
You must be signed in to change notification settings - Fork 0
/
uc_tests.fnl
executable file
·770 lines (640 loc) · 21.8 KB
/
uc_tests.fnl
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
ns main
import uc
import er
import domain
import stdvar
import stdfu
import stdpr
import stddbc
import stdsort
# set debug print functions
is-debug-on = true
debug = call(stdpr.get-pr is-debug-on)
debugpp = call(stdpr.get-pp-pr is-debug-on)
new-simulated-store = proc()
task-store = call(stdvar.new list())
# mock implementation for get-values
new-get-values = func(store-impl)
proc(matcher)
tasklist = call(stdvar.value store-impl)
tasks = call(stdfu.filter tasklist matcher)
tasks
end
end
# mock implementation for take-values
new-take-values = func(store-impl)
proc(matcher)
updator = func(tasks)
choose = func(remaining left-list taken-list)
if( empty(remaining)
list(left-list taken-list)
call(func()
next-task = head(remaining)
next-left next-taken = if( call(matcher next-task)
list(left-list append(taken-list next-task))
list(append(left-list next-task) taken-list)
):
call(choose rest(remaining) next-left next-taken)
end)
)
end
left taken = call(choose tasks list() list()):
list(left taken)
end
ok err _ takenlist = call(stdvar.change-v2 store-impl updator):
takenlist
end
end
# mock implementation for update
new-update = func(store-impl)
proc(matcher)
updator = func(tasks)
update-items = func(remaining newlist any-change)
if( empty(remaining)
list(newlist any-change)
call(func()
next-item = head(remaining)
do-update new-value = call(matcher next-item):
if( do-update
call(update-items rest(remaining) append(newlist new-value) true)
call(update-items rest(remaining) append(newlist next-item) any-change)
)
end)
)
end
new-tasks is-any-change = call(update-items tasks list() false):
list(new-tasks is-any-change)
end
ok err _ is-any-change = call(stdvar.change-v2 store-impl updator):
is-any-change
end
end
# mock implementation for put-value
new-put-value = func(store-impl)
proc(item)
ok err _ = call(stdvar.change store-impl func(prev) append(prev item) end):
list(ok err)
end
end
trans = proc(txn-proc)
orig-value = call(stdvar.value task-store)
new-task-store = call(stdvar.new orig-value)
txn-object = map(
'get-values' call(new-get-values new-task-store)
'take-values' call(new-take-values new-task-store)
'update' call(new-update new-task-store)
'put-value' call(new-put-value new-task-store)
)
do-commit = call(txn-proc txn-object)
_ = if( do-commit
call(stdvar.set task-store call(stdvar.value new-task-store))
'cancelled, changes not done'
)
do-commit
end
# return mock store-object
store-object = map(
'get-values' call(new-get-values task-store)
'take-values' call(new-take-values task-store)
'update' call(new-update task-store)
'put-value' call(new-put-value task-store)
'trans' trans
)
store-object
end
# --- test task adding ok
test-add-task-ok = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
msg = map(
'name' 'task-A'
'state' 'done'
)
status err val = call(task-adder map() msg):
_ = call(stddbc.assert eq(er.No-Error status) sprintf('task adding failed: %s (%d)' err status))
tasklist = call(task-getter map('query-map' map()) map())
_ = call(stddbc.assert eq(len(tasklist) 1) sprintf('unexpected tasks: %v' tasklist))
task = head(tasklist)
_ = call(stddbc.assert eq(get(task 'name') 'task-A') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'state') 'done') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'id') 101) sprintf('wrong id: %v' task))
_ = call(stddbc.assert eq(get(task 'version') 'v1') sprintf('wrong version: %v' task))
true
end
# --- test task adding fails as id -field not allowed
test-add-task-fail-id-not-allowed = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
msg = map(
'name' 'task-A'
'state' 'done'
'id' 100
)
status err val = call(task-adder map() msg):
_ = call(stddbc.assert eq(er.Invalid-Request status) sprintf('task adding should fail: %s (%d)' err status))
_ = call(stddbc.assert eq('id not allowed in task when new task added' err) sprintf('unexpected err: %s (%d)' err status))
tasklist = call(task-getter map('query-map' map()) map())
_ = call(stddbc.assert empty(tasklist) sprintf('unexpected tasks: %v' tasklist))
true
end
# --- test task adding fails as name is missing (invalid task data)
test-add-task-fail-invalid-task-data = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
msg = map(
'state' 'done'
)
status err val = call(task-adder map() msg):
_ = call(stddbc.assert eq(er.Invalid-Request status) sprintf('task adding should fail: %s (%d)' err status))
_ = call(stddbc.assert eq('invalid task: required field name not found ()' err) sprintf('unexpected err: %s (%d)' err status))
tasklist = call(task-getter map('query-map' map()) map())
_ = call(stddbc.assert empty(tasklist) sprintf('unexpected tasks: %v' tasklist))
true
end
# --- test task adding fails in store
test-add-task-fail-in-store = proc()
failing-put-value = proc(item)
list(false 'fake error')
end
store = put(del(call(new-simulated-store) 'put-value') 'put-value' failing-put-value)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
msg = map(
'name' 'task-A'
'state' 'done'
)
status err val = call(task-adder map() msg):
_ = call(stddbc.assert eq(er.Invalid-Request status) sprintf('task adding should fail: %s (%d)' err status))
_ = call(stddbc.assert eq('adding task failed: fake error' err) sprintf('unexpected err: %s (%d)' err status))
tasklist = call(task-getter map('query-map' map()) map())
_ = call(stddbc.assert empty(tasklist) sprintf('unexpected tasks: %v' tasklist))
true
end
# --- test task modify ok
test-modify-task-ok = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
task-modifier = call(uc.new-task-modifier store)
msg = map(
'name' 'task-A'
'state' 'done'
)
_ = call(task-adder map() msg)
status err _ = call(task-modifier
map('query-map' map() 'selected-id' 101)
map('version' 'v1' 'state' 'ongoing' 'description' 'Huraa !!!')
):
_ = call(stddbc.assert eq(er.No-Error status) sprintf('task modify failed: %s (%d)' err status))
tasklist = call(task-getter map('query-map' map()) map())
_ = call(stddbc.assert eq(len(tasklist) 1) sprintf('unexpected tasks: %v' tasklist))
task = head(tasklist)
_ = call(stddbc.assert eq(get(task 'name') 'task-A') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'state') 'ongoing') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'description') 'Huraa !!!') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'id') 101) sprintf('wrong id: %v' task))
_ = call(stddbc.assert eq(get(task 'version') 'v2') sprintf('wrong version: %v' task))
true
end
# --- test task modify fails as wrong version is given
test-modify-task-fail-as-wrong-version = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
task-modifier = call(uc.new-task-modifier store)
msg = map(
'name' 'task-A'
'state' 'done'
)
_ = call(task-adder map() msg)
status err _ = call(task-modifier
map('query-map' map() 'selected-id' 101)
map('version' 'v10' 'state' 'ongoing' 'description' 'Huraa !!!')
):
_ = call(stddbc.assert eq(er.Invalid-Request status) sprintf('task modify, unexpected status: %s (%d)' err status))
# lets check that nothing has changed
tasklist = call(task-getter map('query-map' map()) map())
_ = call(stddbc.assert eq(len(tasklist) 1) sprintf('unexpected tasks: %v' tasklist))
task = head(tasklist)
_ = call(stddbc.assert eq(get(task 'name') 'task-A') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'state') 'done') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'description') '') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'id') 101) sprintf('wrong id: %v' task))
_ = call(stddbc.assert eq(get(task 'version') 'v1') sprintf('wrong version: %v' task))
true
end
# --- test task replace ok
test-replace-task-ok = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
task-replacer = call(uc.new-task-replacer store)
msg = map(
'name' 'task-A'
'state' 'done'
)
_ = call(task-adder map() msg)
task-prev = head(call(task-getter map('query-map' map()) map()))
new-task = map(
'id' get(task-prev 'id')
'name' get(task-prev 'name')
'description' 'text-replaced'
'tags' list('new-tag')
'state' 'ongoing'
'version' get(task-prev 'version')
)
status err _ = call(task-replacer
map('query-map' map() 'selected-id' 101)
new-task
):
_ = call(stddbc.assert eq(er.No-Error status) sprintf('task replace failed: %s (%d)' err status))
tasklist = call(task-getter map('query-map' map()) map())
_ = call(stddbc.assert eq(len(tasklist) 1) sprintf('unexpected tasks: %v' tasklist))
task = head(tasklist)
_ = call(stddbc.assert eq(get(task 'name') 'task-A') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'state') 'ongoing') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'description') 'text-replaced') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'tags') list('new-tag')) sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'id') 101) sprintf('wrong id: %v' task))
_ = call(stddbc.assert eq(get(task 'version') 'v2') sprintf('wrong version: %v' task))
true
end
# --- test task replace fails as wrong version is given
test-replace-task-fail-as-wrong-version = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
task-replacer = call(uc.new-task-replacer store)
msg = map(
'name' 'task-A'
'state' 'done'
)
_ = call(task-adder map() msg)
task-prev = head(call(task-getter map('query-map' map()) map()))
new-task = map(
'id' get(task-prev 'id')
'name' get(task-prev 'name')
'description' 'text-replaced'
'tags' list('new-tag')
'state' 'ongoing'
'version' 'this is wrong version'
)
status err _ = call(task-replacer
map('query-map' map() 'selected-id' 101)
new-task
):
_ = call(stddbc.assert eq(er.Invalid-Request status) sprintf('task replace, unexpected status: %s (%d)' err status))
# lets check that nothing has changed
tasklist = call(task-getter map('query-map' map()) map())
_ = call(stddbc.assert eq(len(tasklist) 1) sprintf('unexpected tasks: %v' tasklist))
task = head(tasklist)
_ = call(stddbc.assert eq(get(task 'name') 'task-A') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'state') 'done') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'description') '') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'tags') list()) sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'id') 101) sprintf('wrong id: %v' task))
_ = call(stddbc.assert eq(get(task 'version') 'v1') sprintf('wrong version: %v' task))
true
end
# --- test task deletion ok
test-delete-task-ok = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
task-deleter = call(uc.new-task-deleter store)
msg = map(
'name' 'task-A'
'state' 'done'
)
_ = call(task-adder map() msg)
status err _ = call(task-deleter
map('query-map' map() 'selected-id' 101)
map()
):
_ = call(stddbc.assert eq(er.No-Error status) sprintf('task modify failed: %s (%d)' err status))
tasklist = call(task-getter map('query-map' map()) map())
_ = call(stddbc.assert empty(tasklist) sprintf('unexpected tasks: %v' tasklist))
true
end
# --- test task getting with id ok
test-get-task-by-id = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter-by-id = call(uc.new-task-getter-by-id store)
tasks = list(
map(
'name' 'task-A'
'state' 'new'
)
map(
'name' 'task-B'
'state' 'ongoing'
)
map(
'name' 'task-C'
'state' 'done'
)
)
_ = call(stdfu.ploop proc(task _) call(task-adder map() task) end tasks 'none')
tasklist = call(task-getter-by-id map('selected-id' 102) map())
_ = call(stddbc.assert eq(len(tasklist) 1) sprintf('unexpected tasks: %v' tasklist))
task = head(tasklist)
_ = call(stddbc.assert eq(get(task 'name') 'task-B') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'state') 'ongoing') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'description') '') sprintf('unexpected task: %v' task))
_ = call(stddbc.assert eq(get(task 'id') 102) sprintf('wrong id: %v' task))
_ = call(stddbc.assert eq(get(task 'version') 'v1') sprintf('wrong version: %v' task))
# test also by giving non existing id
tasklist2 = call(task-getter-by-id map('selected-id' 1234) map())
_ = call(stddbc.assert empty(tasklist2) sprintf('should be empty: %v' tasklist))
true
end
# --- test task getting with query parameter ok
test-get-task-by-query = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
tasks = list(
map(
'name' 'task-A'
'state' 'new'
)
map(
'name' 'task-B'
'state' 'ongoing'
)
map(
'name' 'task-C'
'state' 'done'
)
)
_ = call(stdfu.ploop proc(task _) call(task-adder map() task) end tasks 'none')
tasklist = call(task-getter
map('query-map' map('state' list('ongoing' 'new')))
map()
)
_ = call(stddbc.assert eq(len(tasklist) 2) sprintf('unexpected tasks: %v' tasklist))
check-task = proc(task)
_ = call(stddbc.assert in(list('task-A' 'task-B') get(task 'name')) sprintf('unexpected task: %v' task))
_ = call(stddbc.assert in(list('ongoing' 'new') get(task 'state')) sprintf('unexpected task: %v' task))
_ = call(stddbc.assert in(list(101 102) get(task 'id')) sprintf('wrong id: %v' task))
true
end
and(
call(check-task head(tasklist))
call(check-task last(tasklist))
)
end
# --- test task getting with query parameter (search) for text search
test-get-task-by-text-search = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
tasks = list(
map(
'name' 'Carwash'
'description' 'Washing car'
)
map(
'name' 'Garage'
'description' 'Clean the garage'
)
map(
'name' 'Shopping'
'description' 'Drive with car to do shopping'
)
)
_ = call(stdfu.ploop proc(task _) call(task-adder map() task) end tasks 'none')
check-names = proc(tasklist expect-names)
_ = call(stddbc.assert eq(len(tasklist) len(expect-names)) sprintf('unexpected tasks: %v' tasklist))
namelist = call(stdfu.apply tasklist func(task) get(task 'name') end)
_ = call(stddbc.assert eq(len(namelist) len(expect-names)) sprintf('list len dont match: %v' tasklist))
names-ok = call(stdfu.applies-for-all expect-names func(tn) in(namelist tn) end)
_ = call(stddbc.assert names-ok sprintf('names dont match: %v' namelist))
true
end
do-get = proc(search-list)
call(task-getter
map('query-map' map('search' search-list))
map()
)
end
# search one string which occurs in two tasks
_ = call(check-names call(do-get list('car')) list('Shopping' 'Carwash'))
# no search string given -> empty result list
_ = call(check-names call(do-get list()) list())
# search two strings
_ = call(check-names call(do-get list('Car' 'garage')) list('Carwash' 'Garage'))
true
end
# --- test getting all tags
test-get-tags-OK = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
task-adder = call(uc.new-task-adder store task-id-var)
tag-getter = call(uc.new-tag-getter store)
tasks = list(
map(
'name' 'task-A'
'state' 'new'
'tags' list('A1-tag' 'A2-tag' 'common')
)
map(
'name' 'task-B'
'state' 'ongoing'
)
map(
'name' 'task-C'
'state' 'done'
'tags' list('C1-tag' 'C2-tag' 'common')
)
)
_ = call(stdfu.ploop proc(task _) call(task-adder map() task) end tasks 'none')
taglist = call(tag-getter map() map())
_ = call(stddbc.assert eq(len(taglist) 5) sprintf('unexpected tags: %v' taglist))
_ = call(stddbc.assert in(taglist 'A1-tag') sprintf('unexpected tags: %v' taglist))
_ = call(stddbc.assert in(taglist 'A2-tag') sprintf('unexpected tags: %v' taglist))
_ = call(stddbc.assert in(taglist 'C1-tag') sprintf('unexpected tags: %v' taglist))
_ = call(stddbc.assert in(taglist 'C2-tag') sprintf('unexpected tags: %v' taglist))
_ = call(stddbc.assert in(taglist 'common') sprintf('unexpected tags: %v' taglist))
true
end
# --- test tasks import OK
test-import-tasks-OK = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
tasks-importer = call(uc.new-tasks-importer store task-id-var)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
old-tasks = list(
map(
'name' 'Carwash'
'description' 'Washing car'
)
map(
'name' 'Garage'
'description' 'Clean the garage'
)
map(
'name' 'Shopping'
'description' 'Drive with car to do shopping'
)
)
_ = call(stdfu.ploop proc(task _) call(task-adder map() task) end old-tasks 'none')
tasks = list(
map(
'id' 1001
'name' 'task-A'
'description' 'text-A'
'tags' list('tag-A')
'state' 'ongoing'
'version' 'v100'
)
map(
'id' 1002
'name' 'task-B'
'description' 'text-B'
'tags' list('tag-B')
'state' 'new'
'version' 'v101'
)
map(
'id' 1003
'name' 'task-C'
'description' 'text-C'
'tags' list('tag-C')
'state' 'done'
'version' 'v102'
)
)
imp-ok imp-err _ = call(tasks-importer map() tasks):
new-tasks = call(task-getter map('query-map' map()) map())
compa = func(val1 val2)
gt(
conv(slice(get(val1 'version') 1) 'int')
conv(slice(get(val2 'version') 1) 'int')
)
end
tsk1 = call(stdsort.sort call(stdfu.apply tasks func(item) del(item 'id') end) compa)
tsk2 = call(stdsort.sort call(stdfu.apply new-tasks func(item) del(item 'id') end) compa)
_ = call(stddbc.assert eq(tsk1 tsk2) sprintf('differing: %v \n %v' tsk1 tsk2))
true
end
# --- test tasks import fail (tasks should stay as those were in store)
test-import-tasks-fail = proc()
store = call(new-simulated-store)
task-id-var = call(stdvar.new 100)
tasks-importer = call(uc.new-tasks-importer store task-id-var)
task-adder = call(uc.new-task-adder store task-id-var)
task-getter = call(uc.new-task-getter store)
old-tasks = list(
map(
'name' 'Carwash'
'description' 'Washing car'
)
map(
'name' 'Garage'
'description' 'Clean the garage'
)
map(
'name' 'Shopping'
'description' 'Drive with car to do shopping'
)
)
_ = call(stdfu.ploop proc(task _) call(task-adder map() task) end old-tasks 'none')
# read previous tasks
previous-tasks = call(task-getter map('query-map' map()) map())
tasks = list(
map(
'id' 1001
'name' 'task-A'
'description' 'text-A'
'tags' list('tag-A')
'state' 'ongoing'
'version' 'v100'
)
map(
'id' 1002
'name' 'task-B'
'description' 'text-B'
'tags' list('tag-B')
'state' 'THIS VALUE IS INVALID'
'version' 'v101'
)
map(
'id' 1003
'name' 'task-C'
'description' 'text-C'
'tags' list('tag-C')
'state' 'done'
'version' 'v102'
)
)
imp-ok imp-err _ = call(tasks-importer map() tasks):
new-tasks = call(task-getter map('query-map' map()) map())
compa = func(val1 val2)
gt(
conv(slice(get(val1 'version') 1) 'int')
conv(slice(get(val2 'version') 1) 'int')
)
end
tsk1 = call(stdsort.sort call(stdfu.apply previous-tasks func(item) del(item 'id') end) compa)
tsk2 = call(stdsort.sort call(stdfu.apply new-tasks func(item) del(item 'id') end) compa)
_ = call(stddbc.assert eq(tsk1 tsk2) sprintf('differing: %v \n %v' tsk1 tsk2))
true
end
main = proc()
tests-uc = list(
test-add-task-ok
test-add-task-fail-id-not-allowed
test-add-task-fail-in-store
test-add-task-fail-invalid-task-data
test-modify-task-ok
test-modify-task-fail-as-wrong-version
test-replace-task-ok
test-replace-task-fail-as-wrong-version
test-delete-task-ok
test-get-task-by-id
test-get-task-by-query
test-get-task-by-text-search
test-import-tasks-OK
test-import-tasks-fail
test-get-tags-OK
)
tests = extend(tests-uc call(domain.get-testcases))
test-runner = proc(tst-proc)
res = try(call(tst-proc))
test-result = cond(
eq(type(res) 'string') false
res
)
_ = if(test-result
print('PASS: ' tst-proc)
print('FAIL: ' tst-proc '\n' res)
)
test-result
end
tp-list = call(stdfu.proc-apply tests proc(tp) proc() call(test-runner tp) end end)
all-tests-ok = call(stdfu.ploop proc(tp prev-res) and(call(tp) prev-res) end tp-list true)
result = if( all-tests-ok
'PASS'
'FAILED'
)
result
end
endns