Files
swagger-ui/test/unit/core/plugins/oas3/helpers.js
Tim Lai 1a27c0a8bd feat: migrate unit tests to Jest (#6353)
* config(jest): updated setup
* config(jest): update testMatch to include jsx files
* config(jest): add transformIgnorePatterns
* config(jest): update ignore files that do not work in jest yet
* config: add test:unit-jest to test script

* fix(jest): lint with eslint-plugin-jest

* refactor(jest): move unit test directory
* refactor(mocha): restore mocha tests that fail in jest

* docs(jest): update helpful scripts with test:unit-jest
2020-09-01 10:41:01 -07:00

68 lines
2.2 KiB
JavaScript

import { fromJS } from "immutable"
import { isOAS3, isSwagger2 } from "corePlugins/oas3/helpers"
const isOAS3Shorthand = (version) => isOAS3(fromJS({
openapi: version
}))
const isSwagger2Shorthand = (version) => isSwagger2(fromJS({
swagger: version
}))
describe("isOAS3", function () {
it("should recognize valid OAS3 version values", function () {
expect(isOAS3Shorthand("3.0.0")).toEqual(true)
expect(isOAS3Shorthand("3.0.1")).toEqual(true)
expect(isOAS3Shorthand("3.0.11111")).toEqual(true)
expect(isOAS3Shorthand("3.0.0-rc0")).toEqual(true)
})
it("should fail for invalid OAS3 version values", function () {
expect(isOAS3Shorthand("3.0")).toEqual(false)
expect(isOAS3Shorthand("3.0.")).toEqual(false)
expect(isOAS3Shorthand("2.0")).toEqual(false)
})
it("should gracefully fail for non-string values", function () {
expect(isOAS3Shorthand(3.0)).toEqual(false)
expect(isOAS3Shorthand(3)).toEqual(false)
expect(isOAS3Shorthand({})).toEqual(false)
expect(isOAS3Shorthand(null)).toEqual(false)
})
it("should gracefully fail when `openapi` field is missing", function () {
expect(isOAS3(fromJS({
openApi: "3.0.0"
}))).toEqual(false)
expect(isOAS3Shorthand(null)).toEqual(false)
})
})
describe("isSwagger2", function () {
it("should recognize valid Swagger 2.0 version values", function () {
expect(isSwagger2Shorthand("2.0")).toEqual(true)
expect(isSwagger2Shorthand("2.0-rc0")).toEqual(true)
})
it("should fail for invalid Swagger 2.0 version values", function () {
expect(isSwagger2Shorthand("3.0")).toEqual(false)
expect(isSwagger2Shorthand("3.0.")).toEqual(false)
expect(isSwagger2Shorthand("2.1")).toEqual(false)
expect(isSwagger2Shorthand("1.2")).toEqual(false)
expect(isSwagger2Shorthand("2")).toEqual(false)
})
it("should gracefully fail for non-string values", function () {
expect(isSwagger2Shorthand(2.0)).toEqual(false)
expect(isSwagger2Shorthand(2)).toEqual(false)
expect(isSwagger2Shorthand({})).toEqual(false)
expect(isSwagger2Shorthand(null)).toEqual(false)
})
it("should gracefully fail when `swagger` field is missing", function () {
expect(isSwagger2(fromJS({
Swagger: "2.0"
}))).toEqual(false)
})
})