|
| 1 | +import { FetchOptions } from '../merger/types' |
| 2 | +import { OwnersFilters, OwnersSortBy } from './types' |
| 3 | +import { getOwnersQuery } from './utils' |
| 4 | + |
| 5 | +describe('#getOwnersQuery', () => { |
| 6 | + let queryFilters: FetchOptions<OwnersFilters, OwnersSortBy> |
| 7 | + let isCount: boolean |
| 8 | + |
| 9 | + beforeEach(() => { |
| 10 | + queryFilters = { |
| 11 | + contractAddress: 'contractAddress', |
| 12 | + itemId: 'itemId', |
| 13 | + first: 10, |
| 14 | + skip: 10, |
| 15 | + sortBy: OwnersSortBy.ISSUED_ID, |
| 16 | + } |
| 17 | + isCount = false |
| 18 | + }) |
| 19 | + |
| 20 | + describe('when isCount is true', () => { |
| 21 | + beforeEach(() => { |
| 22 | + isCount = true |
| 23 | + }) |
| 24 | + |
| 25 | + it('should have first value in 1000', () => { |
| 26 | + const query = getOwnersQuery(queryFilters, isCount) |
| 27 | + |
| 28 | + expect(query).toContain('first: 1000') |
| 29 | + }) |
| 30 | + |
| 31 | + it('should have skip value as undefined', () => { |
| 32 | + const query = getOwnersQuery(queryFilters, isCount) |
| 33 | + |
| 34 | + expect(query).not.toContain('skip') |
| 35 | + }) |
| 36 | + |
| 37 | + it('should contain id', () => { |
| 38 | + const query = getOwnersQuery(queryFilters, isCount) |
| 39 | + |
| 40 | + expect(query).toContain('id') |
| 41 | + expect(query).not.toContain('...ownerFragment') |
| 42 | + expect(query).not.toContain('fragment ownerFragment on NFT') |
| 43 | + }) |
| 44 | + }) |
| 45 | + |
| 46 | + describe('when isCount is false', () => { |
| 47 | + it('should have first value as first prop', () => { |
| 48 | + const query = getOwnersQuery(queryFilters, isCount) |
| 49 | + |
| 50 | + expect(query).toContain(`first: ${queryFilters.first}`) |
| 51 | + }) |
| 52 | + |
| 53 | + it('should have skip value as skip prop', () => { |
| 54 | + const query = getOwnersQuery(queryFilters, isCount) |
| 55 | + |
| 56 | + expect(query).toContain(`skip: ${queryFilters.skip}`) |
| 57 | + }) |
| 58 | + |
| 59 | + it('should contain ownerFragment', () => { |
| 60 | + const query = getOwnersQuery(queryFilters, isCount) |
| 61 | + |
| 62 | + expect(query).toContain('...ownerFragment') |
| 63 | + expect(query).toContain('fragment ownerFragment on NFT') |
| 64 | + }) |
| 65 | + }) |
| 66 | + |
| 67 | + describe('when the sortby filter is undefined', () => { |
| 68 | + beforeEach(() => { |
| 69 | + delete queryFilters.sortBy |
| 70 | + }) |
| 71 | + |
| 72 | + it('should not contain orderBy', () => { |
| 73 | + const query = getOwnersQuery(queryFilters, isCount) |
| 74 | + |
| 75 | + expect(query).not.toContain(`orderBy`) |
| 76 | + }) |
| 77 | + }) |
| 78 | + |
| 79 | + describe('when sortBy is not undefined', () => { |
| 80 | + it('should have orderBy value as sortBy prop ', () => { |
| 81 | + const query = getOwnersQuery(queryFilters, isCount) |
| 82 | + |
| 83 | + expect(query).toContain(`orderBy: ${queryFilters.sortBy}`) |
| 84 | + }) |
| 85 | + }) |
| 86 | + |
| 87 | + describe('when orderDirection is undefined', () => { |
| 88 | + it('should not contain orderDirection', () => { |
| 89 | + const query = getOwnersQuery(queryFilters, isCount) |
| 90 | + |
| 91 | + expect(query).not.toContain(`orderDirection`) |
| 92 | + }) |
| 93 | + }) |
| 94 | + |
| 95 | + describe('when orderDirection is not undefined', () => { |
| 96 | + beforeEach(() => { |
| 97 | + queryFilters = { ...queryFilters, orderDirection: 'desc' } |
| 98 | + }) |
| 99 | + |
| 100 | + it('should have orderDirection value as orderDirection ', () => { |
| 101 | + const query = getOwnersQuery(queryFilters, isCount) |
| 102 | + |
| 103 | + expect(query).toContain(`orderDirection: ${queryFilters.orderDirection}`) |
| 104 | + }) |
| 105 | + }) |
| 106 | + |
| 107 | + it('should have contractAddress and itemId values as the ones passed by params', () => { |
| 108 | + const query = getOwnersQuery(queryFilters, isCount) |
| 109 | + |
| 110 | + expect(query).toContain(`${queryFilters.contractAddress}`) |
| 111 | + expect(query).toContain(`${queryFilters.itemId}`) |
| 112 | + }) |
| 113 | +}) |
0 commit comments