-
Notifications
You must be signed in to change notification settings - Fork 6
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
dev: api integration tests #907
Conversation
defaultValues: { | ||
// default to 1 day from now, mostly to make testing easier | ||
expiration: new Date(Date.now() + 1000 * 60 * 60 * 24), | ||
}, |
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.
i didn't want to write the code to navigate the date picker, so i took the easy way out and set a default time instead. let me know if the default time should be longer or if we should do this differently.
@@ -530,12 +548,19 @@ export const siteApi = contract.router( | |||
}, | |||
}, | |||
{ | |||
strictStatusCodes: true, |
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.
this makes the return types from the api client more legible. instead of getting
type Response =
| { status: 200, body: {...}}
| { status: 201 | 202 | ...., body: any}
you get
type Response = { status: 200, body: {...}}
commonResponses: { | ||
// this makes sure that 400 is always a valid response code | ||
400: zodErrorSchema, | ||
403: z.string(), | ||
404: z.string(), | ||
}, |
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.
did not know this was an option, now every route has the correct error responses at least.
}); | ||
|
||
client = initClient(siteApi, { | ||
baseUrl: `http://localhost:3000/`, |
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.
this might need to be an env var
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.
woot, awesome!!
Issue(s) Resolved
Mostly want this before implementing #887 in the API.
High-level Explanation of PR
Adds integration tests for the API. For now just very basic tests: create a pub, get a pub. Should add more in depth tests later.
Roughly:
ts-rest
clientOther than the initial setup, these tests are quite fast as they don't really use the UI at all.
I chose not to use
playwright
s built in API client, as it's not typed and is more error prone when it comes to routes. The goal is more to test API responses rather than how it interacts with any client.Test Plan
Screenshots (if applicable)
Notes