-
-
Notifications
You must be signed in to change notification settings - Fork 144
Add tests for less common entity routes #920
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,16 @@ test('format SQL query', async () => { | |
expect(res.statusCode).toBe(200) | ||
expect(res.headers['content-type']).toContain('text/plain') | ||
const formattedQuery = res.body | ||
expect(formattedQuery).toContain('SELECT') | ||
expect(formattedQuery).toContain('FROM') | ||
expect(formattedQuery).toContain('WHERE') | ||
expect(formattedQuery).toMatchInlineSnapshot(` | ||
"SELECT | ||
id, | ||
name | ||
FROM | ||
users | ||
WHERE | ||
status = 'ACTIVE' | ||
" | ||
`) | ||
}) | ||
|
||
test('format complex SQL query', async () => { | ||
|
@@ -26,7 +33,24 @@ test('format complex SQL query', async () => { | |
}) | ||
expect(res.statusCode).toBe(200) | ||
expect(res.headers['content-type']).toContain('text/plain') | ||
expect(res.body).toBeTruthy() | ||
expect(res.body).toMatchInlineSnapshot(` | ||
"SELECT | ||
u.id, | ||
u.name, | ||
p.title, | ||
p.created_at | ||
FROM | ||
users u | ||
JOIN posts p ON u.id = p.user_id | ||
WHERE | ||
u.status = 'ACTIVE' | ||
AND p.published = true | ||
ORDER BY | ||
p.created_at DESC | ||
LIMIT | ||
10 | ||
" | ||
`) | ||
}) | ||
|
||
test('format invalid SQL query', async () => { | ||
|
@@ -35,12 +59,17 @@ test('format invalid SQL query', async () => { | |
path: '/query/format', | ||
payload: { query: 'SELECT FROM WHERE;' }, | ||
}) | ||
// Even invalid SQL can be formatted | ||
expect(res.statusCode).toBe(200) | ||
expect(res.headers['content-type']).toContain('text/plain') | ||
expect(res.body).toBeTruthy() | ||
expect(res.body).toMatchInlineSnapshot(` | ||
"SELECT | ||
FROM | ||
WHERE; | ||
" | ||
`) | ||
}) | ||
|
||
// TODO(andrew): Those should return 400 error code for invalid parameter | ||
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. maybe 200 and do nothing? 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. Yeah agreed 200 is fine here. I think just like formatters in code editors it shouldn't fail when there are syntax errors; rather it should try to format the rest of the code despite the errors. |
||
test('format empty query', async () => { | ||
const res = await app.inject({ | ||
method: 'POST', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ test('typescript generator route', async () => { | |
}) | ||
expect(res.statusCode).toBe(200) | ||
expect(res.headers['content-type']).toContain('text/plain') | ||
expect(res.body).toBeTruthy() | ||
expect(res.body).contain('public') | ||
}) | ||
|
||
test('go generator route', async () => { | ||
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. same, not a test |
||
|
@@ -34,22 +34,18 @@ test('swift generator route', async () => { | |
test('generator routes with includedSchemas parameter', async () => { | ||
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. valid, but a lot of actual issues in the code may be missed, would be better to include one or a few of multiple existing schemas and check that only they are included |
||
const res = await app.inject({ | ||
method: 'GET', | ||
path: '/generators/typescript?includedSchemas=public', | ||
path: '/generators/typescript?included_schemas=private', | ||
}) | ||
expect(res.statusCode).toBe(200) | ||
expect(res.headers['content-type']).toContain('text/plain') | ||
expect(res.body).toBeTruthy() | ||
// the only schema is excluded database should be empty | ||
expect(res.body).toContain('Database = {}') | ||
}) | ||
|
||
// Skip this test as the OpenAPI endpoint is not implemented | ||
test.skip('openapi generator route', async () => { | ||
test('invalid generator route', async () => { | ||
const res = await app.inject({ | ||
method: 'GET', | ||
path: '/generators/openapi', | ||
}) | ||
expect(res.statusCode).toBe(200) | ||
expect(res.headers['content-type']).toContain('application/json') | ||
const body = JSON.parse(res.body) | ||
expect(body.openapi).toBeTruthy() | ||
expect(body.paths).toBeTruthy() | ||
expect(res.statusCode).toBe(404) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ test('policy list filtering', async () => { | |
test('policy list with specific included schema', async () => { | ||
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. we need to create some in public and in other schema(s) first (we prob have only 1) |
||
const res = await app.inject({ | ||
method: 'GET', | ||
path: '/policies?includedSchemas=public', | ||
path: '/policies?included_schema=public', | ||
}) | ||
expect(res.statusCode).toBe(200) | ||
const policies = res.json() | ||
|
@@ -48,8 +48,7 @@ test('create policy with missing required field', async () => { | |
command: 'PERMISSIVE', | ||
}, | ||
}) | ||
// The API returns 500 instead of 400 for invalid parameters | ||
expect(res.statusCode).toBe(500) | ||
expect(res.statusCode).toBe(400) | ||
}) | ||
|
||
test('update policy with invalid id', async () => { | ||
|
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.
chore
Avoid
ident
to raise an exception ending with500
if those params are empty. TODO: migrate all this to zod for better validation of the params.