Skip to content

Commit

Permalink
Fix hooks tests (#119)
Browse files Browse the repository at this point in the history
* fix hooks tests

* update circleci version of node

* circleci node version

* move to lts

* update circleci config

* update package json

* node package version install

* fix build docker image

* fix hook tests

* fix snapshots

* zora indexer v1

* fixes

* disable flaky test
  • Loading branch information
iainnash authored May 19, 2022
1 parent 17ef4d5 commit 20ad43c
Show file tree
Hide file tree
Showing 20 changed files with 1,670 additions and 2,842 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
env_defaults: &env_defaults
working_directory: ~
docker:
- image: circleci/node:14.15.1
- image: cimg/node:16.10.0

version: 2.1
jobs:
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
testRegex: "/tests/.*\\.(test|spec)?\\.(ts|tsx)$",
moduleFileExtensions: ['js', 'ts', 'tsx', 'json', 'gql', 'graphql'],
Expand Down
28 changes: 16 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,30 @@
"devDependencies": {
"@graphql-codegen/cli": "^1.21.4",
"@graphql-codegen/typescript": "^1.22.0",
"@graphql-codegen/typescript-graphql-request": "^3.1.1",
"@graphql-codegen/typescript-graphql-request": "^4.4.8",
"@graphql-codegen/typescript-operations": "^1.17.16",
"@graphql-tools/mock": "^8.1.1",
"@graphql-tools/schema": "^7.1.4",
"@jagi/jest-transform-graphql": "^1.0.2",
"@testing-library/react-hooks": "^5.1.2",
"@testing-library/react-hooks": "^8.0.0",
"@types/big.js": "^6.0.2",
"@types/jest": "^26.0.23",
"@types/react": "^18.0.9",
"fetch-mock-jest": "^1.5.1",
"graphql": "^15.5.0",
"graphql-tools": "^7.0.4",
"husky": "^6.0.0",
"jest": "^26.6.3",
"jest-serial-runner": "^1.1.0",
"jest": "^28.0.2",
"jest-environment-jsdom": "^28.1.0",
"jest-runner": "^28.1.0",
"jest-serial-runner": "^1.2.0",
"jest-transform-graphql": "^2.1.0",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"react-test-renderer": "^17.0.2",
"ts-jest": "^26.5.5",
"typescript": "^4.2.4"
"prettier": "^2.6.2",
"react": "^18.1.0",
"react-test-renderer": "^18.1.0",
"ts-jest": "^28.0.2",
"typescript": "^4.6.4"
},
"scripts": {
"publish": "npm publish",
Expand Down Expand Up @@ -68,14 +73,13 @@
"cross-fetch": "^3.1.4",
"dataloader": "^2.0.0",
"deepmerge": "^4.2.2",
"graphql": "^15.5.0",
"graphql-request": "^4.2.0",
"node-abort-controller": "^2.0.0",
"swr": "^0.5.6",
"tslib": "^2.2.0"
"swr": "^1.3.0",
"tslib": "^2.4.0"
},
"prettier": {
"singleQuote": true,
"printWidth": 90
}
}
}
6 changes: 2 additions & 4 deletions src/backends/ens-reverse/EnsReverseFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ export async function reverseResolveEnsAddresses(
const fetcher = new FetchWithTimeout(timeout, 'application/json');
const result = await fetcher.fetch(endpoint, requestOptions);
const json = await result.json();
console.log('json', {json})
const resultAddresses = processReturnData(json.result);
console.log('results', {resultAddresses})
if (resultAddresses.length !== mappingKeys.length) {
throw new Error('Wrong address return length');
}

return mappingKeys.reduce((last, at, index) => {
last[at] = resultAddresses[index];
last[at] = resultAddresses[index] || undefined;
return last;
}, {} as { [name: string]: string });
}, {} as { [name: string]: string | undefined });
}
4 changes: 4 additions & 0 deletions src/backends/zdk-alpha/ZDKAlphaDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export {
} from '../../types/NFTQuery';

function dateToISO(date: string) {
if (!date.endsWith('Z')) {
date += 'Z';
}

return new Date(date).toISOString();
}

