import { convertToObject } from "." ; import { yml as case2_yml } from "./fixtures/case2" ; describe ( "convertToObject / convertable" , ( ) => { it ( "undefined" , ( ) => { const src = undefined ; const result = convertToObject ( src ) ; expect ( result ) . toMatchInlineSnapshot ( `undefined` ) ; } ) ; it ( "empty string" , ( ) => { const src = `` ; const result = convertToObject ( src ) ; expect ( result ) . toMatchInlineSnapshot ( `undefined` ) ; } ) ; it ( "no swagger string" , ( ) => { const src = `any string literal` ; const result = convertToObject ( src ) ; expect ( result ) . toMatchInlineSnapshot ( `undefined` ) ; } ) ; it ( "yaml string" , ( ) => { const src = `
swagger: "2.0"
info:
  title: Simple API overview
paths:
  /:
    get:
      operationId: listVersionsv2
      produces:
      - application/json
      responses:
        "200":
          description: |-
            200 300 response
consumes:
- application/json
` ; const result = convertToObject ( src ) ; expect ( result ) . toMatchInlineSnapshot ( `
      Object {
        "consumes": Array [
          "application/json",
        ],
        "info": Object {
          "title": "Simple API overview",
        },
        "paths": Object {
          "/": Object {
            "get": Object {
              "operationId": "listVersionsv2",
              "produces": Array [
                "application/json",
              ],
              "responses": Object {
                "200": Object {
                  "description": "200 300 response",
                },
              },
            },
          },
        },
        "swagger": "2.0",
      }
    ` ) ; } ) ; it ( "yaml string case2" , ( ) => { const result = convertToObject ( case2_yml ) ; expect ( result ) . toMatchSnapshot ( ) ; } ) ; it ( "json string" , ( ) => { const src = `
{
  "a": "a",
  "b": 2,
  "cc": null,
}
` ; const result = convertToObject ( src ) ; expect ( result ) . toMatchInlineSnapshot ( `
      Object {
        "a": "a",
        "b": 2,
        "cc": null,
      }
    ` ) ; } ) ; } ) ; describe ( "convertToObject / broken string" , ( ) => { describe ( "broken json string" , ( ) => { it ( "case:1" , ( ) => { const src = `
{
  "a": "a",
  "b": 2,
  "cc": null,
` ; expect ( ( ) => { convertToObject ( src ) ; } ) . toThrowErrorMatchingInlineSnapshot ( `
        "unexpected end of the stream within a flow collection (6:1)

         3 |   \\"a\\": \\"a\\",
         4 |   \\"b\\": 2,
         5 |   \\"cc\\": null,
         6 | 
        -----^"
      ` ) ; } ) ; it ( "case:2" , ( ) => { const src = `
{
  "a": "a"
  "b": 2,
  "cc": null,
}
` ; expect ( ( ) => { convertToObject ( src ) ; } ) . toThrowErrorMatchingInlineSnapshot ( `
        "missed comma between flow collection entries (4:3)

         1 | 
         2 | {
         3 |   \\"a\\": \\"a\\"
         4 |   \\"b\\": 2,
        -------^
         5 |   \\"cc\\": null,
         6 | }"
      ` ) ; } ) ; } ) ; describe ( "broken yaml string" , ( ) => { it ( "case:1" , ( ) => { const src = `
swagger: "2.0"
info:
                title: Simple API overview
paths:
  /:
    get: operationId: listVersionsv2
      produces:
      - application/json
      responses:
        "200":
          description: |-
            200 300 response
consumes:
- application/json
` ; expect ( ( ) => { convertToObject ( src ) ; } ) . toThrowErrorMatchingInlineSnapshot ( `
        "bad indentation of a mapping entry (7:21)

         4 |                 title: Simple API overview
         5 | paths:
         6 |   /:
         7 |     get: operationId: listVersionsv2
        -------------------------^
         8 |       produces:
         9 |       - application/json"
      ` ) ; } ) ; it ( "case:2" , ( ) => { const src = `
swagger: "2.0"
info:
  title: Simple API overview
paths:
  /:
    get:
              operationId: listVersionsv2
      produces:
application/json
      responses:
        "200":
          description: |-
            200 300 response
consumes:

` ; expect ( ( ) => { convertToObject ( src ) ; } ) . toThrowErrorMatchingInlineSnapshot ( `
        "bad indentation of a mapping entry (9:7)

          6 |   /:
          7 |     get:
          8 |               operationId: listVersionsv2
          9 |       produces:
        ------------^
         10 | application/json
         11 |       responses:"
      ` ) ; } ) ; } ) ; } ) ;