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): rewrite tests to be more comprehensive #1188

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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: 164 additions & 15 deletions __tests__/commands/openapi/__snapshots__/validate.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`rdme openapi validate > CI tests > should fail if user attempts to pass \`--github\` flag in CI environment 1`] = `
[Error: Parsing --github
The \`--github\` flag is only for usage in non-CI environments.
See more help with --help]
`;

exports[`rdme openapi validate > CI tests > should successfully validate prompt and not run GHA onboarding 1`] = `
{
"result": "__tests__/__fixtures__/petstore-simple-weird-version.json is a valid OpenAPI API definition!",
"stderr": "- Validating the API definition located at __tests__/__fixtures__/petstore-simple-weird-version.json...
",
"stdout": "",
}
`;

exports[`rdme openapi validate > GHA onboarding E2E tests > should create GHA workflow if user passes in spec via opt (github flag enabled) 1`] = `
"
{
"result": "
Your GitHub Actions workflow file has been created! ✨

Almost done! Push your newly created file (.github/workflows/validate-test-opt-spec-github-file.yml) to GitHub and you're all set 🚀

🦉 If you have any more questions, feel free to drop us a line! [email protected]
"
",
"stderr": "- Validating the API definition located at __tests__/__fixtures__/petstore-simple-weird-version.json...
",
"stdout": "__tests__/__fixtures__/petstore-simple-weird-version.json is a valid OpenAPI API definition!

🚀 Let's get you set up with GitHub Actions! 🚀

",
}
`;

exports[`rdme openapi validate > GHA onboarding E2E tests > should create GHA workflow if user passes in spec via opt (github flag enabled) 2`] = `
Expand Down Expand Up @@ -38,13 +62,26 @@ jobs:
`;

exports[`rdme openapi validate > GHA onboarding E2E tests > should create GHA workflow if user passes in spec via opt (including workingDirectory) 1`] = `
"
{
"result": "
Your GitHub Actions workflow file has been created! ✨

Almost done! Push your newly created file (.github/workflows/validate-test-opt-spec-workdir-file.yml) to GitHub and you're all set 🚀

🦉 If you have any more questions, feel free to drop us a line! [email protected]
"
",
"stderr": "- Validating the API definition located at petstore.json...
",
"stdout": "petstore.json is a valid OpenAPI API definition!

🐙 Looks like you're running this command in a GitHub Repository! 🐙

🚀 With a few quick clicks, you can run this \`openapi validate\` command via GitHub Actions (https://github.com/features/actions)

✨ This means it will run automagically with every push to a branch of your choice!

",
}
`;

exports[`rdme openapi validate > GHA onboarding E2E tests > should create GHA workflow if user passes in spec via opt (including workingDirectory) 2`] = `
Expand Down Expand Up @@ -75,13 +112,26 @@ jobs:
`;

exports[`rdme openapi validate > GHA onboarding E2E tests > should create GHA workflow if user passes in spec via opt 1`] = `
"
{
"result": "
Your GitHub Actions workflow file has been created! ✨

Almost done! Push your newly created file (.github/workflows/validate-test-opt-spec-file.yml) to GitHub and you're all set 🚀

🦉 If you have any more questions, feel free to drop us a line! [email protected]
"
",
"stderr": "- Validating the API definition located at __tests__/__fixtures__/petstore-simple-weird-version.json...
",
"stdout": "__tests__/__fixtures__/petstore-simple-weird-version.json is a valid OpenAPI API definition!

🐙 Looks like you're running this command in a GitHub Repository! 🐙

🚀 With a few quick clicks, you can run this \`openapi validate\` command via GitHub Actions (https://github.com/features/actions)

✨ This means it will run automagically with every push to a branch of your choice!

",
}
`;

exports[`rdme openapi validate > GHA onboarding E2E tests > should create GHA workflow if user passes in spec via opt 2`] = `
Expand Down Expand Up @@ -112,13 +162,27 @@ jobs:
`;

exports[`rdme openapi validate > GHA onboarding E2E tests > should create GHA workflow if user passes in spec via prompts 1`] = `
"
{
"result": "
Your GitHub Actions workflow file has been created! ✨

Almost done! Push your newly created file (.github/workflows/validate-test-file.yml) to GitHub and you're all set 🚀

🦉 If you have any more questions, feel free to drop us a line! [email protected]
"
",
"stderr": "- Looking for API definitions...
- Validating the API definition located at __tests__/__fixtures__/petstore-simple-weird-version.json...
",
"stdout": "__tests__/__fixtures__/petstore-simple-weird-version.json is a valid OpenAPI API definition!

🐙 Looks like you're running this command in a GitHub Repository! 🐙

🚀 With a few quick clicks, you can run this \`openapi validate\` command via GitHub Actions (https://github.com/features/actions)

✨ This means it will run automagically with every push to a branch of your choice!

",
}
`;

