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

[Server Integration tests] Enrich integration GraphQL API tests #7699

Merged
merged 9 commits into from
Oct 17, 2024

Conversation

gitstart-app[bot]
Copy link
Contributor

@gitstart-app gitstart-app bot commented Oct 14, 2024

Description

  • We are using gql instead of strings to be able to see the graphql code highlighted

Demo

Fixes #7526

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 and generate-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 () => {
Copy link
Contributor

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

Comment on lines 39 to 52
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');
Copy link
Contributor

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();
Copy link
Contributor

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

Comment on lines 68 to 72
expect(
findCompaniesResponse.body.data.companies.edges.filter((c) =>
companiesIds.includes(c.node.id),
),
).toHaveLength(0);
Copy link
Contributor

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

Comment on lines 90 to 92
const findDeletedCompaniesResponse = await apiRequest(
findDeletedCompaniesQueryData,
);
Copy link
Contributor

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

Comment on lines 102 to 109
expect(findPersonResponse.body.data.person).toEqual(
expect.objectContaining({
company: {
id: companyId,
name: companyName,
},
}),
);
Copy link
Contributor

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

Comment on lines 37 to 42
successfulApiRequest(updateCompanyQueryData).expect((res) => {
const updatedCompany = res.body.data.updateCompany;

expect(updatedCompany).toHaveProperty('name');
expect(updatedCompany.name).toEqual(companyName);
});
Copy link
Contributor

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

Comment on lines 55 to 60
successfulApiRequest(findCompanyQueryData).expect((res) => {
const company = res.body.data.company;

expect(company).toHaveProperty('name');
expect(company.name).toEqual(companyName);
});
Copy link
Contributor

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

Comment on lines 6 to 7
// eslint-disable-next-line no-restricted-imports
import jestConfig from '../../jest-integration.config';
Copy link
Contributor

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

Comment on lines 41 to 50
apiRequest({
query,
variables: {
nameFilter,
personFilter,
},
}).then((res) => {
if (res.body.errors) throw new Error(JSON.stringify(res.body.errors));
global.app.close();
});
Copy link
Contributor

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',
Copy link
Member

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?

Copy link
Contributor

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

Copy link
Member

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)', () => {
Copy link
Member

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) => {
Copy link
Member

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) => {
Copy link
Member

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`
Copy link
Member

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

@gitstart-twenty
Copy link
Contributor

Hello @charlesBochet
for these two comments below, we should use one file for all tests, and run the database clean-up on the afterAll hook, is this correct?

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

Let's avoid that and have the suite clean itself. This will likely impact too much the performance overall

@charlesBochet
Copy link
Member

charlesBochet commented Oct 15, 2024

@gitstart-twenty the idea is that we don't even need to cleanUp as the suite should clean itself through the different tests

So:

  • remove setUp, clean post and pre-suite (we only want a global setUp and tearDown which is already in place)
  • have only one suite (.spec), but split its content in several files (maybe the queries and response could be in different files or the content of the test could be in another file BUT they should not be .spec file)
  • follow the scenario in the main issue that should leave the database data in the same state as before the tests

Other than that the PR looks promising :)

@gitstart-twenty
Copy link
Contributor

gitstart-twenty commented Oct 15, 2024

@charlesBochet thanks for the clarifications, just one question

remove setUp, clean post and pre-suite (we only want a global setUp and tearDown which is already in place)

so we don't need to change the teardown file, right?

@charlesBochet
Copy link
Member

@gitstart-twenty Indeed, I think you can remove your changes in tearDown

@gitstart-twenty
Copy link
Contributor

Hey @charlesBochet
I see that you moved some files and also already updated the teardown, do you need any other change from us?

@gitstart-twenty
Copy link
Contributor

gitstart-twenty commented Oct 16, 2024

@charlesBochet
Actually, We noticed that in your changes you removed the expectSuccessfullGraphqlAPIRequest function but you are still using the function in the tests, are you currently changing this?

Also, the test command is broken after the changes

@gitstart-twenty
Copy link
Contributor

@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

Copy link
Member

@charlesBochet charlesBochet left a 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',
Copy link
Member

Choose a reason for hiding this comment

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

Oh, great!

@charlesBochet charlesBochet merged commit 58fd340 into main Oct 17, 2024
7 checks passed
@charlesBochet charlesBochet deleted the TWNTY-7526 branch October 17, 2024 17:16
Copy link

Fails
🚫

node failed.

Log

�[31mError: �[39m SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
�[90m    at parseJSONFromBytes (node:internal/deps/undici/undici:5584:19)�[39m
�[90m    at successSteps (node:internal/deps/undici/undici:5555:27)�[39m
�[90m    at fullyReadBody (node:internal/deps/undici/undici:1665:9)�[39m
�[90m    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)�[39m
�[90m    at async specConsumeBody (node:internal/deps/undici/undici:5564:7)�[39m
danger-results://tmp/danger-results-9210185c.json

Generated by 🚫 dangerJS against 0228e1e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Server Integration tests] Enrich integration GraphQL API tests
2 participants