graphql-engine/server/testcases/check_constraint.json
2018-06-28 00:32:00 +05:30

269 lines
5.7 KiB
JSON

{
"description": "check constraint test",
"depends": [],
"items": [
{
"name": "create_schema",
"url": "/api/1/query",
"role": "admin",
"user_id": "1",
"status_code": 200,
"method": "POST",
"request": {
"kind": "create_table",
"body": {
"name": "user",
"columns": [
{
"type": "varchar",
"name": "name"
},
{
"type": "serial",
"name": "id"
}
],
"primary_key": [
"id"
],
"unique_constraints": [
{
"columns": [
"id",
"name"
]
}
]
}
}
},
{
"name": "create_schema",
"url": "/api/1/query",
"role": "admin",
"user_id": "1",
"status_code": 200,
"method": "POST",
"request": {
"kind": "create_table",
"body": {
"__type": "create_table",
"name": "author",
"columns": [
{
"type": "serial",
"name": "id"
},
{
"type": "varchar",
"name": "email"
},
{
"type": "varchar",
"name": "name"
},
{
"type": "integer",
"name": "auth_id"
}
],
"primary_key": [
"id"
],
"foreign_key_constraints": [
{
"mapping": {
"auth_id": "id",
"name": "name"
},
"columns": [
"auth_id",
"name"
],
"ref_table": "user",
"ref_columns": [
"id",
"name"
]
}
],
"check_constraints": [
{
"check": {
"$or": [
{
"email": {
"$like": "%@gmail.com"
}
}
]
}
}
],
"unique_constraints": [
{
"columns": [
"name",
"email"
]
}
]
}
}
},
{
"name": "create user Spock as admin",
"url": "/api/1/table/user/insert",
"role": "admin",
"user_id": "1",
"status_code": 200,
"request": {
"objects": [
{
"name": "Spock",
"id": 1
}
],
"returning": [
"id"
]
},
"response": {
"affected_rows": 1,
"returning": [
{
"id": 1
}
]
},
"method": "POST"
},
{
"name": "create user Vader as admin",
"url": "/api/1/table/user/insert",
"role": "admin",
"user_id": "1",
"status_code": 200,
"request": {
"objects": [
{
"name": "Vader",
"id": 2
}
],
"returning": [
"id"
]
},
"response": {
"affected_rows": 1,
"returning": [
{
"id": 2
}
]
},
"method": "POST"
},
{
"name": "create author Spock as admin",
"url": "/api/1/table/author/insert",
"role": "admin",
"user_id": "1",
"status_code": 200,
"request": {
"objects": [
{
"name": "Spock",
"auth_id": 1,
"email": "spock@gmail.com"
}
],
"returning": [
"id"
]
},
"response": {
"affected_rows": 1,
"returning": [
{
"id": 1
}
]
},
"method": "POST"
},
{
"name": "create author Vader as admin",
"url": "/api/1/table/author/insert",
"role": "admin",
"user_id": "1",
"status_code": 400,
"request": {
"objects": [
{
"name": "Vader",
"auth_id": 1,
"email": "vader@b56.com"
}
],
"returning": [
"id"
]
},
"method": "POST",
"response": {
"path": "$",
"error": "Check constraint violation. new row for relation \"author\" violates check constraint \"author_email_check\""
}
},
{
"name": "create Spock as admin with diff auth id",
"url": "/api/1/table/author/insert",
"role": "admin",
"user_id": "1",
"status_code": 400,
"request": {
"objects": [
{
"name": "Spock",
"auth_id": 1,
"email": "spock@gmail.com"
}
],
"returning": [
"id"
]
},
"response": {
"path": "$",
"error": "Uniqueness violation. duplicate key value violates unique constraint \"author_name_email_key\""
},
"method": "POST"
},
{
"name": "create Jack",
"url": "/api/1/table/author/insert",
"role": "admin",
"user_id": "1",
"status_code": 400,
"request": {
"objects": [
{
"name": "Jack",
"auth_id": 1,
"email": "jack@gmail.com"
}
],
"returning": [
"id"
]
},
"response": {
"path": "$",
"error": "Foreign key violation. insert or update on table \"author\" violates foreign key constraint \"author_auth_id_fkey\""
},
"method": "POST"
}
]
}