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

Feature/playwright #72

Merged
merged 12 commits into from
Mar 4, 2025
Merged

Feature/playwright #72

merged 12 commits into from
Mar 4, 2025

Conversation

stefanfaistenauer
Copy link
Contributor

No description provided.

@stefanfaistenauer stefanfaistenauer marked this pull request as ready for review March 4, 2025 18:45
Comment on lines 53 to 109
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', {}, {});

Copy link
Contributor

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

Comment on lines 121 to 144
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));
Copy link
Contributor

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>
Copy link
Contributor

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>
Copy link
Contributor

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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave original

@stefanfaistenauer stefanfaistenauer merged commit 202ffc5 into main Mar 4, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants