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
1 change: 1 addition & 0 deletions packages/twenty-server/jest-integration.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!

'twenty-emails': '<rootDir>/../twenty-emails/dist/index.js',
},
fakeTimers: {
Expand Down
67 changes: 0 additions & 67 deletions packages/twenty-server/test/companies.integration-spec.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import gql from 'graphql-tag';
import { successfulApiRequest } from 'test/utils/api-requests';
import { generateRecordName } from 'test/utils/generate-record-name';

const createCompaniesQuery = gql`
mutation CreateCompanies($data: [CompanyCreateInput!]!) {
createCompanies(data: $data) {
id
name
employees
idealCustomerProfile
position
createdAt
updatedAt
deletedAt
accountOwnerId
tagline
workPolicy
visaSponsorship
}
}
`;

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

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

const companyName1 = generateRecordName();
const companyName2 = generateRecordName();

const queryData = {
query: createCompaniesQuery,
variables: {
data: [
{
name: companyName1,
},
{
name: companyName2,
},
],
},
};

const createdCompanies = await successfulApiRequest(queryData);

expect(createdCompanies.body.data.createCompanies).toHaveLength(2);

createdCompanies.body.data.createCompanies.forEach((company) => {
expect(company).toHaveProperty('name');
expect([companyName1, companyName2]).toContain(company.name);

expect(company).toHaveProperty('employees');
expect(company).toHaveProperty('idealCustomerProfile');
expect(company).toHaveProperty('position');
expect(company).toHaveProperty('id');
expect(company).toHaveProperty('createdAt');
expect(company).toHaveProperty('updatedAt');
expect(company).toHaveProperty('deletedAt');
expect(company).toHaveProperty('accountOwnerId');
expect(company).toHaveProperty('tagline');
expect(company).toHaveProperty('workPolicy');
expect(company).toHaveProperty('visaSponsorship');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import gql from 'graphql-tag';
import { successfulApiRequest } from 'test/utils/api-requests';
import { generateRecordName } from 'test/utils/generate-record-name';

const query = gql`
mutation CreateCompany($data: CompanyCreateInput) {
createCompany(data: $data) {
name
employees
idealCustomerProfile
position
id
createdAt
updatedAt
deletedAt
accountOwnerId
tagline
workPolicy
visaSponsorship
}
}
`;

describe('createCompanyResolver (integration)', () => {
it('should create and return a company', () => {
const companyName = generateRecordName();
const queryData = {
query,
variables: {
data: {
name: companyName,
},
},
};

return successfulApiRequest(queryData).expect((res) => {
const createdCompany = res.body.data.createCompany;

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

});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import gql from 'graphql-tag';
import {
createManyObjects,
successfulApiRequest,
} from 'test/utils/api-requests';
import { generateRecordName } from 'test/utils/generate-record-name';

const deleteCompaniesQuery = gql`
mutation DeleteCompanies($filter: CompanyFilterInput) {
deleteCompanies(filter: $filter) {
deletedAt
}
}
`;

const findCompaniesQuery = gql`
query Companies($filter: CompanyFilterInput) {
companies(filter: $filter) {
edges {
node {
id
}
}
}
}
`;

describe('deleteCompaniesResolver (integration)', () => {
it('should delete companies and hide them from simple queries', async () => {
const companiesIds = await createManyObjects('Company', [
{ name: generateRecordName() },
{ name: generateRecordName() },
]);

const filter = {
id: {
in: companiesIds,
},
};

const deleteCompaniesQueryData = {
query: deleteCompaniesQuery,
variables: {
filter,
},
};

const deleteCompaniesResponse = await successfulApiRequest(
deleteCompaniesQueryData,
);

const deleteCompanies = deleteCompaniesResponse.body.data.deleteCompanies;

expect(deleteCompanies).toHaveLength(companiesIds.length);

deleteCompanies.forEach((company) => {
expect(company.deletedAt).toBeTruthy();
});

const findCompaniesQueryData = {
query: findCompaniesQuery,
variables: {
filter,
},
};

const findCompaniesResponse = await successfulApiRequest(
findCompaniesQueryData,
);

expect(findCompaniesResponse.body.data.companies.edges).toHaveLength(0);

const findDeletedCompaniesQueryData = {
query: findCompaniesQuery,
variables: {
filter: {
id: {
in: companiesIds,
},
deletedAt: {
not: 'NULL',
},
},
},
};

const findDeletedCompaniesResponse = await successfulApiRequest(
findDeletedCompaniesQueryData,
);

expect(findDeletedCompaniesResponse.body.data.companies.edges).toHaveLength(
companiesIds.length,
);
});
});
Loading
Loading