From 0aba14f5986a43d4011ad86ea76415412218639c Mon Sep 17 00:00:00 2001 From: Siddharth9890 Date: Thu, 7 Mar 2024 17:10:25 +0530 Subject: [PATCH] feat: proofs,data models, requests testing done --- src/data-model/data-model.ts | 2 +- src/organization/organization.ts | 2 +- src/testMutationsAndQuery.ts | 245 ++++++++++++++++++++++++------- src/utils/constants.ts | 2 +- src/utils/errorHandler.ts | 26 ++-- 5 files changed, 211 insertions(+), 66 deletions(-) diff --git a/src/data-model/data-model.ts b/src/data-model/data-model.ts index 4b13b1a..2079582 100644 --- a/src/data-model/data-model.ts +++ b/src/data-model/data-model.ts @@ -28,7 +28,7 @@ export class DataModel { return this.sdk.createDataModel_mutation({ input: createModelInput, }); - } catch (error: any) { + } catch (error) { throw new Error(errorHandler(error)); } } diff --git a/src/organization/organization.ts b/src/organization/organization.ts index b351932..c1161df 100644 --- a/src/organization/organization.ts +++ b/src/organization/organization.ts @@ -51,7 +51,7 @@ export class Organization { return await this.sdk.addMemberToOrganization_mutation({ input: memberInput, }); - } catch (error: any) { + } catch (error) { throw new Error(errorHandler(error)); } } diff --git a/src/testMutationsAndQuery.ts b/src/testMutationsAndQuery.ts index f8383c1..da4407c 100644 --- a/src/testMutationsAndQuery.ts +++ b/src/testMutationsAndQuery.ts @@ -19,6 +19,10 @@ function generateRandomString() { return result; } +// error handler +// transactions +// some minor backend errors in getRequestsReceived + const testMutationsAndQueries = async () => { const gatewayInstance = new Gateway({ apiKey: 'm9Y5ntNcTlwQ2LbRpYr6K_VhxJXuZJ6Q', @@ -28,12 +32,12 @@ const testMutationsAndQueries = async () => { }); try { // ORGANIZATIONS - const { createOrganization } = - await gatewayInstance.organization.createOrganization({ - name: 'Create sample organization', - description: 'Sample organization description', - username: generateRandomString(), - }); + // const { createOrganization } = + // await gatewayInstance.organization.createOrganization({ + // name: 'Create sample organization', + // description: 'Sample organization description', + // username: generateRandomString(), + // }); // THESE ARE WORKING FINE JUST COMMENTED THEM TO PREVENT ERROR AS THERE IS ONLY 1 USER IN ORG // const { addMemberToOrganization } = @@ -58,67 +62,208 @@ const testMutationsAndQueries = async () => { // user: { type: 'GATEWAY_ID', value: USER_GATEWAY_ID }, // }); - const { updateOrganization } = - await gatewayInstance.organization.updateOrganization({ - id: createOrganization.id, - description: 'updated description', + // const { updateOrganization } = + // await gatewayInstance.organization.updateOrganization({ + // id: createOrganization.id, + // description: 'updated description', + // }); + + // const { organization } = await gatewayInstance.organization.getOrganization( + // OrganizationIdentifierType.ORG_ID, + // createOrganization.id, + // ); + + // const { organizations } = + // await gatewayInstance.organization.getOrganizations({ + // filter: { verified: true }, + // }); + + console.log('\n ORGS DONE \n'); + + // PDA + // let obj = { + // dataModelId: '74719072-0268-4c06-84d5-73ba8a4e51fb', + // description: 'Description of the PDA', + // title: 'Favorite Person on Crypto Twitter', + // claim: { + // name: '@gateway_xyz', + // age: 20, + // }, + // owner: { + // type: UserIdentifierType.GATEWAY_ID, + // value: USER_GATEWAY_ID, + // }, + // }; + // const { createPDA } = await gatewayInstance.pda.createPDA(obj); + + // const { updatePDA } = await gatewayInstance.pda.updatePDA({ + // id: createPDA.id, + // title: 'Changed PDA title', + // }); + + // const { PDA } = await gatewayInstance.pda.getPDA(createPDA.id); + + await gatewayInstance.pda.getPDAs(); + + // const { issuedPDAs } = await gatewayInstance.pda.getIssuedPDAs({ + // skip: 0, + // take: 20, + // filter: { dataModelIds: ['74719072-0268-4c06-84d5-73ba8a4e51fb'] }, + // }); + + // await gatewayInstance.pda.getIssuedPDAsCount(); + + // await gatewayInstance.pda.getPDACount(); + + console.log('\n PDAS DONE \n'); + // Transactions + + // const { transactions } = + // await gatewayInstance.transaction.getTransactions(); + // console.log(transactions[0], transactions.length); + // await gatewayInstance.transaction.getTransaction('<-- transaction id -->'); + + // await gatewayInstance.transaction.getTransactionCount(); + + console.log('\n TRANSACTIONS DONE \n'); + + // Data Models + + const { createDataModel } = await gatewayInstance.dataModel.createDataModel( + { + description: 'testing', + permissions: 'ALL', + title: 'testing', + schema: { + type: 'object', + default: {}, + title: 'Root Schema', + required: ['name', 'age'], + properties: { + name: { + type: 'string', + title: 'name', + }, + age: { + type: 'integer', + title: 'age', + examples: ['Tell us what your experience was like'], + }, + }, + }, + }, + ); + + await gatewayInstance.dataModel.getDataModel( + '74719072-0268-4c06-84d5-73ba8a4e51fb', + ); + + await gatewayInstance.dataModel.getDataModels(); + + await gatewayInstance.dataModel.getDataModelsCount(); + + await gatewayInstance.dataModel.getDataModelsMetaData(); + + await gatewayInstance.dataModel.getIssuersByDataModel( + '74719072-0268-4c06-84d5-73ba8a4e51fb', + ); + + await gatewayInstance.dataModel.getTotalofIssuersByDataModel( + '74719072-0268-4c06-84d5-73ba8a4e51fb', + ); + + await gatewayInstance.dataModel.getIssuersByDataModelCount( + '74719072-0268-4c06-84d5-73ba8a4e51fb', + ); + + console.log('\n DATA MODELS DONE \n'); + // Data Requests template + const { createDataRequestTemplate } = + await gatewayInstance.dataRequestTemplate.createDataRequestTemplate({ + title: 'Create Data Request Template Example', + description: 'Lorem ipsum dolor sit amet.', + dataModels: [ + { + id: '74719072-0268-4c06-84d5-73ba8a4e51fb', + required: true, + claimValidations: { + type: 'object', + properties: { + name: { + type: 'string', + }, + age: { + type: 'number', + }, + }, + required: ['name', 'age'], + }, + }, + ], }); - const { organization } = await gatewayInstance.organization.getOrganization( - OrganizationIdentifierType.ORG_ID, - createOrganization.id, + await gatewayInstance.dataRequestTemplate.getDataRequestTemplate( + createDataRequestTemplate.id, + ); + + await gatewayInstance.dataRequestTemplate.getDataRequestTemplates({ + filter: { user: { type: 'GATEWAY_ID', value: USER_GATEWAY_ID } }, + }); + + await gatewayInstance.dataRequestTemplate.getDataRequestsTemplateCount(); + + await gatewayInstance.dataRequestTemplate.getDataRequestsTemplatesMetadata(); + + await gatewayInstance.dataRequestTemplate.getVerifiersByDataRequestTemplate( + createDataRequestTemplate.id, ); - const { organizations } = - await gatewayInstance.organization.getOrganizations({ - // filter: { verified: true }, + await gatewayInstance.dataRequestTemplate.getVerifiersByDataRequestTemplateCount( + createDataRequestTemplate.id, + ); + console.log('\n DATA REQUESTS TEMPLATE DONE \n'); + + // Data requests + const { createDataRequest } = + await gatewayInstance.request.createDataRequest({ + dataRequestTemplateId: createDataRequestTemplate.id, + dataUse: + 'Web3 is an idea for a new iteration of the World Wide Web which incorporates concepts such as decentralization, blockchain technologies, and token-based economics.', + owner: { type: 'GATEWAY_ID', value: USER_GATEWAY_ID }, }); - console.log(organizations[0].description, organizations.length); - console.log('\n \n'); + await gatewayInstance.request.getDataRequest(createDataRequest.id); - // PDA - let obj = { - dataModelId: '74719072-0268-4c06-84d5-73ba8a4e51fb', - description: 'Description of the PDA', - title: 'Favorite Person on Crypto Twitter', - claim: { - name: '@gateway_xyz', - age: 20, - }, - owner: { - type: UserIdentifierType.GATEWAY_ID, - value: USER_GATEWAY_ID, - }, - }; - const { createPDA } = await gatewayInstance.pda.createPDA(obj); + await gatewayInstance.request.getDataRequestCount(); + + await gatewayInstance.request.getDataRequestStatus(createDataRequest.id); - const { updatePDA } = await gatewayInstance.pda.updatePDA({ - id: createPDA.id, - title: 'Changed PDA title', + await gatewayInstance.request.getDataRequests({ + dataTemplateIds: [createDataRequest.id], }); - const { PDA } = await gatewayInstance.pda.getPDA(createPDA.id); + // await gatewayInstance.request.getRequestsReceived(); + + await gatewayInstance.request.getRequestsSent(); - const { issuedPDAs } = await gatewayInstance.pda.getIssuedPDAs({ - skip: 0, - take: 20, - filter: { dataModelIds: ['74719072-0268-4c06-84d5-73ba8a4e51fb'] }, + console.log('\n DATA REQUESTS DONE \n'); + // Proofs + + // await gatewayInstance.proof.getProofs(); + + await gatewayInstance.proof.getProofsByPDAIds({ + pdaIds: ['c75a800b-5649-461b-86ab-a4864c6578ee'], }); - await gatewayInstance.pda.getIssuedPDAsCount(); + await gatewayInstance.proof.getReceivedProofs(); - await gatewayInstance.pda.getPDACount(); + await gatewayInstance.proof.getReceivedProofsCount(); - console.log('\n \n'); - // Transactions + await gatewayInstance.proof.getSentProofs(); - const { transactions } = - await gatewayInstance.transaction.getTransactions(); - console.log(transactions[0], transactions.length); - await gatewayInstance.transaction.getTransaction('<-- transaction id -->'); + await gatewayInstance.proof.getSentProofsCount(); - await gatewayInstance.transaction.getTransactionCount(); + console.log('\n PROOFS DONE \n'); } catch (error) { console.log(error); } diff --git a/src/utils/constants.ts b/src/utils/constants.ts index a32446f..4894933 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,3 +1,3 @@ -export const STRING_VALIDATION_LENGTH = 3; +export const STRING_VALIDATION_LENGTH = 2; export const TEST_DEFAULT_TIMEOUT = 10000; export const DEFAULT_TAKE_LIMIT = 15; diff --git a/src/utils/errorHandler.ts b/src/utils/errorHandler.ts index 0b25f10..1cea2aa 100644 --- a/src/utils/errorHandler.ts +++ b/src/utils/errorHandler.ts @@ -1,15 +1,15 @@ export const errorHandler = (error: any): string => { - return error.response.errors[0].message; - // if (typeof error === 'object' && error !== null) { - // if ( - // Array.isArray(error.errors) && - // error.errors.length > 0 && - // 'message' in error.errors[0] - // ) { - // return error.errors[0].message; - // } else if ('message' in error) { - // return error.message; - // } - // } - // return 'Something went wrong!'; + // return error.response.errors[0].message; + if (typeof error === 'object' && error !== null) { + if ( + Array.isArray(error.errors) && + error.errors.length > 0 && + 'message' in error.errors[0] + ) { + return error.errors[0].message; + } else if ('message' in error) { + return error.message; + } + } + return 'Something went wrong!'; };