summaryrefslogtreecommitdiff
path: root/lib/query/tests/insert.t
blob: 236bb97997db8f7c7d408c6172016b05e59bfa5c (plain)
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
Test the capacity to insert elements in the database according a specific
schema

The data to insert is given in the json format. This format is a subset from the
configuration (for example we can’t have a property with the same name as a
subcontent)

Minimal exemple, a content without any field does not have any value:

  $ tests -insert <<EOF
  > {
  >   "content": [
  >     {
  >       "id": "entity",
  >       "values": [ {} ]
  >     }
  >   ]
  > }
  > EOF
  entity:1
    {}

Ensure an error is raised if the value does not match the expected type.

Here, the year is declared as an integer, but the value is provided as string.
This error is expected to be checked and reported.

  $ tests -insert <<EOF
  > {
  >   "content": [
  >     {
  >       "id": "entity",
  >       "section": [
  >         {
  >           "field": [
  >             {
  >               "name": "year",
  >               "label": {},
  >               "type": "integer"
  >             }
  >           ]
  >         }
  >       ],
  >       "values": [ { "year": "1234", } ]
  >     }
  >   ]
  > }
  > EOF
  Fatal error: exception Query__Insert.TypeMismatch
  [2]

  $ tests -insert <<EOF
  > {
  >   "content": [
  >     {
  >       "id": "entity",
  >       "section": [
  >         {
  >           "field": [
  >             {
  >               "name": "name",
  >               "label": {},
  >               "type": "text",
  >               "required": true
  >             },
  >             {
  >               "name": "year",
  >               "label": {},
  >               "type": "integer"
  >             }
  >           ]
  >         }
  >       ],
  >       "values": [
  >         {
  >           "name": "name",
  >           "year": 1234,
  >         }
  >       ]
  >     }
  >   ]
  > }
  > EOF
  entity:1
    {"name":"name","year":1234}

Any value can be omitted and will be replaced by the default value:
  $ tests -insert <<EOF
  > {
  >   "content": [
  >     {
  >       "id": "entity",
  >       "section": [
  >         {
  >           "field": [
  >             {
  >               "name": "year",
  >               "label": {},
  >               "type": "integer",
  >             }
  >           ]
  >         }
  >       ],
  >       "values": [ {} ]
  >     }
  >   ]
  > }
  > EOF
  entity:1
    {"year":null}

If the field is "required" the value is still inserted: the requirement feature
is only functionnal; this shall not block the creation of the content.

  $ tests -insert <<EOF
  > {
  >   "content": [
  >     {
  >       "id": "entity",
  >       "section": [
  >         {
  >           "field": [
  >             {
  >               "name": "year",
  >               "label": {},
  >               "type": "integer",
  >               "required": true,
  >             }
  >           ]
  >         }
  >       ],
  >       "values": [ {} ]
  >     }
  >   ]
  > }
  > EOF
  entity:1
    {"year":null}

A subcontent is linked to the parent:

  $ tests -insert <<EOF
  > {
  >   "content": [
  >     {
  >       "id": "referential",
  >     },
  >     {
  >       "id": "entity",
  >        "section": [
  >          {
  >            "field": [
  >              {
  >                "name": "idx",
  >                "label": {},
  >                "type": "integer"
  >              },
  >              {
  >                "name": "ref",
  >                "label": {},
  >                "type": {
  >                  "content": "referential",
  >                  "multivaluated": true
  >                }
  >              }
  >            ]
  >          }
  >        ],
  >       "subcontent": [
  >         {
  >           "id": "details",
  >           "section": [
  >             {
  >               "field": [
  >                 {
  >                   "name": "comment",
  >                   "label": {},
  >                   "type": "text"
  >                 },
  >               ]
  >             }
  >           ],
  >         }
  >       ],
  >       "values": [
  >         {
  >           "idx": 1,
  >           "details": [
  >             {"comment": "lorem"},
  >             {"comment": "ipsum"}
  >           ]
  >         },
  >         {
  >           "idx": 2,
  >           "details": [
  >             {"comment": "lorem 2"},
  >           ]
  >         }
  >       ]
  >     }
  >   ]
  > }
  > EOF
  entity:1
    {"idx":1}
  details:1
    {"comment":"lorem","parent":1}
  details:2
    {"comment":"ipsum","parent":1}
  entity:2
    {"idx":2}
  details:3
    {"comment":"lorem 2","parent":2}