|
| 1 | +package test_api |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/sted/smoothdb/test" |
| 7 | +) |
| 8 | + |
| 9 | +// Tests for issue #15: Incorrect native type casting for boolean and null values |
| 10 | +// when filtering JSONB via `->` operator. |
| 11 | + |
| 12 | +func TestJSONBBoolNull(t *testing.T) { |
| 13 | + |
| 14 | + cmdConfig := test.Config{ |
| 15 | + BaseUrl: "http://localhost:8082/admin/databases", |
| 16 | + CommonHeaders: test.Headers{"Authorization": {adminToken}}, |
| 17 | + } |
| 18 | + |
| 19 | + commands := []test.Command{ |
| 20 | + { |
| 21 | + Method: "POST", |
| 22 | + Query: "/dbtest/tables", |
| 23 | + Body: `{ |
| 24 | + "name": "jsonb_bool_null", |
| 25 | + "columns": [ |
| 26 | + {"name": "id", "type": "int4", "notnull": true}, |
| 27 | + {"name": "data", "type": "jsonb"} |
| 28 | + ], |
| 29 | + "ifnotexists": true |
| 30 | + }`, |
| 31 | + }, |
| 32 | + } |
| 33 | + test.Prepare(cmdConfig, commands) |
| 34 | + |
| 35 | + testConfig := test.Config{ |
| 36 | + BaseUrl: "http://localhost:8082/api/dbtest", |
| 37 | + CommonHeaders: test.Headers{"Authorization": {adminToken}}, |
| 38 | + } |
| 39 | + |
| 40 | + tests := []test.Test{ |
| 41 | + { |
| 42 | + Description: "insert jsonb records with boolean and null values", |
| 43 | + Method: "POST", |
| 44 | + Query: "/jsonb_bool_null", |
| 45 | + Body: `[ |
| 46 | + {"id": 1, "data": {"f": true}}, |
| 47 | + {"id": 2, "data": {"f": false}}, |
| 48 | + {"id": 3, "data": {"g": null}} |
| 49 | + ]`, |
| 50 | + Status: 201, |
| 51 | + }, |
| 52 | + { |
| 53 | + Description: "can filter jsonb boolean true via arrow operator", |
| 54 | + Query: "/jsonb_bool_null?data->f=eq.true", |
| 55 | + Expected: `[{"id":1,"data":{"f": true}}]`, |
| 56 | + Status: 200, |
| 57 | + }, |
| 58 | + { |
| 59 | + Description: "can filter jsonb boolean false via arrow operator", |
| 60 | + Query: "/jsonb_bool_null?data->f=eq.false", |
| 61 | + Expected: `[{"id":2,"data":{"f": false}}]`, |
| 62 | + Status: 200, |
| 63 | + }, |
| 64 | + { |
| 65 | + Description: "can filter jsonb null via arrow operator", |
| 66 | + Query: "/jsonb_bool_null?data->g=eq.null", |
| 67 | + Expected: `[{"id":3,"data":{"g": null}}]`, |
| 68 | + Status: 200, |
| 69 | + }, |
| 70 | + } |
| 71 | + |
| 72 | + test.Execute(t, testConfig, tests) |
| 73 | +} |
0 commit comments