-
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
Changes from 1 commit
0b554d6
4910415
5c7a740
ac1807e
7efde63
66396ce
8393141
8093074
0228e1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
); | ||
}); | ||
}); |
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!