Skip to content

Commit

Permalink
Merge pull request #919 from ensdomains/bump-msw
Browse files Browse the repository at this point in the history
bump msw
  • Loading branch information
sugh01 authored Jan 14, 2025
2 parents fb6e55b + 8b0e2e8 commit 7e89a3d
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 242 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"jsdom": "^24.1.0",
"knip": "^5.27.2",
"lokijs": "^1.5.12",
"msw": "^1.2.3",
"msw": "^2.6.8",
"multiformats": "^12.0.1",
"next-compose-plugins": "^2.2.1",
"next-dev-https": "^0.1.2",
Expand Down
349 changes: 168 additions & 181 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { act, renderHook, waitFor } from '@app/test-utils'

import { rest } from 'msw'
import { HttpResponse, http } from 'msw'
import { setupServer } from 'msw/node'
import { afterAll, afterEach, beforeAll, describe, expect, it, test, vi } from 'vitest'

import { EARNIFI_ENDPOINT, getErrorMessage, useSubscribeToEarnifi } from './useSubscribeToEarnifi'

export const handlers = [
rest.post(EARNIFI_ENDPOINT, async (req, res, ctx) => {
const { email, address, chainId } = await req.json()
http.post(EARNIFI_ENDPOINT, async ({request}) => {
const { email, address, chainId } = (await request.json()) as Record<string, string>
if (email && address && chainId) {
return res(ctx.status(200))
return HttpResponse.json({}, {status: 200})
}
return res(ctx.status(400), ctx.json({ message: 'Bad Request' }))
return HttpResponse.json({ message: 'Bad Request' }, {status: 400})
}),
]

Expand Down
28 changes: 10 additions & 18 deletions src/utils/SyncProvider/SyncDroppedTransaction.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mockFunction, render } from '@app/test-utils'

import { rest } from 'msw'
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import { getTransaction, getTransactionCount } from 'viem/actions'
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
Expand All @@ -27,18 +27,10 @@ vi.mock('@app/hooks/transactions/TransactionStoreContext')
const ADDRESS = '0x1234567890abcdef'

export const handlers = [
rest.get(getAccountHistoryEndpoint(ADDRESS, 1), (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json([
{
hash: '0xabc123',
input: 'input',
timeStamp: '1',
nonce: 0,
},
]),
)
http.get(getAccountHistoryEndpoint(ADDRESS, 1), () => {
return HttpResponse.json([{ hash: '0xabc123', input: 'input', timeStamp: '1', nonce: 0 }], {
status: 200,
})
}),
]

Expand Down Expand Up @@ -177,10 +169,9 @@ describe('findDroppedTransactions', () => {
})
it('should error if there is more than one transaction that could be a replacement', async () => {
server.use(
rest.get(getAccountHistoryEndpoint(ADDRESS, 1), (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json([
http.get(getAccountHistoryEndpoint(ADDRESS, 1), () => {
return HttpResponse.json(
[
{
hash: '0xabc123',
input: 'input',
Expand All @@ -191,7 +182,8 @@ describe('findDroppedTransactions', () => {
input: 'input',
timeStamp: '1',
},
]),
],
{ status: 200 },
)
}),
)
Expand Down
18 changes: 10 additions & 8 deletions src/utils/date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,23 @@ describe('secondsFromDateDiff', () => {
describe('calculateDateDiff', () => {
it.each([
['2024-01-10', '2025-01-10', '1-0-0'],
['2024-01-10', '2024-02-10', '0-1-0' ],
['2024-01-10', '2024-01-11', '0-0-1' ],
['2024-01-10', '2024-02-10', '0-1-0'],
['2024-01-10', '2024-01-11', '0-0-1'],
['2024-01-10', '2025-01-9', '0-11-30'],
['2024-03-10', '2025-03-9', '0-11-27'],
['2023-03-10', '2024-03-9', '0-11-28'], // leap year
['2024-04-10', '2025-04-9', '0-11-30'],
['2024-04-10', '2025-04-10', '1-0-0' ],
['2024-11-10', '2026-05-1', '1-5-21' ],
['2024-04-10', '2025-04-10', '1-0-0'],
['2024-11-10', '2026-05-1', '1-5-21'],
])(`should return correct diff from %s to %s`, (date1, date2, result) => {
const startDate = new Date(date1)
const endDate = new Date(date2)

const toUnit = (i: number) => i === 0 ? 'years' : i === 1 ? 'months' : 'days'
const dateDiff = Object.fromEntries(result.split('-').map((value, i) => [toUnit(i),parseInt(value)]))
const toUnit = (i: number) => (i === 0 ? 'years' : i === 1 ? 'months' : 'days')
const dateDiff = Object.fromEntries(
result.split('-').map((value, i) => [toUnit(i), parseInt(value)]),
)

expect(calculateDatesDiff(startDate, endDate)).toEqual({ diff: dateDiff, isNegative: false})
expect(calculateDatesDiff(startDate, endDate)).toEqual({ diff: dateDiff, isNegative: false })
})
})
})
14 changes: 7 additions & 7 deletions src/utils/query/reactQuery.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { render, waitFor } from '@app/test-utils'

import { QueryClientProvider } from '@tanstack/react-query'
import { useQuery } from './useQuery'
import { PropsWithChildren, ReactNode } from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { WagmiProvider } from 'wagmi'

import { queryClient } from './reactQuery'
import { useQuery } from './useQuery'
import { wagmiConfig } from './wagmi'

const mockFetchData = vi.fn().mockResolvedValue('Test data')
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('reactQuery', () => {
it('should not refetch query on rerender', async () => {
const { getByTestId, rerender } = render(
<TestComponentWrapper>
<TestComponentWithHook data-testid="test"/>
<TestComponentWithHook data-testid="test" />
</TestComponentWrapper>,
)

Expand All @@ -75,7 +75,7 @@ describe('reactQuery', () => {

rerender(
<TestComponentWrapper>
<TestComponentWithHook data-testid="test"/>
<TestComponentWithHook data-testid="test" />
</TestComponentWrapper>,
)

Expand All @@ -88,7 +88,7 @@ describe('reactQuery', () => {
it('should refetch query on mount', async () => {
const { getByTestId, unmount } = render(
<TestComponentWrapper>
<TestComponentWithHook data-testid="test"/>
<TestComponentWithHook data-testid="test" />
</TestComponentWrapper>,
)

Expand All @@ -100,7 +100,7 @@ describe('reactQuery', () => {
unmount()
const { getByTestId: getByTestId2 } = render(
<TestComponentWrapper>
<TestComponentWithHook data-testid="test"/>
<TestComponentWithHook data-testid="test" />
</TestComponentWrapper>,
)

Expand All @@ -114,7 +114,7 @@ describe('reactQuery', () => {
const { getByTestId, unmount } = render(
<TestComponentWrapper>
<TestComponentWithHook data-testid="test">
<TestComponentWithHook data-testid="nested"/>
<TestComponentWithHook data-testid="nested" />
</TestComponentWithHook>
</TestComponentWrapper>,
)
Expand All @@ -129,7 +129,7 @@ describe('reactQuery', () => {
const { getByTestId: getByTestId2 } = render(
<TestComponentWrapper>
<TestComponentWithHook data-testid="test">
<TestComponentWithHook data-testid="nested"/>
<TestComponentWithHook data-testid="nested" />
</TestComponentWithHook>
</TestComponentWrapper>,
)
Expand Down
37 changes: 18 additions & 19 deletions src/utils/records/categoriseProfileTextRecords.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { vi, describe, it, expect } from 'vitest'
import { describe, expect, it, vi } from 'vitest'

import { categoriseAndTransformTextRecords } from './categoriseProfileTextRecords'

describe('categoriseProfileTextRecords', () => {
it('should return text records correctly categorised', () => {
const result = categoriseAndTransformTextRecords({
texts: [
{ key: 'com.twitter', value: 'name'},
{ key: 'other', value: 'value'},
{ key: 'description', value: 'description'},
{ key: 'com.twitter', value: 'name' },
{ key: 'other', value: 'value' },
{ key: 'description', value: 'description' },
],
contentHash: 'ipfs://contenthash',
appendVerificationProps: (record: any) => ({
Expand All @@ -17,35 +18,35 @@ describe('categoriseProfileTextRecords', () => {
}),
})
expect(result).toEqual({
general: [ { key: 'description', value: 'description' } ],
general: [{ key: 'description', value: 'description' }],
accounts: [
{
key: 'com.twitter',
normalisedKey: 'com.twitter',
value: '@name',
isVerified: true,
verifiers: ['dentity'],
iconKey: 'com.twitter'
}
iconKey: 'com.twitter',
},
],
other: [
{ key: 'other', value: 'value', type: 'text', iconKey: 'other' },
{
key: 'contenthash',
value: 'ipfs://contenthash',
type: 'contenthash',
iconKey: 'contenthash'
}
]
iconKey: 'contenthash',
},
],
})
})

it('should not return a contenthash record item if it is undefined', () => {
const result = categoriseAndTransformTextRecords({
texts: [
{ key: 'com.twitter', value: 'name'},
{ key: 'other', value: 'value'},
{ key: 'description', value: 'description'},
{ key: 'com.twitter', value: 'name' },
{ key: 'other', value: 'value' },
{ key: 'description', value: 'description' },
],
contentHash: undefined,
appendVerificationProps: (record: any) => ({
Expand All @@ -55,20 +56,18 @@ describe('categoriseProfileTextRecords', () => {
}),
})
expect(result).toEqual({
general: [ { key: 'description', value: 'description' } ],
general: [{ key: 'description', value: 'description' }],
accounts: [
{
key: 'com.twitter',
normalisedKey: 'com.twitter',
value: '@name',
isVerified: true,
verifiers: ['dentity'],
iconKey: 'com.twitter'
}
iconKey: 'com.twitter',
},
],
other: [
{ key: 'other', value: 'value', type: 'text', iconKey: 'other' },
]
other: [{ key: 'other', value: 'value', type: 'text', iconKey: 'other' }],
})
})
})
2 changes: 1 addition & 1 deletion src/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('formatDurationOfDates', () => {
formatDurationOfDates({
startDate: new Date(),
endDate: new Date(Date.now() + 123 * 1000),
t: (x, options: any) => x + options?.count,
t: (x, options: any) => x + options?.count,
}),
).toEqual('unit.days0')
})
Expand Down
5 changes: 3 additions & 2 deletions src/utils/verification/isVerificationProtocol.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isVerificationProtocol } from "./isVerificationProtocol";
import { describe, it, expect } from "vitest";
import { describe, expect, it } from 'vitest'

import { isVerificationProtocol } from './isVerificationProtocol'

describe('isVerificationProtocol', () => {
it.each(['dentity'])('should return true for protocol: %s', (protocol) => {
Expand Down

0 comments on commit 7e89a3d

Please sign in to comment.