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 more api test cases #4449

Merged
merged 6 commits into from
Dec 29, 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
33 changes: 0 additions & 33 deletions apps/api/src/routes/ipfs/pin.ts

This file was deleted.

54 changes: 54 additions & 0 deletions apps/api/tests/feed/ids.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { AlgorithmProvider } from '@hey/data/enums';
import { TEST_URL } from '@utils/constants';
import axios from 'axios';
import { describe, expect, test } from 'vitest';

describe('feed/ids', () => {
test('should return most viewed ids from hey', async () => {
const response = await axios.get(`${TEST_URL}/feed/ids`, {
params: { provider: AlgorithmProvider.HEY, strategy: 'mostviewed' }
});

expect(response.data.ids).toHaveLength(50);
});

test('should return most interacted ids from hey', async () => {
const response = await axios.get(`${TEST_URL}/feed/ids`, {
params: { provider: AlgorithmProvider.HEY, strategy: 'mostinteracted' }
});

expect(response.data.ids).toHaveLength(50);
});

test('should return recommended ids from k3l', async () => {
const response = await axios.get(`${TEST_URL}/feed/ids`, {
params: { provider: AlgorithmProvider.K3L, strategy: 'recommended' }
});

expect(response.data.ids).toHaveLength(50);
});

test('should return popular ids from k3l', async () => {
const response = await axios.get(`${TEST_URL}/feed/ids`, {
params: { provider: AlgorithmProvider.K3L, strategy: 'popular' }
});

expect(response.data.ids).toHaveLength(50);
});

test('should return recent ids from k3l', async () => {
const response = await axios.get(`${TEST_URL}/feed/ids`, {
params: { provider: AlgorithmProvider.K3L, strategy: 'recent' }
});

expect(response.data.ids).toHaveLength(50);
});

test('should return crowdsourced ids from k3l', async () => {
const response = await axios.get(`${TEST_URL}/feed/ids`, {
params: { provider: AlgorithmProvider.K3L, strategy: 'crowdsourced' }
});

expect(response.data.ids).toHaveLength(50);
});
});
19 changes: 19 additions & 0 deletions apps/api/tests/leafwatch/events.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { PAGEVIEW } from '@hey/data/tracking';
import { TEST_URL } from '@utils/constants';
import axios from 'axios';
import { describe, expect, test } from 'vitest';

describe('leafwatch/events', () => {
test('should push event to leafwatch', async () => {
const response = await axios.post(`${TEST_URL}/leafwatch/events`, {
actor: '0x0d',
name: PAGEVIEW,
platform: 'web',
properties: { page: 'explore' },
referrer: null,
url: 'https://hey.xyz/explore'
});

expect(response.data.id).toHaveLength(36);
});
});
14 changes: 14 additions & 0 deletions apps/api/tests/leafwatch/impressions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TEST_URL } from '@utils/constants';
import axios from 'axios';
import { describe, expect, test } from 'vitest';

describe('leafwatch/impressions', () => {
test('should push impressions to leafwatch', async () => {
const response = await axios.post(`${TEST_URL}/leafwatch/impressions`, {
ids: ['0x0d-0x01', '0x0d-0x02'],
viewer_id: '0x0d'
});

expect(response.data.id).toHaveLength(36);
});
});
16 changes: 16 additions & 0 deletions apps/api/tests/live/create.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import getAuthWorkerHeadersForTest from '@hey/lib/getAuthWorkerHeadersForTest';
import { TEST_URL } from '@utils/constants';
import axios from 'axios';
import { describe, expect, test } from 'vitest';

describe('live/create', () => {
test('should return created live stream', async () => {
const response = await axios.post(
`${TEST_URL}/live/create`,
{ record: true },
{ headers: await getAuthWorkerHeadersForTest() }
);

expect(response.data.result.createdByTokenName).toEqual('Hey Live');
});
});
13 changes: 13 additions & 0 deletions apps/api/tests/metadata/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { TEST_URL } from '@utils/constants';
import axios from 'axios';
import { describe, expect, test } from 'vitest';

