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

Write more tests #8799

Merged
merged 3 commits into from
Nov 28, 2024
Merged

Write more tests #8799

merged 3 commits into from
Nov 28, 2024

Conversation

Devessier
Copy link
Contributor

No description provided.

@Devessier Devessier changed the title Write more tests so I can merge my last PR Write more tests Nov 28, 2024
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 PR significantly enhances test coverage across workflow-related utilities and removes unused utility functions, focusing on type safety and comprehensive test scenarios.

  • Added test coverage for workflow utilities in /packages/twenty-front/src/modules/workflow/utils/__tests__/ including trigger definitions, step names, and record actions
  • Critical bug in /packages/twenty-front/src/utils/__tests__/castToString.test.ts where null test actually checks undefined
  • Removed /packages/twenty-front/src/utils/isAnObject.ts and /promise-to-observable.ts utilities which may require codebase updates
  • Improved type safety in /packages/twenty-front/src/modules/workflow/search-variables/utils/getTriggerStepName.ts by replacing null checks with isDefined()
  • Duplicate test descriptions found in /packages/twenty-front/src/modules/workflow/utils/__tests__/getManualTriggerDefaultSettings.test.ts

💡 (4/5) You can add custom instructions or style guidelines for the bot here!

11 file(s) reviewed, 12 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +42 to +52
it('throws when an unknown trigger type is provided', () => {
expect(() => {
getTriggerStepName({
type: 'unknown' as any,
name: '',
settings: {
objectType: 'company',
outputSchema: {},
},
});
}).toThrow();
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 should verify the specific error message thrown, not just that an error occurs

import { capitalize } from '~/utils/string/capitalize';

export const getTriggerStepName = (trigger: WorkflowTrigger): string => {
switch (trigger.type) {
case 'DATABASE_EVENT':
return getDatabaseEventTriggerStepName(trigger);
case 'MANUAL':
if (!trigger.settings.objectType) {
if (!isDefined(trigger.settings.objectType)) {
return 'Manual trigger';
}

return 'Manual trigger for ' + capitalize(trigger.settings.objectType);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: String concatenation replaced with template literal for consistency with line 29


it('throws when argument is not never', () => {
expect(() => {
assertUnreachable(42 as never);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: casting 42 to never type is not a realistic test case - consider using a more representative example like an unhandled enum case

it('throws when provided workflow is undefined', () => {
expect(() => {
assertWorkflowWithCurrentVersionIsDefined(undefined);
}).toThrow();
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 checking for a specific error message to ensure the right error is thrown

Comment on lines +4 to +14
it('returns settings for a manual trigger that can be activated from any where', () => {
expect(
getManualTriggerDefaultSettings({
availability: 'EVERYWHERE',
activeObjectMetadataItems: generatedMockObjectMetadataItems,
}),
).toStrictEqual({
objectType: undefined,
outputSchema: {},
});
});
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 description is duplicated with the test below. Should be 'returns settings for EVERYWHERE availability' instead.

Comment on lines +1 to +2
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems';
import { getStepDefaultDefinition } from '../getStepDefaultDefinition';
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Missing test for when activeObjectMetadataItems is empty or undefined

type: 'DATABASE_EVENT',
activeObjectMetadataItems: [],
});
}).toThrow();
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Test should verify the exact error message thrown matches implementation: 'This function need to receive at least one object metadata item to run.'

});

it('returns false for Record Update', () => {
const codeAction: WorkflowRecordCRUDAction = {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: variable name 'codeAction' is misleading since this is a CRUD action

});

it('returns an empty string when null is provided', () => {
expect(castToString(undefined)).toBe('');
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: This test claims to test null but is actually testing undefined. Should be castToString(null) instead of castToString(undefined)

Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Removing this function could break type checking in other parts of the codebase. Need to verify all usages are updated to handle empty objects correctly. Consider using TypeScript's type system or Object.prototype.toString.call() instead.

@Devessier Devessier enabled auto-merge (squash) November 28, 2024 16:42
@Devessier Devessier merged commit 38b83f0 into main Nov 28, 2024
19 checks passed
@Devessier Devessier deleted the fix-bad-coverage branch November 28, 2024 16:43
Copy link

Thanks @Devessier for your contribution!
This marks your 29th PR on the repo. You're top 1% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

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

Successfully merging this pull request may close these issues.

2 participants