Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(openapi/validate): cleanup 🧹 #520

Merged
merged 23 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9ee396c
chore(deps): install ora
kanadgupta Jun 17, 2022
97e7678
chore: add ora to dependabot and reformat
kanadgupta Jun 17, 2022
0ad8d64
feat: add spinner for file validation
kanadgupta Jun 17, 2022
7051783
feat: initial registry upload function
kanadgupta Jun 17, 2022
813b158
refactor: move ora opts into shared function
kanadgupta Jun 22, 2022
574d2a9
refactor: use shared ora opts in new function also
kanadgupta Jun 22, 2022
f53b758
feat: first pass at rewriting openapi command to support new flow
kanadgupta Jun 22, 2022
e58a092
chore: making the spinners spin
kanadgupta Jun 22, 2022
8a748db
test: refactor existing tests to work with new flow
kanadgupta Jun 23, 2022
7836b05
test: fix error code in test
kanadgupta Jun 23, 2022
3970905
test: adding coverage for PUT endpoint error handling
kanadgupta Jun 23, 2022
73870f2
chore: move two tests under describe block
kanadgupta Jun 23, 2022
5ecce6d
test: add coverage for if registry endpoint fails
kanadgupta Jun 23, 2022
51a5ebb
chore: fix typo in test
kanadgupta Jun 23, 2022
0327f34
chore: remove unnecessary error handling
kanadgupta Jun 23, 2022
56489df
chore: test coverage in ora opts
kanadgupta Jun 23, 2022
5195fc8
Merge branch 'kanad/rm-4367-update-rdme-to-support-new-oas-upload' in…
kanadgupta Jun 23, 2022
ab5f313
chore: oops
kanadgupta Jun 23, 2022
d86369e
chore: spinner language
kanadgupta Jun 23, 2022
fe72f41
Merge branch 'kanad/rm-4367-update-rdme-to-support-new-oas-upload' in…
kanadgupta Jun 23, 2022
6ab51a3
Merge branch 'main' into openapi/test-housekeeping
kanadgupta Jun 23, 2022
27a997e
test: remove unused prompt handler
kanadgupta Jun 23, 2022
fba4df5
chore: add test TODO
kanadgupta Jun 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions __tests__/__fixtures__/invalid-ref-oas/external-components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{
"requestBodies": {
"Pet": {
"content": {
"application/json": {
"schema": {
"$ref": "#/schemas/Pet"
}
},
"application/xml": {
"schema": {
"$ref": "#/schemas/Pet"
}
}
},
"description": "Pet object that needs to be added to the store",
"required": true
}
},
"schemas": {
"Order": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"petId": {
"type": "integer",
"format": "int64"
},
"quantity": {
"type": "integer",
"format": "int32"
},
"shipDate": {
"type": "string",
"format": "date-time"
},
"status": {
"type": "string",
"description": "Order Status",
"enum": [
"placed",
"approved",
"delivered"
]
},
"complete": {
"type": "boolean",
"default": false
}
},
"xml": {
"name": "Order"
}
},
"Category": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
},
"xml": {
"name": "Category"
}
},
"User": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"username": {
"type": "string"
},
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"email": {
"type": "string"
},
"password": {
"type": "string"
},
"phone": {
"type": "string"
},
"userStatus": {
"type": "integer",
"format": "int32",
"description": "User Status"
}
},
"xml": {
"name": "User"
}
},
"Tag": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
},
"xml": {
"name": "Tag"
}
},
"Pet": {
"type": "object",
"required": [
"name",
"photoUrls"
],
"properties": {
"id": {
"type": "integer",
"format": "int64",
"default": 40,
"example": 25
},
"category": {
"$ref": "#/schemas/Category"
},
"name": {
"type": "string",
"example": "doggie"
},
"photoUrls": {
"type": "array",
"xml": {
"name": "photoUrl",
"wrapped": true
},
"items": {
"type": "string",
"example": "https://example.com/photo.png"
}
},
"tags": {
"type": "array",
"xml": {
"name": "tag",
"wrapped": true
},
"items": {
"$ref": "#/schemas/Tag"
}
},
"status": {
"type": "string",
"description": "pet status in the store",
"enum": [
"available",
"pending",
"sold"
]
}
},
"xml": {
"name": "Pet"
}
}
}
}
132 changes: 132 additions & 0 deletions __tests__/__fixtures__/invalid-ref-oas/petstore.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Example petstore to demo our handling of external $ref pointers"
},
"servers": [
{
"url": "http://petstore.swagger.io/v2"
}
],
"paths": {
"/pet": {
"post": {
"tags": ["pet"],
"summary": "Add a new pet to the store",
"description": "",
"operationId": "addPet",
"requestBody": {
"$ref": "__tests__/__fixtures__/ref-oas/external-components.json#/requestBodies/Petty"
},
"responses": {
"405": {
"description": "Invalid input"
}
},
"security": [
{
"petstore_auth": ["write:pets", "read:pets"]
}
]
},
"put": {
"tags": ["pet"],
"summary": "Update an existing pet",
"description": "",
"operationId": "updatePet",
"requestBody": {
"$ref": "__tests__/__fixtures__/ref-oas/external-components.json#/requestBodies/Petty"
},
"responses": {
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "Pet not found"
},
"405": {
"description": "Validation exception"
}
},
"security": [
{
"petstore_auth": ["write:pets", "read:pets"]
}
]
}
},
"/pet/{petId}": {
"get": {
"tags": ["pet"],
"summary": "Find pet by ID",
"description": "Returns a single pet",
"operationId": "getPetById",
"parameters": [
{
"name": "petId",
"in": "path",
"description": "ID of pet to return",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/xml": {
"schema": {
"$ref": "__tests__/__fixtures__/ref-oas/external-components.json#/schemas/Petty"
}
},
"application/json": {
"schema": {
"$ref": "__tests__/__fixtures__/ref-oas/external-components.json#/schemas/Petty"
}
}
}
},
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "Pet not found"
},
"default": {
"description": "successful response"
}
},
"security": [
{
"api_key": []
}
]
}
}
},
"components": {
"securitySchemes": {
"petstore_auth": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
}
},
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header"
}
}
}
}
6 changes: 4 additions & 2 deletions __tests__/cmds/__snapshots__/openapi.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ REQUIRED must have required property 'name'
29 | }]
`;

exports[`rdme openapi should bundle and upload the expected content 1`] = `
exports[`rdme openapi error handling should throw an error if an invalid ref is supplied 1`] = `[MissingPointerError: Token "Petty" does not exist.]`;