exports[`rdme openapi validate > GHA onboarding E2E tests > should create GHA workflow if user passes in spec via prompts 2`] = `
Expand Down Expand Up @@ -148,8 +212,27 @@ jobs:
"
`;

exports[`rdme openapi validate > GHA onboarding E2E tests > should reject if user says no to creating GHA workflow 1`] = `
{
"error": [Error: GitHub Actions workflow creation cancelled. If you ever change your mind, you can run this command again with the \`--github\` flag.],
"stderr": "- Looking for API definitions...
- Validating the API definition located at __tests__/__fixtures__/petstore-simple-weird-version.json...
",
"stdout": "__tests__/__fixtures__/petstore-simple-weird-version.json is a valid OpenAPI API definition!

🐙 Looks like you're running this command in a GitHub Repository! 🐙

🚀 With a few quick clicks, you can run this \`openapi validate\` command via GitHub Actions (https://github.com/features/actions)

✨ This means it will run automagically with every push to a branch of your choice!

",
}
`;

exports[`rdme openapi validate > error handling > should throw an error if an invalid API definition has many errors 1`] = `
[SyntaxError: OpenAPI schema validation failed.
{
"error": [SyntaxError: OpenAPI schema validation failed.

REQUIRED must have required property 'url'

Expand All @@ -169,13 +252,27 @@ ADDITIONAL PROPERTY must NOT have additional properties
| ^^^^^^^ tagss is not expected to be here!
27 | "pet"
28 | ],
29 | "summary": "Finds Pets by status",]
29 | "summary": "Finds Pets by status",],
"stderr": "- Validating the API definition located at ./__tests__/__fixtures__/very-invalid-oas.json...
✖ Validating the API definition located at ./__tests__/__fixtures__/very-invalid-oas.json...
",
"stdout": "",
}
`;

exports[`rdme openapi validate > error handling > should throw an error if an invalid OpenAPI 3.0 definition is supplied 1`] = `[MissingPointerError: Token "Error" does not exist.]`;
exports[`rdme openapi validate > error handling > should throw an error if an invalid OpenAPI 3.0 definition is supplied 1`] = `
{
"error": [MissingPointerError: Token "Error" does not exist.],
"stderr": "- Validating the API definition located at ./__tests__/__fixtures__/invalid-oas.json...
✖ Validating the API definition located at ./__tests__/__fixtures__/invalid-oas.json...
",
"stdout": "",
}
`;

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

REQUIRED must have required property 'name'

Expand All @@ -185,11 +282,17 @@ REQUIRED must have required property 'name'
| ^ name is missing here!
27 | "type": "mutualTLS"
28 | }
29 | }]
29 | }],
"stderr": "- Validating the API definition located at ./__tests__/__fixtures__/invalid-oas-3.1.json...
✖ Validating the API definition located at ./__tests__/__fixtures__/invalid-oas-3.1.json...
",
"stdout": "",
}
`;

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

ADDITIONAL PROPERTY must NOT have additional properties

Expand All @@ -199,5 +302,51 @@ ADDITIONAL PROPERTY must NOT have additional properties
| ^^^^^^^^^^^^^^^^^^^^^^^ this-shouldnt-be-here is not expected to be here!
26 | }
27 | }
28 | ],]
28 | ],],
"stderr": "- Validating the API definition located at ./__tests__/__fixtures__/invalid-swagger.json...
✖ Validating the API definition located at ./__tests__/__fixtures__/invalid-swagger.json...
",
"stdout": "",
}
`;

exports[`rdme openapi validate > error handling > should throw an error if invalid JSON is supplied 1`] = `
{
"error": [SyntaxError: Unexpected end of JSON input],
"stderr": "- Validating the API definition located at ./__tests__/__fixtures__/invalid-json/yikes.json...
✖ Validating the API definition located at ./__tests__/__fixtures__/invalid-json/yikes.json...
",
"stdout": "",
}
`;

exports[`rdme openapi validate > should adhere to .gitignore in subdirectories 1`] = `
{
"result": "nest/petstore.json is a valid OpenAPI API definition!",
"stderr": "- Looking for API definitions...
- Validating the API definition located at nest/petstore.json...
",
"stdout": "ℹ️ We found nest/petstore.json and are attempting to validate it.
",
}
`;

exports[`rdme openapi validate > should discover and upload an API definition if none is provided 1`] = `
{
"result": "petstore.json is a valid OpenAPI API definition!",
"stderr": "- Looking for API definitions...
- Validating the API definition located at petstore.json...
",
"stdout": "ℹ️ We found petstore.json and are attempting to validate it.
",
}
`;

exports[`rdme openapi validate > should use specified working directory 1`] = `
{
"result": "petstore.json is a valid OpenAPI API definition!",
"stderr": "- Validating the API definition located at petstore.json...
",
"stdout": "",
}
`;
Loading
Loading