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

feat: add tests for imageProxy #1958

Merged
merged 2 commits into from
Mar 16, 2023
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
2 changes: 1 addition & 1 deletion apps/web/src/components/Notification/WalletProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Image } from '@components/UI/Image';
import imageProxy from '@lib/imageProxy';
import { POLYGONSCAN_URL } from 'data/constants';
import type { Wallet } from 'lens';
import type { FC } from 'react';
import formatAddress from 'utils/formatAddress';
import getStampFyiURL from 'utils/getStampFyiURL';
import imageProxy from 'utils/imageProxy';

interface NotificationWalletProfileProps {
wallet: Wallet;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Profile/Cover.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import imageProxy from '@lib/imageProxy';
import { COVER, STATIC_IMAGES_URL } from 'data/constants';
import type { FC } from 'react';
import getIPFSLink from 'utils/getIPFSLink';
import imageProxy from 'utils/imageProxy';

interface CoverProps {
cover: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Settings/Profile/Picture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Modal } from '@components/UI/Modal';
import { Spinner } from '@components/UI/Spinner';
import { PencilIcon } from '@heroicons/react/outline';
import getSignature from '@lib/getSignature';
import imageProxy from '@lib/imageProxy';
import { Mixpanel } from '@lib/mixpanel';
import onError from '@lib/onError';
import splitSignature from '@lib/splitSignature';
Expand All @@ -28,6 +27,7 @@ import toast from 'react-hot-toast';
import { useAppStore } from 'src/store/app';
import { SETTINGS } from 'src/tracking';
import getIPFSLink from 'utils/getIPFSLink';
import imageProxy from 'utils/imageProxy';
import { useContractWrite, useSignTypedData } from 'wagmi';

import ImageCropperController from './ImageCropperController';
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Settings/Profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { PencilIcon } from '@heroicons/react/outline';
import getProfileAttribute from '@lib/getProfileAttribute';
import getSignature from '@lib/getSignature';
import hasPrideLogo from '@lib/hasPrideLogo';
import imageProxy from '@lib/imageProxy';
import { Mixpanel } from '@lib/mixpanel';
import onError from '@lib/onError';
import splitSignature from '@lib/splitSignature';
Expand All @@ -33,6 +32,7 @@ import toast from 'react-hot-toast';
import { useAppStore } from 'src/store/app';
import { SETTINGS } from 'src/tracking';
import getIPFSLink from 'utils/getIPFSLink';
import imageProxy from 'utils/imageProxy';
import { v4 as uuid } from 'uuid';
import { useContractWrite, useSignTypedData } from 'wagmi';
import { object, string, union } from 'zod';
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/Attachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Image } from '@components/UI/Image';
import { LightBox } from '@components/UI/LightBox';
import type { NewLensterAttachment } from '@generated/types';
import { ExternalLinkIcon, XIcon } from '@heroicons/react/outline';
import imageProxy from '@lib/imageProxy';
import { Mixpanel } from '@lib/mixpanel';
import { stopEventPropagation } from '@lib/stopEventPropagation';
import { Trans } from '@lingui/macro';
Expand All @@ -15,6 +14,7 @@ import { useState } from 'react';
import { usePublicationStore } from 'src/store/publication';
import { PUBLICATION } from 'src/tracking';
import getIPFSLink from 'utils/getIPFSLink';
import imageProxy from 'utils/imageProxy';

import Audio from './Audio';
import Video from './Video';
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/Audio/CoverImage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Image } from '@components/UI/Image';
import { Spinner } from '@components/UI/Spinner';
import { PhotographIcon } from '@heroicons/react/outline';
import imageProxy from '@lib/imageProxy';
import uploadToIPFS from '@lib/uploadToIPFS';
import clsx from 'clsx';
import { ATTACHMENT, ERROR_MESSAGE } from 'data/constants';
import type { ChangeEvent, FC, Ref } from 'react';
import { useState } from 'react';
import toast from 'react-hot-toast';
import getIPFSLink from 'utils/getIPFSLink';
import imageProxy from 'utils/imageProxy';

interface CoverImageProps {
isNew: boolean;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/IFramely/Embed.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Card } from '@components/UI/Card';
import { Image } from '@components/UI/Image';
import type { OG } from '@generated/types';
import imageProxy from '@lib/imageProxy';
import { Mixpanel } from '@lib/mixpanel';
import { stopEventPropagation } from '@lib/stopEventPropagation';
import { ATTACHMENT } from 'data/constants';
import Link from 'next/link';
import type { FC } from 'react';
import { PUBLICATION } from 'src/tracking';
import imageProxy from 'utils/imageProxy';

interface EmbedProps {
og: OG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
TypeaheadOption,
useBasicTypeaheadTriggerMatch
} from '@lexical/react/LexicalTypeaheadMenuPlugin';
import imageProxy from '@lib/imageProxy';
import isVerified from '@lib/isVerified';
import clsx from 'clsx';
import { AVATAR } from 'data/constants';
Expand All @@ -19,6 +18,7 @@ import * as ReactDOM from 'react-dom';
import formatHandle from 'utils/formatHandle';
import getIPFSLink from 'utils/getIPFSLink';
import getStampFyiURL from 'utils/getStampFyiURL';
import imageProxy from 'utils/imageProxy';

import { $createMentionNode } from '../Nodes/MentionsNode';

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/Video.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'plyr-react/plyr.css';

import imageProxy from '@lib/imageProxy';
import Plyr from 'plyr-react';
import type { FC } from 'react';
import { memo } from 'react';
import getIPFSLink from 'utils/getIPFSLink';
import imageProxy from 'utils/imageProxy';

interface VideoProps {
src: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/WalletProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Image } from '@components/UI/Image';
import { ExternalLinkIcon } from '@heroicons/react/outline';
import imageProxy from '@lib/imageProxy';
import { POLYGONSCAN_URL } from 'data/constants';
import type { Wallet } from 'lens';
import type { FC } from 'react';
import formatAddress from 'utils/formatAddress';
import getStampFyiURL from 'utils/getStampFyiURL';
import imageProxy from 'utils/imageProxy';

import Slug from './Slug';

Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/lib/getAvatar.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AVATAR, ZERO_ADDRESS } from 'data/constants';
import getIPFSLink from 'utils/getIPFSLink';
import getStampFyiURL from 'utils/getStampFyiURL';

import imageProxy from './imageProxy';
import imageProxy from 'utils/imageProxy';

const skipList = [
'static-assets.lenster.xyz',
Expand Down
8 changes: 7 additions & 1 deletion apps/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@
"@generated*": ["src/generated*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "src/styles/index.css"]
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"src/styles/index.css",
"../../packages/utils/imageProxy.ts"
]
}
File renamed without changes.
17 changes: 17 additions & 0 deletions tests/scripts/utils/imageProxy.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from '@playwright/test';
import { AVATAR, USER_CONTENT_URL } from 'data/constants';
import imageProxy from 'utils/imageProxy';

test.describe('imageProxy', async () => {
test('should return a url with just the image url when no name is provided', async () => {
const url = 'image.jpg';
const result = imageProxy(url);
await expect(result).toEqual(`${USER_CONTENT_URL}/${url}`);
});

test('should return a url with the image url and name when name is provided', async () => {
const url = 'image.jpg';
const result = imageProxy(url, AVATAR);
await expect(result).toEqual(`${USER_CONTENT_URL}/${AVATAR}/${url}`);
});
});