-
Notifications
You must be signed in to change notification settings - Fork 63
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
Feature/playwright #72
Conversation
it('should fetch GraphQL schema for GraphQL endpoints', async () => { | ||
const mockSchema = { | ||
__schema: { | ||
types: [ | ||
{ name: 'Query', fields: [] } | ||
] | ||
} | ||
}; | ||
|
||
mockedAxios.get.mockResolvedValueOnce({ data: 'GraphQL API Documentation' }); | ||
mockedAxios.post.mockResolvedValueOnce({ | ||
data: { data: mockSchema } | ||
}); | ||
|
||
const result = await getDocumentation( | ||
'https://api.example.com/graphql', | ||
{ 'Authorization': 'Bearer token' }, | ||
{ 'version': '1' } | ||
); | ||
|
||
// Verify both documentation and schema were fetched | ||
expect(mockedAxios.get).toHaveBeenCalledWith('https://api.example.com/graphql'); | ||
expect(mockedAxios.post).toHaveBeenCalledWith( | ||
'https://api.example.com/graphql', | ||
expect.objectContaining({ | ||
query: expect.any(String), | ||
operationName: 'IntrospectionQuery' | ||
}), | ||
expect.objectContaining({ | ||
headers: { 'Authorization': 'Bearer token' }, | ||
params: { 'version': '1' } | ||
}) | ||
); | ||
expect(result).toContain(JSON.stringify(mockSchema.__schema)); | ||
}); | ||
|
||
it('should handle GraphQL schema fetch errors gracefully', async () => { | ||
const plainDoc = 'GraphQL API Documentation'; | ||
mockedAxios.get.mockResolvedValueOnce({ data: plainDoc }); | ||
mockedAxios.post.mockRejectedValueOnce(new Error('GraphQL Error')); | ||
|
||
const result = await getDocumentation('https://api.example.com/graphql', {}, {}); | ||
|
||
expect(result).toBe(plainDoc); | ||
}); | ||
|
||
it('should handle GraphQL schema errors in response', async () => { | ||
const plainDoc = 'GraphQL API Documentation'; | ||
mockedAxios.get.mockResolvedValueOnce({ data: plainDoc }); | ||
mockedAxios.post.mockResolvedValueOnce({ | ||
data: { | ||
errors: [{ message: 'Invalid introspection query' }] | ||
} | ||
}); | ||
|
||
const result = await getDocumentation('https://api.example.com/graphql', {}, {}); | ||
|
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.
don't delete gql schema tests
it('should detect GraphQL endpoints from documentation content', async () => { | ||
const docWithGraphQL = 'This is a GraphQL API endpoint'; | ||
const mockSchema = { | ||
__schema: { | ||
types: [ | ||
{ name: 'Query', fields: [] } | ||
] | ||
} | ||
}; | ||
it('should set custom headers when provided', async () => { | ||
const headers = { 'Authorization': 'Bearer token' }; | ||
await getDocumentation('https://api.example.com/docs', headers, {}); | ||
|
||
expect(mockContext.setExtraHTTPHeaders).toHaveBeenCalledWith(headers); | ||
}); | ||
|
||
mockedAxios.get.mockResolvedValueOnce({ data: docWithGraphQL }); | ||
mockedAxios.post.mockResolvedValueOnce({ | ||
data: { data: mockSchema } | ||
}); | ||
it('should handle query parameters correctly', async () => { | ||
const queryParams = { 'version': '1' }; | ||
await getDocumentation('https://api.example.com/docs', {}, queryParams); | ||
|
||
expect(mockPage.goto).toHaveBeenCalledWith('https://api.example.com/docs?version=1'); | ||
}); | ||
|
||
const result = await getDocumentation( | ||
'https://api.example.com/docs', | ||
{}, | ||
{} | ||
); | ||
it('should clean up resources after fetching', async () => { | ||
await getDocumentation('https://api.example.com/docs', {}, {}); | ||
|
||
expect(mockPage.close).toHaveBeenCalled(); | ||
expect(mockContext.close).toHaveBeenCalled(); | ||
}); | ||
|
||
expect(mockedAxios.post).toHaveBeenCalled(); | ||
expect(result).toContain(docWithGraphQL); | ||
expect(result).toContain(JSON.stringify(mockSchema.__schema)); |
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.
don't delete this gql test
|
||
<script src="/static/ninja/swagger-ui-bundle.ca90216c3f6d.js"></script> | ||
<script src="/static/ninja/swagger-ui-init.ec666b6c27d3.js"></script> | ||
|
||
</body> |
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 would leave the more complex html here, because it represents reality
<script type="application/json" id="swagger-settings"> | ||
{ | ||
"url": "https://external-api.com/openapi.json" | ||
} | ||
</script> | ||
<div id="swagger-ui"></div> | ||
</body> |
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.
leave original
<script type="application/json" id="swagger-settings"> | ||
{ | ||
"url": "/api/v1/openapi.json" | ||
} | ||
</script> | ||
<div id="swagger-ui"></div> | ||
</body> |
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.
leave original
No description provided.