Skip to content

Commit 0cea308

Browse files
committed
✅ Add mongo values tests
1 parent 8deb767 commit 0cea308

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/test/resources/mongo-values.sk

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
test "mongo-values":
2+
set {_document} to mongo document
3+
set mongo value "playerName" of {_document} to "Romitou"
4+
set mongo value "coins" of {_document} to 100
5+
assert mongo json of {_document} is "{""playerName"": ""Romitou"", ""coins"": 100}" with "incorrect mongo value definition"
6+
7+
8+
set mongo list "fruitList" of {_document} to "kiwi", "pear"
9+
set mongo list "appleList" of {_document} to "apple", "apple"
10+
remove "apple" from mongo list "appleList" of {_document}
11+
assert mongo json of {_document} is "{""playerName"": ""Romitou"", ""coins"": 100, ""fruitList"": [""kiwi"", ""pear""], ""appleList"": [""apple""]}" with "incorrect mongo list definition"
12+
13+
set mongo list "appleList" of {_document} to "apple", "apple"
14+
remove all "apple" from mongo list "appleList" of {_document}
15+
assert mongo json of {_document} is "{""playerName"": ""Romitou"", ""coins"": 100, ""fruitList"": [""kiwi"", ""pear""], ""appleList"": []}" with "incorrect mongo list removal"
16+
17+
delete mongo value "coins" of {_document}
18+
assert mongo json of {_document} is "{""playerName"": ""Romitou"", ""fruitList"": [""kiwi"", ""pear""], ""appleList"": [""apple""]}" with "incorrect mongo value deletion"
19+
20+
add "banana" to mongo list "fruitList" of {_document}
21+
assert mongo json of {_document} is "{""playerName"": ""Romitou"", ""fruitList"": [""kiwi"", ""pear"", ""banana""], ""appleList"": []}" with "incorrect mongo list addition"
22+
23+
set {_fruits::*} to "orange", "grape"
24+
add {_fruits::*} to mongo list "fruitList" of {_document}
25+
assert mongo json of {_document} is "{""playerName"": ""Romitou"", ""fruitList"": [""kiwi"", ""pear"", ""banana"", ""orange"", ""grape""], ""appleList"": []}" with "incorrect mongo list addition with list"
26+
27+
remove "kiwi" from mongo list "fruitList" of {_document}
28+
assert mongo json of {_document} is "{""playerName"": ""Romitou"", ""fruitList"": [""pear"", ""banana"", ""orange"", ""grape""], ""appleList"": []}" with "incorrect mongo list removal"
29+
30+
remove all {_fruits::*} from mongo list "fruitList" of {_document}
31+
assert mongo json of {_document} is "{""playerName"": ""Romitou"", ""fruitList"": [""pear""], ""appleList"": []}" with "incorrect mongo list removal with list"
32+
33+
test "mongo-embedded-values":
34+
set {_document} to mongo document
35+
set mongo embedded value "stats.wins" of {_document} to 42
36+
set mongo embedded value "stats.losses" of {_document} to 10
37+
assert mongo json of {_document} is "{\"stats\":{\"wins\":42,\"losses\":10}}" with "incorrect embedded value definition"
38+
39+
delete mongo embedded value "stats.losses" of {_document}
40+
assert mongo json of {_document} is "{\"stats\":{\"wins\":42}}" with "embedded value deletion failed"
41+
42+
set {_document} to mongo document
43+
set mongo embedded value "inventory[0].name" of {_document} to "Sword"
44+
set mongo embedded value "inventory[0].power" of {_document} to 5
45+
set mongo embedded value "inventory[1].name" of {_document} to "Shield"
46+
set mongo embedded value "inventory[1].defense" of {_document} to 12
47+
assert mongo json of {_document} is "{\"inventory\":[{\"name\":\"Sword\",\"power\":5},{\"name\":\"Shield\",\"defense\":12}]}" with "incorrect nested array definition"
48+
49+
set mongo embedded value "inventory[1].defense" of {_document} to 15
50+
assert mongo json of {_document} is "{\"inventory\":[{\"name\":\"Sword\",\"power\":5},{\"name\":\"Shield\",\"defense\":15}]}" with "embedded array element update failed"
51+
52+
set {_document} to mongo document
53+
set mongo embedded value "newList[2]" of {_document} to "filled"
54+
assert mongo json of {_document} is "{\"newList\":[null,null,\"filled\"]}" with "list auto-fill failed"

0 commit comments

Comments
 (0)