-
Notifications
You must be signed in to change notification settings - Fork 159
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
(followup): add tests for playground validation messages #4283
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
569b185
add validation around selectable environments for playground settings
RohinBhargava 71f63f0
add explicit not null check
RohinBhargava 387c7ec
move to rule
RohinBhargava 8fc91c2
beat linter
RohinBhargava 834f08d
simplify conditions
RohinBhargava 715427d
type violations array
RohinBhargava 057366c
prettier
RohinBhargava 5f0a02c
change error messages
RohinBhargava a40f9a7
prettier
RohinBhargava d99e180
(followup): add test for playground environments validation
dsinghvi f03d38f
Merge remote-tracking branch 'origin/main' into dsinghvi/add-tests-fo…
dsinghvi 132cd26
update fix
dsinghvi 8b2e4d8
fix ci
dsinghvi 5d9148d
== to ===
dsinghvi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { loadApis, loadProject } from "./loadProject"; | ||
export { loadApis, loadProject, loadProjectFromDirectory } from "./loadProject"; | ||
export { type Project } from "./Project"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ound-environments-exist/__test__/__snapshots__/playground-environments-exist.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`playground-environments-exist > no environments in api definition 1`] = ` | ||
[ | ||
{ | ||
"message": "The API does not contain the Staging environment. ", | ||
"nodePath": [ | ||
"navigation", | ||
"0", | ||
"api", | ||
], | ||
"relativeFilepath": "docs.yml", | ||
"severity": "error", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`playground-environments-exist > non existent environment specified 1`] = ` | ||
[ | ||
{ | ||
"message": "The API does not contain the Staging environment. Existing enviroments include Production, Dev.", | ||
"nodePath": [ | ||
"navigation", | ||
"0", | ||
"api", | ||
], | ||
"relativeFilepath": "docs.yml", | ||
"severity": "error", | ||
}, | ||
] | ||
`; |
3 changes: 3 additions & 0 deletions
3
...round-environments-exist/__test__/fixtures/no-environments-in-api/fern/definition/api.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: api | ||
error-discrimination: | ||
strategy: status-code |
60 changes: 60 additions & 0 deletions
60
...ound-environments-exist/__test__/fixtures/no-environments-in-api/fern/definition/imdb.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json | ||
|
||
service: | ||
auth: false | ||
base-path: /movies | ||
endpoints: | ||
createMovie: | ||
docs: Add a movie to the database | ||
method: POST | ||
path: /create-movie | ||
request: CreateMovieRequest | ||
response: MovieId | ||
|
||
getMovie: | ||
docs: Retrieve a movie from the database based on the ID | ||
method: GET | ||
path: /{id} | ||
path-parameters: | ||
id: MovieId | ||
response: Movie | ||
errors: | ||
- MovieDoesNotExistError | ||
examples: | ||
# Success response | ||
- path-parameters: | ||
id: tt0111161 | ||
response: | ||
body: | ||
id: tt0111161 | ||
title: The Shawshank Redemption | ||
rating: 9.3 | ||
# Error response | ||
- path-parameters: | ||
id: tt1234 | ||
response: | ||
error: MovieDoesNotExistError | ||
body: tt1234 | ||
|
||
types: | ||
MovieId: | ||
type: string | ||
docs: The unique identifier for a Movie in the database | ||
|
||
Movie: | ||
properties: | ||
id: MovieId | ||
title: string | ||
rating: | ||
type: double | ||
docs: The rating scale out of ten stars | ||
|
||
CreateMovieRequest: | ||
properties: | ||
title: string | ||
rating: double | ||
|
||
errors: | ||
MovieDoesNotExistError: | ||
status-code: 404 | ||
type: MovieId |
11 changes: 11 additions & 0 deletions
11
...ules/playground-environments-exist/__test__/fixtures/no-environments-in-api/fern/docs.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
instances: | ||
- url: https://fern.docs.buildwithfern.com | ||
title: Fern | Documentation | ||
navigation: | ||
- api: API Reference | ||
playground: | ||
environments: | ||
- Staging | ||
colors: | ||
accentPrimary: '#ffffff' | ||
background: '#000000' |
4 changes: 4 additions & 0 deletions
4
...yground-environments-exist/__test__/fixtures/no-environments-in-api/fern/fern.config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"organization": "fern", | ||
"version": "0.37.16" | ||
} |
9 changes: 9 additions & 0 deletions
9
...layground-environments-exist/__test__/fixtures/no-environments-in-api/fern/generators.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
default-group: local | ||
groups: | ||
local: | ||
generators: | ||
- name: fernapi/fern-typescript-node-sdk | ||
version: 0.9.5 | ||
output: | ||
location: local-file-system | ||
path: ../sdks/typescript |
6 changes: 6 additions & 0 deletions
6
...d-environments-exist/__test__/fixtures/wrong-environments-in-docs/fern/definition/api.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: api | ||
environments: | ||
Production: prod.com | ||
Dev: dev.com | ||
error-discrimination: | ||
strategy: status-code |
60 changes: 60 additions & 0 deletions
60
...-environments-exist/__test__/fixtures/wrong-environments-in-docs/fern/definition/imdb.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json | ||
|
||
service: | ||
auth: false | ||
base-path: /movies | ||
endpoints: | ||
createMovie: | ||
docs: Add a movie to the database | ||
method: POST | ||
path: /create-movie | ||
request: CreateMovieRequest | ||
response: MovieId | ||
|
||
getMovie: | ||
docs: Retrieve a movie from the database based on the ID | ||
method: GET | ||
path: /{id} | ||
path-parameters: | ||
id: MovieId | ||
response: Movie | ||
errors: | ||
- MovieDoesNotExistError | ||
examples: | ||
# Success response | ||
- path-parameters: | ||
id: tt0111161 | ||
response: | ||
body: | ||
id: tt0111161 | ||
title: The Shawshank Redemption | ||
rating: 9.3 | ||
# Error response | ||
- path-parameters: | ||
id: tt1234 | ||
response: | ||
error: MovieDoesNotExistError | ||
body: tt1234 | ||
|
||
types: | ||
MovieId: | ||
type: string | ||
docs: The unique identifier for a Movie in the database | ||
|
||
Movie: | ||
properties: | ||
id: MovieId | ||
title: string | ||
rating: | ||
type: double | ||
docs: The rating scale out of ten stars | ||
|
||
CreateMovieRequest: | ||
properties: | ||
title: string | ||
rating: double | ||
|
||
errors: | ||
MovieDoesNotExistError: | ||
status-code: 404 | ||
type: MovieId |
11 changes: 11 additions & 0 deletions
11
.../playground-environments-exist/__test__/fixtures/wrong-environments-in-docs/fern/docs.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
instances: | ||
- url: https://fern.docs.buildwithfern.com | ||
title: Fern | Documentation | ||
navigation: | ||
- api: API Reference | ||
playground: | ||
environments: | ||
- Staging | ||
colors: | ||
accentPrimary: '#ffffff' | ||
background: '#000000' |
4 changes: 4 additions & 0 deletions
4
...und-environments-exist/__test__/fixtures/wrong-environments-in-docs/fern/fern.config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"organization": "fern", | ||
"version": "0.37.16" | ||
} |
9 changes: 9 additions & 0 deletions
9
...round-environments-exist/__test__/fixtures/wrong-environments-in-docs/fern/generators.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
default-group: local | ||
groups: | ||
local: | ||
generators: | ||
- name: fernapi/fern-typescript-node-sdk | ||
version: 0.9.5 | ||
output: | ||
location: local-file-system | ||
path: ../sdks/typescript |
33 changes: 33 additions & 0 deletions
33
...or/src/rules/playground-environments-exist/__test__/playground-environments-exist.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { AbsoluteFilePath, join, RelativeFilePath } from "@fern-api/fs-utils"; | ||
import { getViolationsForRule } from "../../../testing-utils/getViolationsForRule"; | ||
import { PlaygroundEnvironmentsExistRule } from "../playground-environments-exist"; | ||
|
||
describe("playground-environments-exist", () => { | ||
it("no environments in api definition", async () => { | ||
const violations = await getViolationsForRule({ | ||
rule: PlaygroundEnvironmentsExistRule, | ||
absolutePathToFernDirectory: join( | ||
AbsoluteFilePath.of(__dirname), | ||
RelativeFilePath.of("fixtures"), | ||
RelativeFilePath.of("no-environments-in-api"), | ||
RelativeFilePath.of("fern") | ||
) | ||
}); | ||
|
||
expect(violations).toMatchSnapshot(); | ||
}); | ||
|
||
it("non existent environment specified", async () => { | ||
const violations = await getViolationsForRule({ | ||
rule: PlaygroundEnvironmentsExistRule, | ||
absolutePathToFernDirectory: join( | ||
AbsoluteFilePath.of(__dirname), | ||
RelativeFilePath.of("fixtures"), | ||
RelativeFilePath.of("wrong-environments-in-docs"), | ||
RelativeFilePath.of("fern") | ||
) | ||
}); | ||
|
||
expect(violations).toMatchSnapshot(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RohinBhargava the two cases |
||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RohinBhargava output of the unit test