Skip to content

Commit

Permalink
Merge pull request #112 from poap-xyz/fix/filter-poaps-with-collector…
Browse files Browse the repository at this point in the history
…-and-not-null-filter

Fix fetch POAPs with collector and without null address filter
  • Loading branch information
jm42 authored Apr 18, 2024
2 parents 5aefad9 + 54e5980 commit 132af67
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npm_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn install --immutable

- name: Check package versions and publish
run: yarn publish
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm_publish_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
git config user.email "[email protected]"
- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn install --immutable

- name: Check package versions and publish
run: yarn publish-beta $GITHUB_REF_NAME
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn install --immutable

- name: Build packages
run: yarn build
Expand Down
6 changes: 3 additions & 3 deletions packages/drops/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/drops",
"version": "0.2.1",
"version": "0.2.2",
"description": "Drops module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down Expand Up @@ -29,7 +29,7 @@
"node": ">=18"
},
"dependencies": {
"@poap-xyz/providers": "0.2.1",
"@poap-xyz/utils": "0.2.1"
"@poap-xyz/providers": "0.2.2",
"@poap-xyz/utils": "0.2.2"
}
}
6 changes: 3 additions & 3 deletions packages/moments/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/moments",
"version": "0.2.1",
"version": "0.2.2",
"description": "Moments module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -26,8 +26,8 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/providers": "0.2.1",
"@poap-xyz/utils": "0.2.1",
"@poap-xyz/providers": "0.2.2",
"@poap-xyz/utils": "0.2.2",
"uuid": "^9.0.0"
},
"engines": {
Expand Down
6 changes: 3 additions & 3 deletions packages/poaps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/poaps",
"version": "0.2.1",
"version": "0.2.2",
"description": "Poaps module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -26,8 +26,8 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/providers": "0.2.1",
"@poap-xyz/utils": "0.2.1"
"@poap-xyz/providers": "0.2.2",
"@poap-xyz/utils": "0.2.2"
},
"engines": {
"node": ">=18"
Expand Down
12 changes: 7 additions & 5 deletions packages/poaps/src/PoapsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ export class PoapsClient {
orderBy: createOrderBy<PoapsSortFields>(sortField, sortDir),
where: {
...createAddressFilter('collector_address', collectorAddress),
...createNotNullAddressFilter(
'collector_address',
filterZeroAddress,
filterDeadAddress,
),
...(collectorAddress == undefined
? createNotNullAddressFilter(
'collector_address',
filterZeroAddress,
filterDeadAddress,
)
: {}),
...createEqFilter('chain', chain),
...createEqFilter('drop_id', dropId),
...createBetweenFilter('minted_on', mintedDateFrom, mintedDateTo),
Expand Down
188 changes: 188 additions & 0 deletions packages/poaps/test/PoapsClient.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import { MockProxy, anyString, mock } from 'jest-mock-extended';
import { CompassProvider, TokensApiProvider } from '@poap-xyz/providers';
import { PoapsClient } from '../src/PoapsClient';

describe('PoapsClient', () => {
let compassProviderMock: MockProxy<CompassProvider>;
let tokensApiProviderMock: MockProxy<TokensApiProvider>;

let poapsClient: PoapsClient;

beforeEach(() => {
compassProviderMock = mock<CompassProvider>();
tokensApiProviderMock = mock<TokensApiProvider>();

poapsClient = new PoapsClient(compassProviderMock, tokensApiProviderMock);
});

describe('fetch', () => {
it('request all tokens except zero address and dead address when no filter is given', async () => {
// Given
compassProviderMock.request.mockResolvedValue({
data: {
poaps: [],
},
});

// When
await poapsClient.fetch({
limit: 1,
offset: 0,
});

// Then
expect(compassProviderMock.request).toHaveBeenCalledWith(anyString(), {
limit: 1,
offset: 0,
orderBy: {},
where: {
collector_address: {
_nin: [
'0x0000000000000000000000000000000000000000',
'0x000000000000000000000000000000000000dead',
],
},
},
});
});

it('request all tokens including zero address and dead address when those filters are given on false', async () => {
// Given
compassProviderMock.request.mockResolvedValue({
data: {
poaps: [],
},
});

// When
await poapsClient.fetch({
limit: 1,
offset: 0,
filterZeroAddress: false,
filterDeadAddress: false,
});

// Then
expect(compassProviderMock.request).toHaveBeenCalledWith(anyString(), {
limit: 1,
offset: 0,
orderBy: {},
where: {},
});
});

it('request all tokens except dead address but include zero address when filter is given on false', async () => {
// Given
compassProviderMock.request.mockResolvedValue({
data: {
poaps: [],
},
});

// When
await poapsClient.fetch({
limit: 1,
offset: 0,
filterZeroAddress: false,
});

// Then
expect(compassProviderMock.request).toHaveBeenCalledWith(anyString(), {
limit: 1,
offset: 0,
orderBy: {},
where: {
collector_address: {
_neq: '0x000000000000000000000000000000000000dead',
},
},
});
});

it('request all tokens except zero address but include dead address when filter is given on false', async () => {
// Given
compassProviderMock.request.mockResolvedValue({
data: {
poaps: [],
},
});

// When
await poapsClient.fetch({
limit: 1,
offset: 0,
filterDeadAddress: false,
});

// Then
expect(compassProviderMock.request).toHaveBeenCalledWith(anyString(), {
limit: 1,
offset: 0,
orderBy: {},
where: {
collector_address: {
_neq: '0x0000000000000000000000000000000000000000',
},
},
});
});

it('request tokens for collector when collectorAddress filter is given', async () => {
// Given
compassProviderMock.request.mockResolvedValue({
data: {
poaps: [],
},
});

// When
await poapsClient.fetch({
limit: 1,
offset: 0,
collectorAddress: '0xf6b6f07862a02c85628b3a9688beae07fea9c863',
});

// Then
expect(compassProviderMock.request).toHaveBeenCalledWith(anyString(), {
limit: 1,
offset: 0,
orderBy: {},
where: {
collector_address: {
_eq: '0xf6b6f07862a02c85628b3a9688beae07fea9c863',
},
},
});
});

it('request tokens for collector when collectorAddress filter is given without null address filter even when given', async () => {
// Given
compassProviderMock.request.mockResolvedValue({
data: {
poaps: [],
},
});

// When
await poapsClient.fetch({
limit: 1,
offset: 0,
collectorAddress: '0xf6b6f07862a02c85628b3a9688beae07fea9c863',
filterZeroAddress: true,
filterDeadAddress: true,
});

// Then
expect(compassProviderMock.request).toHaveBeenCalledWith(anyString(), {
limit: 1,
offset: 0,
orderBy: {},
where: {
collector_address: {
_eq: '0xf6b6f07862a02c85628b3a9688beae07fea9c863',
},
},
});
});
});
});
5 changes: 0 additions & 5 deletions packages/poaps/test/index.spec.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/providers",
"version": "0.2.1",
"version": "0.2.2",
"description": "Providers module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -26,7 +26,7 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/utils": "0.2.1",
"@poap-xyz/utils": "0.2.2",
"axios": "^1.3.5"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/utils",
"version": "0.2.1",
"version": "0.2.2",
"description": "Utils module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/queries/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function createAddressFilter(

export function createNotNullAddressFilter(
key: string,
filterZeroAddress = true,
filterDeadAddress = true,
filterZeroAddress?: boolean,
filterDeadAddress?: boolean,
): FieldFilter<NeqFilter<string>> | FieldFilter<NinFilter<string>> {
if (filterZeroAddress && filterDeadAddress) {
return {
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/drops@workspace:packages/drops"
dependencies:
"@poap-xyz/providers": 0.2.1
"@poap-xyz/utils": 0.2.1
"@poap-xyz/providers": 0.2.2
"@poap-xyz/utils": 0.2.2
languageName: unknown
linkType: soft

Expand All @@ -901,8 +901,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/moments@workspace:packages/moments"
dependencies:
"@poap-xyz/providers": 0.2.1
"@poap-xyz/utils": 0.2.1
"@poap-xyz/providers": 0.2.2
"@poap-xyz/utils": 0.2.2
"@types/uuid": ^9.0.2
uuid: ^9.0.0
languageName: unknown
Expand All @@ -912,22 +912,22 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/poaps@workspace:packages/poaps"
dependencies:
"@poap-xyz/providers": 0.2.1
"@poap-xyz/utils": 0.2.1
"@poap-xyz/providers": 0.2.2
"@poap-xyz/utils": 0.2.2
languageName: unknown
linkType: soft

"@poap-xyz/providers@*, @poap-xyz/[email protected].1, @poap-xyz/providers@workspace:packages/providers":
"@poap-xyz/providers@*, @poap-xyz/[email protected].2, @poap-xyz/providers@workspace:packages/providers":
version: 0.0.0-use.local
resolution: "@poap-xyz/providers@workspace:packages/providers"
dependencies:
"@poap-xyz/utils": 0.2.1
"@poap-xyz/utils": 0.2.2
axios: ^1.3.5
axios-mock-adapter: ^1.21.4
languageName: unknown
linkType: soft

"@poap-xyz/utils@*, @poap-xyz/[email protected].1, @poap-xyz/utils@workspace:packages/utils":
"@poap-xyz/utils@*, @poap-xyz/[email protected].2, @poap-xyz/utils@workspace:packages/utils":
version: 0.0.0-use.local
resolution: "@poap-xyz/utils@workspace:packages/utils"
languageName: unknown
Expand Down

0 comments on commit 132af67

Please sign in to comment.