add tests for nested oneOf fromJSONString (#12740)

This commit is contained in:
William Cheng 2022-06-30 23:08:49 +08:00 committed by GitHub
parent 3a2bbbb850
commit 08108cc4ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,7 +15,6 @@ result <- pet_api$AddPet(pet)
test_that("AddPet", {
expect_equal(pet_id, 123321)
#expect_equal(result, NULL)
expect_equal(pet$toJSONString(), '{"id":123321,"category":{"id":450,"name":"test_cat"},"name":"name_test","photoUrls":["photo_test","second test"],"tags":[{"id":123,"name":"tag_test"},{"id":456,"name":"unknown"}],"status":"available"}')
})
@ -231,12 +230,17 @@ test_that("Tests oneOf", {
expect_error(Pig$new(instance = basque_pig), 'Failed to initialize Pig with oneOf schemas BasquePig, DanishPig. Provided class name: Pig')
# test nested oneOf
# test nested oneOf toJSONString
nested_oneof <- NestedOneOf$new()
nested_oneof$nested_pig <- pig
nested_oneof$size <- 15
expect_equal(nested_oneof$toJSONString(), '{"size":15,"nested_pig":{"className":"BasquePig","color":"red"}}')
# test fromJSONString with nested oneOf
nested_json_str <- '{"size":15,"nested_pig":{"className":"BasquePig","color":"red"}}'
nested_oneof2 <- NestedOneOf$new()$fromJSONString(nested_json_str)
expect_equal(nested_oneof2$toJSONString(), '{"size":15,"nested_pig":{"className":"BasquePig","color":"red"}}')
# test toString
expect_equal(as.character(jsonlite::minify(pig$toString())), "{\"actual_instance\":{\"className\":\"BasquePig\",\"color\":\"red\"},\"actual_type\":\"BasquePig\",\"one_of\":\"BasquePig, DanishPig\"}")
expect_equal(as.character(jsonlite::minify(Pig$new()$toString())), "{\"one_of\":\"BasquePig, DanishPig\"}")
@ -270,7 +274,7 @@ test_that("Tests anyOf", {
expect_equal(pig$actual_instance$size, 7)
expect_equal(pig$actual_instance$className, "DanishPig")
# test toJSON
# test toJSONString
expect_equal(danish_pig$toJSONString(), original_danish_pig$toJSONString())
basque_pig <- pig$fromJSON(basque_pig_json)