summaryrefslogtreecommitdiff
path: root/lib/query/tests/insert.t
diff options
context:
space:
mode:
Diffstat (limited to 'lib/query/tests/insert.t')
-rw-r--r--lib/query/tests/insert.t213
1 files changed, 213 insertions, 0 deletions
diff --git a/lib/query/tests/insert.t b/lib/query/tests/insert.t
new file mode 100644
index 0000000..236bb97
--- /dev/null
+++ b/lib/query/tests/insert.t
@@ -0,0 +1,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}