exports[`rdme openapi upload should bundle and upload the expected content 1`] = `
Object {
"components": Object {
"securitySchemes": Object {
Expand Down Expand Up @@ -250,7 +252,7 @@ Object {
}
`;

exports[`rdme openapi should use specified working directory and upload the expected content 1`] = `
exports[`rdme openapi upload should use specified working directory and upload the expected content 1`] = `
Object {
"components": Object {
"securitySchemes": Object {
Expand Down
28 changes: 14 additions & 14 deletions __tests__/cmds/__snapshots__/validate.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`rdme validate error handling should throw an error if an in valid Swagger definition is supplied 1`] = `
[SyntaxError: Swagger schema validation failed.

ADDITIONAL PROPERTY must NOT have additional properties

23 | "description": "Find out more",
24 | "url": "http://swagger.io",
> 25 | "this-shouldnt-be-here": true
| ^^^^^^^^^^^^^^^^^^^^^^^ 😲 this-shouldnt-be-here is not expected to be here!
26 | }
27 | }
28 | ],]
`;

exports[`rdme validate error handling should throw an error if an invalid OpenAPI 3.1 definition is supplied 1`] = `
[SyntaxError: OpenAPI schema validation failed.

Expand All @@ -27,3 +13,17 @@ REQUIRED must have required property 'name'
28 | }
29 | }]
`;

exports[`rdme validate error handling should throw an error if an invalid Swagger definition is supplied 1`] = `
[SyntaxError: Swagger schema validation failed.

ADDITIONAL PROPERTY must NOT have additional properties

23 | "description": "Find out more",
24 | "url": "http://swagger.io",
> 25 | "this-shouldnt-be-here": true
| ^^^^^^^^^^^^^^^^^^^^^^^ 😲 this-shouldnt-be-here is not expected to be here!
26 | }
27 | }
28 | ],]
`;
Loading