Skip to content

Commit

Permalink
feat: support search base on nftType
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizgar91 committed Oct 4, 2023
1 parent 222bec9 commit c4d50f8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
49 changes: 41 additions & 8 deletions integration/external/Datasets.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { assert } from 'chai'
import { decodeJwt, JWTPayload } from 'jose'
import { Account, DDO, MetaData, Nevermined, AssetPrice, NFTAttributes } from '../../src'
import {
Account,
DDO,
MetaData,
Nevermined,
AssetPrice,
NFTAttributes,
NeverminedNFT721Type,
} from '../../src'
import { EscrowPaymentCondition, TransferNFT721Condition, Token } from '../../src/keeper'
import { config } from '../config'
import { generateMetadata, getMetadata } from '../utils'
Expand Down Expand Up @@ -322,28 +330,41 @@ describe('Gate-keeping of Dataset using NFT ERC-721 End-to-End', () => {

describe('As a user I want to be able to search DDOs by subscriptions', () => {
it('should be able to retrieve the subscriptionDDO by contractAddress', async () => {
const result = await nevermined.search.bySubscriptionContractAddress(subscriptionNFT.address)
const result = await nevermined.search.bySubscriptionContractAddress(
subscriptionNFT.address,
NeverminedNFT721Type.nft721Subscription,
)
assert.equal(result.totalResults.value, 1)
})

it('should be able to retrieve subscriptions created', async () => {
const result = await nevermined.search.subscriptionsCreated(publisher)
const result = await nevermined.search.subscriptionsCreated(
publisher,
NeverminedNFT721Type.nft721Subscription,
)
assert.isAbove(result.totalResults.value, 1)

const dids = result.results.map((ddo) => ddo.id)
assert.include(dids, subscriptionDDO.id)
})

it('should be able to retrieve subscriptions purchased', async () => {
const result = await nevermined.search.subscriptionsPurchased(subscriber)
const result = await nevermined.search.subscriptionsPurchased(
subscriber,
NeverminedNFT721Type.nft721Subscription,
)
assert.isAbove(result.totalResults.value, 1)

const dids = result.results.map((ddo) => ddo.id)
assert.include(dids, subscriptionDDO.id)
})

it('should be able to retrieve subscriptions published filtering by tags', async () => {
const result = await nevermined.search.subscriptionsCreated(publisher, tagsFilter)
const result = await nevermined.search.subscriptionsCreated(
publisher,
NeverminedNFT721Type.nft721Subscription,
tagsFilter,
)

assert.isAbove(result.totalResults.value, 1)

Expand All @@ -357,13 +378,21 @@ describe('Gate-keeping of Dataset using NFT ERC-721 End-to-End', () => {
})

it('should not be able to retrieve any subscriptions published filtering by tags which not exist', async () => {
const result = await nevermined.search.subscriptionsCreated(publisher, tagsFilter2)
const result = await nevermined.search.subscriptionsCreated(
publisher,
NeverminedNFT721Type.nft721Subscription,
tagsFilter2,
)

assert.equal(result.totalResults.value, 0)
})

it('should be able to retrieve subscriptions purchased filtering by tags', async () => {
const result = await nevermined.search.subscriptionsPurchased(subscriber, tagsFilter)
const result = await nevermined.search.subscriptionsPurchased(
subscriber,
NeverminedNFT721Type.nft721Subscription,
tagsFilter,
)
assert.isAbove(result.totalResults.value, 1)

assert.isTrue(
Expand All @@ -376,7 +405,11 @@ describe('Gate-keeping of Dataset using NFT ERC-721 End-to-End', () => {
})

it('should not be able to retrieve not subscriptions purchased filtering by tags which do not exist', async () => {
const result = await nevermined.search.subscriptionsPurchased(subscriber, tagsFilter2)
const result = await nevermined.search.subscriptionsPurchased(
subscriber,
NeverminedNFT721Type.nft721Subscription,
tagsFilter2,
)
assert.equal(result.totalResults.value, 0)
})

Expand Down
16 changes: 13 additions & 3 deletions integration/external/Services.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
AssetPrice,
NFTAttributes,
ResourceAuthentication,
NeverminedNFT721Type,
} from '../../src'
import { EscrowPaymentCondition, TransferNFT721Condition, Token } from '../../src/keeper'
import { config } from '../config'
Expand Down Expand Up @@ -456,20 +457,29 @@ describe('Gate-keeping of Web Services using NFT ERC-721 End-to-End', () => {

describe('As a user I want to be able to search DDOs by subscriptions', () => {
it('should be able to retrieve the subscriptionDDO by contractAddress', async () => {
const result = await nevermined.search.bySubscriptionContractAddress(subscriptionNFT.address)
const result = await nevermined.search.bySubscriptionContractAddress(
subscriptionNFT.address,
NeverminedNFT721Type.nft721Subscription,
)
assert.equal(result.totalResults.value, 1)
})

it('should be able to retrieve subscriptions created', async () => {
const result = await nevermined.search.subscriptionsCreated(publisher)
const result = await nevermined.search.subscriptionsCreated(
publisher,
NeverminedNFT721Type.nft721Subscription,
)
assert.isAbove(result.totalResults.value, 1)

const dids = result.results.map((ddo) => ddo.id)
assert.include(dids, subscriptionDDO.id)
})

it('should be able to retrieve subscriptions purchased', async () => {
const result = await nevermined.search.subscriptionsPurchased(subscriber)
const result = await nevermined.search.subscriptionsPurchased(
subscriber,
NeverminedNFT721Type.nft721Subscription,
)
assert.isAbove(result.totalResults.value, 1)

const dids = result.results.map((ddo) => ddo.id)
Expand Down
22 changes: 19 additions & 3 deletions src/nevermined/api/SearchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ export class SearchApi extends Instantiable {
* @param customNestedQueries - Custom nested queries to add to the search
* @param page
* @param sort - The sort order
* @param nftType - The nftType
* @param appId - The appId used to filter the results
*
* @returns {@link Promise<QueryResult>}
*/
public async bySubscriptionContractAddress(
contractAddress: string,
nftType: string,
customNestedQueries?: SearchQuery['query'][],
offset = 100,
page = 1,
Expand All @@ -178,7 +180,7 @@ export class SearchApi extends Instantiable {
{ match: { 'service.type': 'metadata' } },
{
match: {
'service.attributes.main.nftType': NeverminedNFT721Type.nft721Subscription,
'service.attributes.main.nftType': nftType,
},
},
],
Expand Down Expand Up @@ -234,12 +236,14 @@ export class SearchApi extends Instantiable {
* @param offset - The number of results to return
* @param page
* @param sort - The sort order
* @param nftType - The nftType
* @param appId - The appId used to filter the results
*
* @returns {@link Promise<QueryResult>}
*/
public async subscriptionsCreated(
account: Account,
nftType: string,
customNestedQueries?: SearchQuery['query'][],
offset = 100,
page = 1,
Expand All @@ -256,7 +260,12 @@ export class SearchApi extends Instantiable {
{ match: { 'service.type': 'metadata' } },
{
match: {
'service.attributes.main.nftType': NeverminedNFT721Type.nft721Subscription,
'service.attributes.main.nftType': nftType,
},
},
{
match: {
'service.attributes.main.type': 'subscription',
},
},
],
Expand Down Expand Up @@ -299,12 +308,14 @@ export class SearchApi extends Instantiable {
* @param offset - The number of results to return
* @param page
* @param sort - The sort order
* @param nftType - The nftType
* @param appId - The appId used to filter the results
*
* @returns {@link Promise<QueryResult>}
*/
public async subscriptionsPurchased(
account: Account,
nftType: string,
customNestedQueries?: SearchQuery['query'][],
offset = 100,
page = 1,
Expand Down Expand Up @@ -343,7 +354,12 @@ export class SearchApi extends Instantiable {
{ match: { 'service.type': 'metadata' } },
{
match: {
'service.attributes.main.nftType': NeverminedNFT721Type.nft721Subscription,
'service.attributes.main.nftType': nftType,
},
},
{
match: {
'service.attributes.main.type': 'subscription',
},
},
],
Expand Down

0 comments on commit c4d50f8

Please sign in to comment.