Expand Down
4 changes: 4 additions & 0 deletions src/backends/zora-indexer-v1/ZoraIndexerV1DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function unixToISO(unix?: string | number) {
}

function dateToISO(date: string) {
if (!date.endsWith('Z')) {
date += 'Z';
}

return new Date(date).toISOString();
}

Expand Down
1 change: 0 additions & 1 deletion src/fetcher/FetchWithTimeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class FetchWithTimeout {
this.fetch = this.fetch.bind(this);
}
async fetch(url: string, options: any = {}) {
console.log({ url });
const controller = this.controller;
const response = await fetch(url, {
...options,
Expand Down
12 changes: 3 additions & 9 deletions src/hooks/useNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useContext } from 'react';

import { NFTFetchContext } from '../context/NFTFetchContext';
import merge from 'deepmerge';
import useSWR from 'swr';
import useSWR, { SWRConfiguration } from 'swr';
import { NFTStrategy } from '../strategies/NFTStrategy';
import { NFTObject } from '../types/NFTInterface';

Expand All @@ -13,12 +13,6 @@ export type useNFTType = {
data?: NFTObject;
};

type OptionsType = {
refreshInterval?: number;
initialData?: any;
loadCurrencyInfo?: boolean;
useBetaIndexer?: boolean;
};

/**
* Fetches on-chain NFT data and pricing for the given nft contract address and id
Expand All @@ -31,8 +25,8 @@ type OptionsType = {
export function useNFT(
contractAddress?: string,
tokenId?: string,
options: OptionsType = {},
marketOptions: OptionsType = {}
options: SWRConfiguration = {},
marketOptions: SWRConfiguration = {}
): useNFTType {
const dataContext = useContext(NFTFetchContext);

Expand Down
9 changes: 6 additions & 3 deletions src/hooks/useNFTMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from 'react';
import useSWR from 'swr';
import useSWR, { SWRConfiguration } from 'swr';

import { NFTFetchContext } from '../context/NFTFetchContext';

Expand All @@ -17,12 +17,15 @@ export type useNFTMetadataType = {
* @param uri URI of metadata to fetch
* @returns @type useNFTMetadataType
*/
export function useNFTMetadata(uri?: string, initialData?: any): useNFTMetadataType {
export function useNFTMetadata(
uri?: string,
options?: SWRConfiguration
): useNFTMetadataType {
const { fetcher } = useContext(NFTFetchContext);
const { error, data } = useSWR(
uri ? ['loadMetadata', uri] : null,
(_, uri) => fetcher.fetchIPFSMetadata(uri),
{ initialData }
options
);

return {
Expand Down
16 changes: 6 additions & 10 deletions src/hooks/useNFTQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from 'react';
import useSWR from 'swr';
import useSWR, { SWRConfiguration } from 'swr';

import { NFTFetchContext } from '../context/NFTFetchContext';
import { NFTStrategy } from '../strategies/NFTStrategy';
Expand All @@ -11,26 +11,22 @@ export type useNFTQueryType = {
error: Error;
};

type OptionsType = {
refreshInterval?: number;
initialData?: any;
loadCurrencyInfo?: boolean;
useBetaIndexer?: boolean;
};

/**
* Fetches on-chain NFT data and pricing for a given general NFT Query
*
* @param query Query parameter to get list of NFTs for
* @param options Options for SWR flags
* @returns useNFTQueryType results including data and error for resulting NFTs
*/
export function useNFTQuery(query: NFTQuery, options: OptionsType = {}): useNFTQueryType {
export function useNFTQuery(
query: NFTQuery,
options: SWRConfiguration<NFTObject[]>
): useNFTQueryType {
const dataContext = useContext(NFTFetchContext);

const strategy: NFTStrategy = dataContext.strategy;

// run query
// Run query
const { data, error } = useSWR<NFTObject[]>(
query ? ['queryNFTs', JSON.stringify(query)] : null,
(_, queryString) => strategy.queryNFTs(JSON.parse(queryString) as NFTQuery),
Expand Down
Loading

0 comments on commit 20ad43c

Please sign in to comment.