Skip to content

Commit ce47858

Browse files
author
iyashragrawal
committed
feat: add tests for simple collections
1 parent da637e4 commit ce47858

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { Image } from './types'
2+
import { createSetImagesCaller } from './setImages'
3+
import { stubTransactionResposeFactory } from '../../common/utils/for-test'
4+
5+
describe('setImages.spec.ts', () => {
6+
describe('createSetImages', () => {
7+
it('call success', async () => {
8+
const propertyAddress = '0x0000000000000000000000000000000000000000'
9+
const images = [
10+
{
11+
src: 'https://example.com',
12+
requiredETHAmount: 0,
13+
requiredETHFee: 0,
14+
gateway: '0x0000000000000000000000000000000000000000',
15+
},
16+
]
17+
const keys = ['0x000']
18+
19+
const success = stubTransactionResposeFactory({})
20+
const devContract = {
21+
setImages: jest
22+
.fn()
23+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
24+
.mockImplementation(
25+
async (
26+
propertyAddress: string,
27+
images: readonly Image[],
28+
keys: readonly string[]
29+
) => success
30+
),
31+
}
32+
const expected = success
33+
const caller = createSetImagesCaller(devContract as any)
34+
const result = await caller(propertyAddress, images, keys)
35+
36+
expect(result).toEqual(expected)
37+
})
38+
39+
it('call failure', async () => {
40+
const propertyAddress = '0x0000000000000000000000000000000000000000'
41+
const images = [
42+
{
43+
src: 'https://example.com',
44+
requiredETHAmount: 0,
45+
requiredETHFee: 0,
46+
gateway: '0x0000000000000000000000000000000000000000',
47+
},
48+
]
49+
const keys = ['0x000']
50+
51+
const error = 'error'
52+
const devContract = {
53+
setImages: jest
54+
.fn()
55+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
56+
.mockImplementation(
57+
async (
58+
propertyAddress: string,
59+
images: readonly Image[],
60+
keys: readonly string[]
61+
) => Promise.reject(error)
62+
),
63+
}
64+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
65+
const caller = createSetImagesCaller(devContract as any)
66+
const result = await caller(propertyAddress, images, keys).catch(
67+
(err) => err
68+
)
69+
70+
expect(result).toEqual(error)
71+
})
72+
})
73+
})

0 commit comments

Comments
 (0)