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

Fix frontend tests #6585

Merged
merged 7 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"@sentry/tracing": "^7.99.0",
"@sniptt/guards": "^0.2.0",
"@stoplight/elements": "^8.0.5",
"@storybook/icons": "^1.2.9",
"@swc/jest": "^0.2.29",
"@tabler/icons-react": "^2.44.0",
"@types/dompurify": "^3.0.5",
Expand Down Expand Up @@ -189,7 +188,7 @@
"stripe": "^14.17.0",
"ts-key-enum": "^2.0.12",
"tslib": "^2.3.0",
"tsup": "^8.0.1",
"tsup": "^8.2.4",
"type-fest": "4.10.1",
"typeorm": "patch:[email protected]#./packages/twenty-server/patches/typeorm+0.3.20.patch",
"typescript": "5.3.3",
Expand Down Expand Up @@ -233,6 +232,7 @@
"@storybook/addon-onboarding": "^1.0.10",
"@storybook/blocks": "^7.6.3",
"@storybook/core-server": "7.6.3",
"@storybook/icons": "^1.2.9",
"@storybook/jest": "^0.2.3",
"@storybook/react": "^7.6.3",
"@storybook/react-vite": "^7.6.3",
Expand Down Expand Up @@ -296,7 +296,7 @@
"danger": "^11.3.0",
"dotenv-cli": "^7.2.1",
"drizzle-kit": "^0.20.14",
"esbuild": "^0.20.2",
"esbuild": "^0.23.0",
"eslint": "^8.53.0",
"eslint-config-next": "14.0.4",
"eslint-config-prettier": "^9.1.0",
Expand Down Expand Up @@ -328,14 +328,14 @@
"storybook": "^7.6.3",
"storybook-addon-cookie": "^3.2.0",
"storybook-addon-pseudo-states": "^2.1.2",
"storybook-dark-mode": "^4.0.1",
"storybook-dark-mode": "^3.0.3",
"supertest": "^6.1.3",
"ts-jest": "^29.1.1",
"ts-loader": "^9.2.3",
"ts-node": "10.9.1",
"tsconfig-paths": "^4.2.0",
"tsx": "^4.7.2",
"vite": "^5.0.0",
"tsx": "^4.17.0",
"vite": "^5.4.0",
"vite-plugin-checker": "^0.6.2",
"vite-plugin-dts": "3.8.1",
"vite-plugin-svgr": "^4.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ContainerProps = {
const StyledContainer = styled.div<ContainerProps>`
align-items: center;
background-color: ${({ theme, isOn, color }) =>
isOn ? color ?? theme.color.blue : theme.background.quaternary};
isOn ? (color ?? theme.color.blue) : theme.background.quaternary};
border-radius: 10px;
cursor: pointer;
display: flex;
Expand Down
6 changes: 3 additions & 3 deletions packages/twenty-front/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const jestConfig: JestConfigWithTsJest = {
extensionsToTreatAsEsm: ['.ts', '.tsx'],
coverageThreshold: {
global: {
statements: 64,
lines: 63,
functions: 55,
statements: 62,
lines: 61,
functions: 52,
},
},
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { loggerLink } from '../utils';
const logger = loggerLink(() => 'Twenty');

export interface Options<TCacheShape> extends ApolloClientOptions<TCacheShape> {
onError?: (err: GraphQLFormattedError | undefined) => void;
onError?: (err: readonly GraphQLFormattedError[] | undefined) => void;
onNetworkError?: (err: Error | ServerParseError | ServerError) => void;
onTokenPairChange?: (tokenPair: AuthTokenPair) => void;
onUnauthenticatedError?: () => void;
Expand Down Expand Up @@ -80,9 +80,8 @@ export class ApolloFactory<TCacheShape> implements ApolloManager<TCacheShape> {
const errorLink = onError(
({ graphQLErrors, networkError, forward, operation }) => {
if (isDefined(graphQLErrors)) {
onErrorCb?.(graphQLErrors);
for (const graphQLError of graphQLErrors) {
onErrorCb?.(graphQLError);

if (graphQLError.message === 'Unauthorized') {
return fromPromise(
renewToken(uri, this.tokenPair)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { useIsFieldReadOnly } from '@/object-record/record-field/hooks/useIsFiel
import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition';
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';

const entityId = 'entityId';
const recordId = 'recordId';

const getWrapper =
(fieldDefinition: FieldDefinition<FieldMetadata>) =>
({ children }: { children: ReactNode }) => (
<FieldContext.Provider
value={{
fieldDefinition,
entityId,
recordId,
hotkeyScope: 'hotkeyScope',
isLabelIdentifier: false,
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactNode, useContext } from 'react';
import { styled } from '@linaria/react';
import { ReactNode, useContext } from 'react';
import { BORDER_COMMON, ThemeContext } from 'twenty-ui';

import { FieldContext } from '@/object-record/record-field/contexts/FieldContext';
Expand Down Expand Up @@ -79,7 +79,7 @@ export const RecordTableCellBaseContainer = ({

const { hotkeyScope } = useContext(FieldContext);

const editHotkeyScope = { scope: hotkeyScope } ?? DEFAULT_CELL_SCOPE;
const editHotkeyScope = { scope: hotkeyScope ?? DEFAULT_CELL_SCOPE };

return (
<CellHotkeyScopeContext.Provider value={editHotkeyScope}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7918,7 +7918,7 @@ export const mockedStandardObjectMetadataQueryResult: ObjectMetadataItemsQuery =
"__typename": "fieldEdge",
"node": {
"__typename": "field",
"id": "af19a3ba-b725-4b9d-a0b7-8bf6b04fadbf",
"id": "5dcef112-ce1b-46c1-a33a-4d1394628c34",
"type": "DATE_TIME",
"name": "updatedAt",
"label": "Update date",
Expand All @@ -7941,7 +7941,7 @@ export const mockedStandardObjectMetadataQueryResult: ObjectMetadataItemsQuery =
"__typename": "fieldEdge",
"node": {
"__typename": "field",
"id": "af19a3ba-b725-4b9d-a0b7-8bf6b04fadds",
"id": "277d8939-1ead-4cdb-a560-854644219779",
"type": "MULTI_SELECT",
"name": "testMultiSelect",
"label": "Test Multi Select",
Expand All @@ -7964,7 +7964,7 @@ export const mockedStandardObjectMetadataQueryResult: ObjectMetadataItemsQuery =
"__typename": "fieldEdge",
"node": {
"__typename": "field",
"id": "tt929592-4f74-419e-8b26-6d216859078f",
"id": "f207dd14-f05e-4f29-b222-8993d4680f31",
"type": "RAW_JSON",
"name": "testRawJson",
"label": "Test Raw Json",
Expand All @@ -7987,7 +7987,7 @@ export const mockedStandardObjectMetadataQueryResult: ObjectMetadataItemsQuery =
"__typename": "fieldEdge",
"node": {
"__typename": "field",
"id": "vv929592-4f74-419e-8b26-6d216859078f",
"id": "81db846a-a2f9-4b31-8931-81fac5cdd1b6",
"type": "RATING",
"name": "testRating",
"label": "Rating",
Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-front/src/testing/mock-data/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ const customObjectMetadataItemEdge: ObjectEdge = {
color: 'yellow',
},
{
id: '3',
id: '6f6e1421-8a42-4d4a-bf76-465b5f84b6d2',
value: 'HIGH',
label: 'High',
color: 'red',
Expand Down
4 changes: 2 additions & 2 deletions packages/twenty-front/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'tsup';
import svgr from 'esbuild-plugin-svgr';
import { Config } from '@svgr/core';
import svgr from 'esbuild-plugin-svgr';
import { defineConfig } from 'tsup';

const template: Config['template'] = (variables, { tpl }) => {
return tpl`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export const computePgGraphQLError = (
const error = errors[0];
const errorMessage = error?.message;

const mappedErrorKey = Object.keys(pgGraphQLErrorMapping).find(
(key) => errorMessage?.includes(key),
const mappedErrorKey = Object.keys(pgGraphQLErrorMapping).find((key) =>
errorMessage?.includes(key),
);

const mappedError = mappedErrorKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ export class TimelineMessagingService {
messageThreadIdsForWhichWorkspaceMemberIsNotInParticipants.includes(
messageThreadId,
)
? threadVisibilityByThreadIdForWhichWorkspaceMemberIsNotInParticipants?.[
? (threadVisibilityByThreadIdForWhichWorkspaceMemberIsNotInParticipants?.[
messageThreadId
] ?? MessageChannelVisibility.METADATA
] ?? MessageChannelVisibility.METADATA)
: MessageChannelVisibility.SHARE_EVERYTHING;

return threadVisibilityAcc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ export class MessageQueueCoreModule extends ConfigurableModuleClass {
const driverProvider: Provider = {
provide: QUEUE_DRIVER,
useFactory: async (...args: any[]) => {
const config = await options.useFactory!(...args);
if (options.useFactory) {
const config = await options.useFactory(...args);

return this.createDriver(config);
return this.createDriver(config);
}
throw new Error('useFactory is not defined');
},
inject: options.inject || [],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import compact from 'lodash.compact';
import { Any, EntityManager, Repository } from 'typeorm';

import { ObjectRecordCreateEvent } from 'src/engine/integrations/event-emitter/types/object-record-create.event';
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
import { CONTACTS_CREATION_BATCH_SIZE } from 'src/modules/contact-creation-manager/constants/contacts-creation-batch-size.constant';
Expand All @@ -22,8 +24,6 @@ import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/perso
import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository';
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
import { isWorkEmail } from 'src/utils/is-work-email';
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';

@Injectable()
export class CreateCompanyAndContactService {
Expand Down Expand Up @@ -105,7 +105,7 @@ export class CreateCompanyAndContactService {
filteredContactsToCreateWithCompanyDomainNames
.filter((participant) => participant.companyDomainName)
.map((participant) => ({
domainName: participant.companyDomainName!,
domainName: participant.companyDomainName,
createdBySource: source,
createdByWorkspaceMember: connectedAccount.accountOwner,
})),
Expand Down Expand Up @@ -196,7 +196,7 @@ export class CreateCompanyAndContactService {
name: 'person.created',
workspaceId,
// FixMe: TypeORM typing issue... id is always returned when using save
recordId: createdPerson.id!,
recordId: createdPerson.id as string,
objectMetadata,
properties: {
after: createdPerson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/sta
import { computeDisplayName } from 'src/utils/compute-display-name';

type CompanyToCreate = {
domainName: string;
domainName: string | undefined;
createdBySource: FieldActorSource;
createdByWorkspaceMember?: WorkspaceMemberWorkspaceEntity | null;
};
Expand Down Expand Up @@ -186,7 +186,9 @@ export class CreateCompanyService {
return lastCompanyPosition ?? 0;
}

private async getCompanyInfoFromDomainName(domainName: string): Promise<{
private async getCompanyInfoFromDomainName(
domainName: string | undefined,
): Promise<{
name: string;
city: string;
}> {
Expand All @@ -196,12 +198,12 @@ export class CreateCompanyService {
const data = response.data;

return {
name: data.name ?? getCompanyNameFromDomainName(domainName),
name: data.name ?? getCompanyNameFromDomainName(domainName ?? ''),
city: data.city,
};
} catch (e) {
return {
name: getCompanyNameFromDomainName(domainName),
name: getCompanyNameFromDomainName(domainName ?? ''),
city: '',
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/twenty-server/src/queue-worker/queue-worker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NestFactory } from '@nestjs/core';

import { shouldFilterException } from 'src/engine/utils/global-exception-handler.util';
import { ExceptionHandlerService } from 'src/engine/integrations/exception-handler/exception-handler.service';
import { LoggerService } from 'src/engine/integrations/logger/logger.service';
import { shouldFilterException } from 'src/engine/utils/global-exception-handler.util';
import { QueueWorkerModule } from 'src/queue-worker/queue-worker.module';

async function bootstrap() {
Expand All @@ -18,7 +18,7 @@ async function bootstrap() {
exceptionHandlerService = app.get(ExceptionHandlerService);

// Inject our logger
app.useLogger(loggerService!);
app.useLogger(loggerService ?? false);
} catch (err) {
loggerService?.error(err?.message, err?.name);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { DocSearch } from '@docsearch/react';
import { StoredDocSearchHit } from '@docsearch/react/dist/esm/types';
import { env } from 'next-runtime-env';

interface AlgoliaHit extends StoredDocSearchHit {
_snippetResult?: {
content: { value: string };
};
}

interface AlgoliaDocSearchProps {
pathname: string;
}
Expand All @@ -18,7 +11,7 @@ export const AlgoliaDocSearch = ({ pathname }: AlgoliaDocSearchProps) => {
: 'developer';
return (
<DocSearch
hitComponent={({ hit }: { hit: AlgoliaHit }) => (
hitComponent={({ hit }: { hit: any }) => (
<section className="DocSearch-Hits">
<a href={hit.url}>
<div className="DocSearch-Hit-Container">
Expand Down
Loading
Loading