-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[Server Integration tests] Enrich integration GraphQL API tests #7699
Conversation
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.
PR Summary
This pull request enhances the integration tests for the GraphQL API, focusing on company-related operations. The changes introduce more comprehensive and organized testing strategies. Here are the key points:
- Replaced single
companies.integration-spec.ts
file with multiple specialized test files for different company operations - Implemented GraphQL tag (gql) for improved query readability and syntax highlighting
- Added tests for create, read, update, delete, and destroy operations for both single and multiple companies
- Introduced utility functions in
api-requests.ts
andgenerate-record-name.ts
for consistent API interaction and unique record naming - Enhanced teardown process in
teardown-test.ts
to clean up test data, ensuring test independence
These changes significantly improve the test coverage and maintainability of the company-related GraphQL API tests.
17 file(s) reviewed, 16 comment(s)
Edit PR Review Bot Settings | Greptile
`; | ||
|
||
describe('createCompaniesResolver (integration)', () => { | ||
it('should create and return companies', 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.
syntax: Extra space in test description
expect(createdCompany).toHaveProperty('name'); | ||
expect(createdCompany.name).toEqual(companyName); | ||
|
||
expect(createdCompany).toHaveProperty('employees'); | ||
expect(createdCompany).toHaveProperty('idealCustomerProfile'); | ||
expect(createdCompany).toHaveProperty('position'); | ||
expect(createdCompany).toHaveProperty('id'); | ||
expect(createdCompany).toHaveProperty('createdAt'); | ||
expect(createdCompany).toHaveProperty('updatedAt'); | ||
expect(createdCompany).toHaveProperty('deletedAt'); | ||
expect(createdCompany).toHaveProperty('accountOwnerId'); | ||
expect(createdCompany).toHaveProperty('tagline'); | ||
expect(createdCompany).toHaveProperty('workPolicy'); | ||
expect(createdCompany).toHaveProperty('visaSponsorship'); |
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.
style: Consider using a loop or helper function to reduce repetition in property checks
|
||
const findCompanyResponse = await apiRequest(findCompanyQueryData); | ||
|
||
expect(findCompanyResponse.body.data.company).toBeNull(); |
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.
style: Check for specific error message or code instead of just null
expect( | ||
findCompaniesResponse.body.data.companies.edges.filter((c) => | ||
companiesIds.includes(c.node.id), | ||
), | ||
).toHaveLength(0); |
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.
style: Use a more specific assertion
const findDeletedCompaniesResponse = await apiRequest( | ||
findDeletedCompaniesQueryData, | ||
); |
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.
style: Use successfulApiRequest for consistency
expect(findPersonResponse.body.data.person).toEqual( | ||
expect.objectContaining({ | ||
company: { | ||
id: companyId, | ||
name: companyName, | ||
}, | ||
}), | ||
); |
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.
style: Consider using more specific assertions for nested objects
successfulApiRequest(updateCompanyQueryData).expect((res) => { | ||
const updatedCompany = res.body.data.updateCompany; | ||
|
||
expect(updatedCompany).toHaveProperty('name'); | ||
expect(updatedCompany.name).toEqual(companyName); | ||
}); |
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.
logic: Add await to ensure the request is completed before moving to the next step
successfulApiRequest(findCompanyQueryData).expect((res) => { | ||
const company = res.body.data.company; | ||
|
||
expect(company).toHaveProperty('name'); | ||
expect(company.name).toEqual(companyName); | ||
}); |
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.
logic: Add await to ensure the request is completed before the test ends
// eslint-disable-next-line no-restricted-imports | ||
import jestConfig from '../../jest-integration.config'; |
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.
style: Consider moving this import to the top of the file with other imports for consistency
apiRequest({ | ||
query, | ||
variables: { | ||
nameFilter, | ||
personFilter, | ||
}, | ||
}).then((res) => { | ||
if (res.body.errors) throw new Error(JSON.stringify(res.body.errors)); | ||
global.app.close(); | ||
}); |
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.
style: This apiRequest is using a .then() chain. Consider using async/await for better readability and error handling
@@ -16,6 +16,7 @@ const jestConfig: JestConfigWithTsJest = { | |||
testTimeout: 15000, | |||
moduleNameMapper: { | |||
...pathsToModuleNameMapper(tsConfig.compilerOptions.paths), | |||
'^test/(.*)$': '<rootDir>/test/$1', |
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.
@gitstart-twenty what is this line about?
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 fixes the import for ultils folder, Jest was not resolving the imports
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.
Oh, great!
} | ||
`; | ||
|
||
describe('createCompaniesResolver (integration)', () => { |
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.
@gitstart-twenty this is will create a separate suite for the create-many usecase
Could we instead have only 1 suite for the whole company tests? We would still like to split the tests in multiple files but only have one suite. This will ensure in which order the tests are executed because they have side effects on each other
|
||
type StandardObjectsSingularName = 'Company' | 'Person'; | ||
|
||
export const apiRequest = (data: QueryData) => { |
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.
makeGraphqlAPIRequest
.send({ query: print(data.query), variables: data.variables || {} }); | ||
}; | ||
|
||
export const successfulApiRequest = (data: QueryData) => { |
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.
exectSuccessfullGraphqlAPIRequest
// eslint-disable-next-line no-restricted-imports | ||
import jestConfig from '../../jest-integration.config'; | ||
|
||
const query = gql` |
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.
Let's avoid that and have the suite clean itself. This will likely impact too much the performance overall
Hello @charlesBochet
|
@gitstart-twenty the idea is that we don't even need to cleanUp as the suite should clean itself through the different tests So:
Other than that the PR looks promising :) |
@charlesBochet thanks for the clarifications, just one question
so we don't need to change the teardown file, right? |
@gitstart-twenty Indeed, I think you can remove your changes in tearDown |
Hey @charlesBochet |
@charlesBochet Also, the test command is broken after the changes |
@charlesBochet we have a fix for the tests (including the functions and the order of the tests) but we are not sure if you are going to update the branch |
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.
@gitstart-twenty, I have made changes to your PR:
- introduced utils to compute query instead of hard-coding them
- separated existing auto-generated findMany tests from the full resolver lists tests on only one object
- reworked a bit the folder arch for more clarity
@@ -16,6 +16,7 @@ const jestConfig: JestConfigWithTsJest = { | |||
testTimeout: 15000, | |||
moduleNameMapper: { | |||
...pathsToModuleNameMapper(tsConfig.compilerOptions.paths), | |||
'^test/(.*)$': '<rootDir>/test/$1', |
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.
Oh, great!
Log
|
Description
Demo
Fixes #7526