describe('metadata/index', () => {
test('should return ens names', async () => {
const response = await axios.post(`${TEST_URL}/metadata`, {
ping: 'pong'
});

expect(response.data.id).toHaveLength(43);
});
});
3 changes: 0 additions & 3 deletions apps/web/src/lib/uploadToIPFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ const uploadToIPFS = async (
const metadata = result.Metadata;
const cid = metadata?.['ipfs-hash'];

// Pin the file to the Lens IPFS network.
axios.get(`${HEY_API_URL}/ipfs/pin`, { params: { cid } });

return { mimeType: file.type || FALLBACK_TYPE, uri: `ipfs://${cid}` };
})
);
Expand Down
6 changes: 5 additions & 1 deletion packages/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const PUBLICACT_PROXY = getEnvConfig().publicActProxyAddress;
export const DEFAULT_COLLECT_TOKEN = getEnvConfig().defaultCollectToken;

export const IS_MAINNET = LENS_API_URL === LensEndpoint.Mainnet;
export const REWARDS_ADDRESS = '0xf618330f51fa54ce5951d627ee150c0fdadeba43';
export const ADDRESS_PLACEHOLDER = '0x03Ba3...7EF';

// Application
Expand All @@ -33,6 +32,11 @@ export const GIT_COMMIT_SHA =

// Misc
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
export const REWARDS_ADDRESS = '0xf618330f51fa54ce5951d627ee150c0fdadeba43';
export const TEST_WALLET_ADDRESS = '0xb9C6e304545386E95d5c4ab183EE97A13555A49d';
export const TEST_PK =
'0x8b33302ca865bc1ed65bc02b71dd02067bd3dae3da2f8bb0d95b16509e9ac71e';
export const TEST_LENS_ID = '0x0383';
export const HANDLE_PREFIX = IS_MAINNET ? 'lens/' : 'test/';

// URLs
Expand Down
59 changes: 59 additions & 0 deletions packages/lib/getAuthWorkerHeadersForTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ApolloClient, from, HttpLink, InMemoryCache } from '@apollo/client';
import {
TEST_LENS_ID,
TEST_PK,
TEST_WALLET_ADDRESS
} from '@hey/data/constants';
import LensEndpoint from '@hey/data/lens-endpoints';
import { AuthenticateDocument, ChallengeDocument } from '@hey/lens';
import { createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { polygonMumbai } from 'viem/chains';

const httpLink = new HttpLink({
fetch,
fetchOptions: 'no-cors',
uri: LensEndpoint.Staging
});

const apolloClient = () =>
new ApolloClient({
cache: new InMemoryCache({}),
link: from([httpLink])
});

const getAuthWorkerHeadersForTest = async () => {
const account = privateKeyToAccount(TEST_PK);
const client = createWalletClient({
account,
chain: polygonMumbai,
transport: http()
});

// Get challenge
const { data: challenge } = await apolloClient().query({
query: ChallengeDocument,
variables: { request: { for: TEST_LENS_ID, signedBy: TEST_WALLET_ADDRESS } }
});

if (!challenge?.challenge?.text) {
throw new Error('Challenge failed');
}

// Get signature
const signature = await client.signMessage({
message: challenge.challenge.text
});

// Auth user
const { data: auth } = await apolloClient().mutate({
mutation: AuthenticateDocument,
variables: { request: { id: challenge.challenge.id, signature } }
});

const accessToken = auth?.authenticate.accessToken;

return { 'X-Access-Token': accessToken, 'X-Lens-Network': 'testnet' };
};

export default getAuthWorkerHeadersForTest;
2 changes: 1 addition & 1 deletion packages/lib/getPublicationIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getPublicationIds = async (
profile?: string
) => {
try {
const response = await axios.get(`${HEY_API_URL}/feed/getPublicationIds`, {
const response = await axios.get(`${HEY_API_URL}/feed/ids`, {
params: {
limit,
offset,
Expand Down
1 change: 1 addition & 0 deletions packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"typecheck": "tsc --pretty"
},
"dependencies": {
"@apollo/client": "^3.8.8",
"@hey/data": "workspace:*",
"@hey/lens": "workspace:*",
"@hey/types": "workspace:*",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading