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 #2 #7978

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

gitstart-app[bot]
Copy link
Contributor

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

This PR was created by GitStart to address the requirements from this ticket: TWNTY-7526.


Description

For workspace members, the deletion of multiple members is a special case that is not permitted by the method for regular users. As a result, we ensure that multiple deletions are not processed.

For certain tests, both an account ID and a user ID are required. We are utilizing Tim's account for all testing purposes, as specified by the token in jest-integration.config.ts. To streamline this process, we have defined a constant to store and reference the account ID and user ID during testing.Refs

#7526

Dem

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 introduces comprehensive integration tests for various GraphQL API resolvers in the Twenty server. Here's a summary of the key changes:

  • Added TIM_USER_ID constant for consistent user identification in tests
  • Implemented extensive test suites for API keys, attachments, audit logs, blocklists, calendar channel event associations, and calendar channels
  • Each test suite covers CRUD operations, including edge cases and error handling
  • Special handling for workspace members, preventing multiple deletions as required

Key points:

  • Tests ensure API behaves correctly for single and multiple record operations
  • Soft deletion and permanent removal scenarios are covered
  • Test suites are designed to be independent and leave no side effects
  • Consistent use of utility functions for creating GraphQL operations and making API requests

8 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings | Greptile

expect(destroyApiKeyResponse.body.data.destroyApiKey).toBeTruthy();
});

it('9. should not find many API keys anymore', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Test could be combined with test on line 257 to reduce duplication

Suggested change
it('9. should not find many API keys anymore', async () => {
it('9. should not find many API keys anymore', async () => {
const graphqlOperation = findManyOperationFactory({
objectMetadataSingularName: 'apiKey',
objectMetadataPluralName: 'apiKeys',
gqlFields: API_KEY_GQL_FIELDS,
filter: {
id: {
in: [API_KEY_1_ID, API_KEY_2_ID],
},
not: {
deletedAt: {
is: 'NULL',
},
},
},
});
const response = await makeGraphqlAPIRequest(graphqlOperation);
expect(response.body.data.apiKeys.edges).toHaveLength(0);
});

expect(createdAttachment).toHaveProperty('opportunityId');
});

it('2. should find many attachments', 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: Duplicate test number. Should be '3.' instead of '2.'

Suggested change
it('2. should find many attachments', async () => {
it('3. should find many attachments', async () => {

},
});

const findAuditLogsResponse = await makeGraphqlAPIRequest(graphqlOperation);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Rename variable to 'response' for consistency with other tests

Comment on lines +373 to +374
const destroyAuditLogResponse =
await makeGraphqlAPIRequest(graphqlOperation);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Unnecessary variable assignment. Use inline await

Comment on lines +194 to +204
if (data.edges.length > 0) {
const associations = data.edges[0].node;

expect(associations).toHaveProperty('eventExternalId');
expect(associations).toHaveProperty('id');
expect(associations).toHaveProperty('createdAt');
expect(associations).toHaveProperty('updatedAt');
expect(associations).toHaveProperty('deletedAt');
expect(associations).toHaveProperty('calendarChannelId');
expect(associations).toHaveProperty('calendarEventId');
}
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 if data exists before asserting properties

expect(data).toBeDefined();
expect(Array.isArray(data.edges)).toBe(true);

if (data.edges.length > 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: Check if data.edges is empty before accessing

Suggested change
if (data.edges.length > 0) {
if (data.edges && data.edges.length > 0) {
const calendarChannels = data.edges[0].node;
// ... existing assertions
}

@charlesBochet charlesBochet merged commit 5ad8ff8 into main Oct 24, 2024
18 checks passed
@charlesBochet charlesBochet deleted the TWNTY-7526-2 branch October 24, 2024 11:25
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.

2 participants