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

Improve tests #5994

Merged
merged 4 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/twenty-front/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const jestConfig: JestConfigWithTsJest = {
coverageThreshold: {
global: {
statements: 65,
lines: 65,
lines: 64,
functions: 55,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { expect } from '@storybook/test';

import { CaptchaDriverType } from '~/generated/graphql';

import { getCaptchaUrlByProvider } from '../getCaptchaUrlByProvider';

describe('getCaptchaUrlByProvider', () => {
it('handles GoogleRecatpcha', async () => {
const captchaUrl = getCaptchaUrlByProvider(
CaptchaDriverType.GoogleRecatpcha,
'siteKey',
);

expect(captchaUrl).toEqual(
'https://www.google.com/recaptcha/api.js?render=siteKey',
);

expect(() =>
getCaptchaUrlByProvider(CaptchaDriverType.GoogleRecatpcha, ''),
).toThrow(
'SiteKey must be provided while generating url for GoogleRecaptcha provider',
);
});

it('handles Turnstile', async () => {
const captchaUrl = getCaptchaUrlByProvider(CaptchaDriverType.Turnstile, '');

expect(captchaUrl).toEqual(
'https://challenges.cloudflare.com/turnstile/v0/api.js',
);
});

it('handles unknown provider', async () => {
expect(() =>
getCaptchaUrlByProvider('Unknown' as CaptchaDriverType, ''),
).toThrow('Unknown captcha provider');
});
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { CaptchaDriverType } from '~/generated-metadata/graphql';
import { isNonEmptyString } from '@sniptt/guards';

export const getCaptchaUrlByProvider = (name: string, siteKey: string) => {
if (!name) {
return '';
}
import { CaptchaDriverType } from '~/generated-metadata/graphql';

export const getCaptchaUrlByProvider = (
name: CaptchaDriverType,
siteKey: string,
) => {
switch (name) {
case CaptchaDriverType.GoogleRecatpcha:
if (!isNonEmptyString(siteKey)) {
throw new Error(
'SiteKey must be provided while generating url for GoogleRecaptcha provider',
);
}
return `https://www.google.com/recaptcha/api.js?render=${siteKey}`;
case CaptchaDriverType.Turnstile:
return 'https://challenges.cloudflare.com/turnstile/v0/api.js';
default:
return '';
throw new Error('Unknown captcha provider');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getForeignDataWrapperType } from '../getForeignDataWrapperType';

describe('getForeignDataWrapperType', () => {
it('should handle postgres', () => {
expect(getForeignDataWrapperType('postgresql')).toBe('postgres_fdw');
});

it('should handle postgres', () => {
expect(getForeignDataWrapperType('stripe')).toBe('stripe_fdw');
});

it('should return null for unknown', () => {
expect(getForeignDataWrapperType('unknown')).toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { AppPath } from '@/types/AppPath';

import indexAppPath from '../indexAppPath';

describe('getIndexAppPath', () => {
it('returns the index app path', () => {
const { getIndexAppPath } = indexAppPath;
expect(getIndexAppPath()).toEqual(AppPath.Index);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ export const SETTINGS_FIELD_CURRENCY_CODES: Record<
BRL: {
label: 'Brazilian real',
Icon: IconCurrencyReal,
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { getSettingsIntegrationAll } from '../getSettingsIntegrationAll';

describe('getSettingsIntegrationAll', () => {
it('should return null if imageUrl is null', () => {
expect(
getSettingsIntegrationAll({
isAirtableIntegrationActive: true,
isAirtableIntegrationEnabled: true,
isPostgresqlIntegrationActive: true,
isPostgresqlIntegrationEnabled: true,
isStripeIntegrationActive: true,
isStripeIntegrationEnabled: true,
}),
).toStrictEqual({
integrations: [
{
from: {
image: '/images/integrations/airtable-logo.png',
key: 'airtable',
},
link: '/settings/integrations/airtable',
text: 'Airtable',
type: 'Active',
},
{
from: {
image: '/images/integrations/postgresql-logo.png',
key: 'postgresql',
},
link: '/settings/integrations/postgresql',
text: 'PostgreSQL',
type: 'Active',
},
{
from: {
image: '/images/integrations/stripe-logo.png',
key: 'stripe',
},
link: '/settings/integrations/stripe',
text: 'Stripe',
type: 'Active',
},
],
key: 'all',
title: 'All',
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getImageAbsoluteURIOrBase64 } from '../getImageAbsoluteURIOrBase64';

describe('getImageAbsoluteURIOrBase64', () => {
it('should return null if imageUrl is null', () => {
const imageUrl = null;
const result = getImageAbsoluteURIOrBase64(imageUrl);
expect(result).toBeNull();
});

it('shoud return base64 encoded string if prefixed with data', () => {
const imageUrl = 'data:XXX';
const result = getImageAbsoluteURIOrBase64(imageUrl);
expect(result).toBe(imageUrl);
});

it('shoud return absolute url if the imageUrl is an absolute url', () => {
const imageUrl = 'https://XXX';
const result = getImageAbsoluteURIOrBase64(imageUrl);
expect(result).toBe(imageUrl);
});

it('should return fully formed url if imageUrl is a relative url', () => {
const imageUrl = 'XXX';
const result = getImageAbsoluteURIOrBase64(imageUrl);
expect(result).toBe('http://localhost:3000/files/XXX');
});
});
Loading