Skip to content

Commit 1a647b2

Browse files
committed
add regression tests for the basic lapis types
1 parent b361be5 commit 1a647b2

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
luarocks install busted
2626
luarocks install moonscript
2727
luarocks install lua-cjson
28+
luarocks install lapis
2829
luarocks make
2930
3031
- name: test

spec/json_schema_spec.moon

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import to_json_schema, simplify, JsonSchema from require "tableshape.json_schema
22
import types from require "tableshape"
33

44
describe "tableshape.json_schema", ->
5-
65
describe "simplify", ->
76
it "passes through plain string", ->
87
result = simplify\transform "hello"
@@ -740,3 +739,75 @@ describe "tableshape.json_schema", ->
740739
it "converts number with description", ->
741740
result = to_json_schema\transform types.number\describe "the count"
742741
assert.same {type: "number", description: "the count"}, result
742+
743+
describe "lapis", ->
744+
local model, types
745+
before_each ->
746+
model = require "lapis.db.base_model"
747+
types = require "lapis.validate.types"
748+
749+
it "converts db_id to json schema", ->
750+
assert.same {
751+
type: "number"
752+
description: "database ID integer"
753+
}, to_json_schema\transform types.db_id
754+
755+
it "converts enum to json schema", ->
756+
statuses = model.enum {
757+
default: 1
758+
banned: 2
759+
deleted: 3
760+
}
761+
762+
statuses_t = types.db_enum statuses
763+
assert.same {
764+
type: "string"
765+
description: "enum(default, banned, deleted)"
766+
enum: {
767+
"default"
768+
"banned"
769+
"deleted"
770+
}
771+
}, to_json_schema\transform statuses_t
772+
773+
it "converts valid_text to json schema", ->
774+
assert.same {
775+
type: "string"
776+
description: "valid text"
777+
}, to_json_schema\transform types.valid_text
778+
779+
it "converts cleaned_text to json schema", ->
780+
assert.same {
781+
type: "string"
782+
description: "text"
783+
}, to_json_schema\transform types.cleaned_text
784+
785+
it "converts empty to json schema", ->
786+
assert.same {
787+
type: "null"
788+
description: "empty"
789+
}, to_json_schema\transform types.empty
790+
791+
it "converts trimmed_text to json schema", ->
792+
assert.same {
793+
type: "string"
794+
description: "valid text"
795+
}, to_json_schema\transform types.trimmed_text
796+
797+
it "converts truncated_text to json schema", ->
798+
assert.same {
799+
type: "string"
800+
description: "valid text"
801+
}, to_json_schema\transform types.truncated_text 10
802+
803+
it "converts limited_text to json schema", ->
804+
assert.same {
805+
type: "string"
806+
description: "text between 1 and 20 characters"
807+
}, to_json_schema\transform types.limited_text 20
808+
809+
it "converts limited_text with minimum length to json schema", ->
810+
assert.same {
811+
type: "string"
812+
description: "text between 5 and 20 characters"
813+
}, to_json_schema\transform types.limited_text 20, 5

0 commit comments

Comments
 (0)