diff --git a/.gitignore b/.gitignore index 7d67972..16f2e96 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,18 @@ node_modules/ .mesh/ .vscode/ .env -build/ \ No newline at end of file +build/ + + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + + +# System Files +.DS_Store +Thumbs.db +.env.* \ No newline at end of file diff --git a/.meshrc.yml b/.meshrc.yml index 1fffbb9..2449bfc 100644 --- a/.meshrc.yml +++ b/.meshrc.yml @@ -10,7 +10,6 @@ sources: - Query.!transaction - Query.!transactions - Query.!myTransactions - customFetch: ./custom-fetch.ts sdk: diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a255863 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "docwriter.style": "JSDoc" +} diff --git a/jest.config.js b/jest.config.js index 3745fc2..2e1ef9f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,4 +2,7 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', + setupFiles: [ + 'dotenv/config' + ], }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b3d972a..1f7a708 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6972,4 +6972,4 @@ packages: resolution: {tarball: https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/c10b47c350cc97c299c6b4a07a98abb628704c71} name: uWebSockets.js version: 20.34.0 - dev: false + dev: false \ No newline at end of file diff --git a/src/Gateway.ts b/src/Gateway.ts index 49a9d0f..7f00933 100644 --- a/src/Gateway.ts +++ b/src/Gateway.ts @@ -3,11 +3,17 @@ import { Organization } from './organization/organization'; import { Auth } from './auth/auth'; import { PDA } from './pda/pda'; import { DataRequestTemplate } from './dataRequestsTemplate/dataRequestsTemplate'; +import { Proof } from './proof/proof'; +import { Request } from './request/request'; +import { DataModel } from './data-model/data-model'; import { User } from './user/user'; export class Gateway { private sdk: Sdk; + public dataModel: DataModel; + public proof: Proof; public user: User; + public request: Request; public pda: PDA; public dataRequestTemplate: DataRequestTemplate; public organization: Organization; @@ -20,9 +26,12 @@ export class Gateway { token, }); this.pda = new PDA(this.sdk); - this.user = new User(this.sdk); this.dataRequestTemplate = new DataRequestTemplate(this.sdk); this.organization = new Organization(this.sdk); this.auth = new Auth(this.sdk); + this.dataModel = new DataModel(this.sdk); + this.proof = new Proof(this.sdk); + this.request = new Request(this.sdk); + this.user = new User(this.sdk); } } diff --git a/src/data-model/data-model.ts b/src/data-model/data-model.ts new file mode 100644 index 0000000..4d016e0 --- /dev/null +++ b/src/data-model/data-model.ts @@ -0,0 +1,168 @@ +import { + CreateDataModelInput, + Sdk, + dataModels_queryQueryVariables, + FilterDataModelInput, +} from '../../.mesh'; +import { errorHandler } from '../utils/errorHandler'; + +/* The `DataModel` class is a TypeScript class that provides methods for creating and retrieving data +models. */ + +export class DataModel { + private sdk: Sdk; + + constructor(sdk: Sdk) { + this.sdk = sdk; + } + + /** + * The function `createModelInput` is an asynchronous function that takes a `CreateDataModelInput` + * object as input and returns a promise that resolves to a `createDataModel_mutationMutation` object. + * @param {CreateDataModelInput} createModelInput - The `createModelInput` parameter is of type + * `CreateDataModelInput`. It is an input object that contains the data needed to create a new data + * model. + * @returns a Promise that resolves to a value of type `createDataModel_mutationMutation`. + */ + async createDataModel(createModelInput: CreateDataModelInput) { + try { + return await this.sdk.createDataModel_mutation({ + input: createModelInput, + }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getDataModel` retrieves a data model using its ID and returns a promise that resolves + * to the queried data model. + * @param {string} dataModelId - The dataModelId parameter is a string that represents the unique + * identifier of a data model. It is used to query and retrieve a specific data model from the system. + * @returns a Promise that resolves to a dataModel_queryQuery object. + */ + async getDataModel(dataModelId: string) { + try { + return await this.sdk.dataModel_query({ id: dataModelId }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getDataModels` is an asynchronous function that queries data models and returns the + * result. + * @param {dataModels_queryQueryVariables} dataModel - The `dataModel` parameter is an object that + * contains variables for the `dataModels_query` query. It is of type `dataModels_queryQueryVariables`. + * @returns The `getDataModels` function is returning the result of the `dataModels_query` function + * call. + */ + + async getDataModels({ + filter, + order, + skip, + take, + }: dataModels_queryQueryVariables = {}) { + try { + const data = await this.sdk.dataModels_query({ + filter, + order, + skip, + take, + }); + return data; + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getDataModelsCount` is an asynchronous function that retrieves the count of data + * models based on the provided filter variables. + * @param variables - The `variables` parameter is of type `InputMaybe`. It is an + * optional input that can be used to filter the data models. The `FilterDataModelInput` is a type that + * contains various filter options . + * * The above type represents the input data model for filtering data, including consumption price, + * organization identification, and user information. + * @property {InputMaybe | undefined} consumptionPrice - It is an optional property of + * type `InputMaybe`. This means that it can either be `undefined` or an object of type + * `FloatRangeDto`. + * @property {InputMaybe | undefined} organization - The + * "organization" property is an optional input that represents the identification of an organization. + * It can be of type "InputMaybe", which means it can either be a + * valid organization identification input or undefined. + * @property {InputMaybe} user - The "user" property is of type "InputMaybe" which means it can either + * be a value of type "undefined" or a value of another type. The specific type of "user" is not + * provided in the code snippet, so it is unclear what type it should be. + * @returns The `getDataModelsCount` function is returning the result of the `dataModelsCount_query` + * method call, which is a promise. + */ + + async getDataModelsCount(filterVariables?: FilterDataModelInput) { + try { + return await this.sdk.dataModelsCount_query({ + filter: filterVariables, + }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getDataModelMetaData` is an asynchronous function that retrieves metadata for data + * models and throws an error if there is any. + * @returns The `getDataModelMetaData` function is returning the result of the + * `dataModelsMetadata_query` method call. + */ + async getDataModelMetaData() { + try { + return await this.sdk.dataModelsMetadata_query(); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getIssuersByDataModel` retrieves issuers based on a given data model ID using an SDK. + * @param {string} id - A string representing the ID of the data model. + * @returns the result of the `issuersByDataModel_query` method call. + */ + async getIssuersByDataModel(id: string) { + try { + return await this.sdk.issuersByDataModel_query({ id: id }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getIssuersByDataModelCount` retrieves the count of issuers based on a given data model + * ID. + * @param {string} dataModelId - The dataModelId parameter is a string that represents the ID of a data + * model. + * @returns the result of the `issuersByDataModelCount_query` method call. + */ + async getIssuersByDataModelCount(dataModelId: string) { + try { + return await this.sdk.issuersByDataModelCount_query({ id: dataModelId }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getTotalofIssuersByDataModel` retrieves the total number of issuers based on a given + * data model ID. + * @param {string} dataModelId - The dataModelId parameter is a string that represents the identifier + * of a data model. It is used to query the total number of issuers associated with that data model. + * @returns the result of the `getTotalofIssuersByDataModel_query` method call. + */ + async getTotalofIssuersByDataModel(dataModelId: string) { + try { + return await this.sdk.getTotalofIssuersByDataModel_query({ dataModelId }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } +} diff --git a/src/proof/proof.ts b/src/proof/proof.ts new file mode 100644 index 0000000..27cb879 --- /dev/null +++ b/src/proof/proof.ts @@ -0,0 +1,198 @@ +import { + Sdk, + createProof_mutationMutationVariables, + proofsByPDAIds_queryQueryVariables, + proofs_queryQueryVariables, + receivedProofs_queryQueryVariables, + sentProofsCount_queryQueryVariables, + sentProofs_queryQueryVariables, +} from '../../.mesh'; +import { errorHandler } from '../utils/errorHandler'; + +export class Proof { + private sdk: Sdk; + + constructor(sdk: Sdk) { + this.sdk = sdk; + } + + /** + * The function `getProof` is an asynchronous function that takes an `id` parameter and returns the + * result of a query using the `sdk` object, or throws an error if there is any. + * @param {string} id - The `id` parameter is a string that represents the identifier of the proof that + * you want to retrieve. + * @returns The `getProof` function is returning the result of the `proof_query` method call from the + * `sdk` object. + */ + async getProof(id: string) { + try { + return await this.sdk.proof_query({ id: id }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + /** + * The function "createProof" is an asynchronous function that calls the "createProof_mutation" method + * from the "sdk" object, passing in the "variables" parameter, and returns the result. If an error + * occurs, it throws an error. + * @param {createProof_mutationMutationVariables} [variables] - The `variables` parameter is an + * optional object that contains the variables needed for the `createProof_mutation` mutation. These + * variables can include any data that is required for the mutation to execute successfully, such as + * input values or authentication tokens. + * @returns The `createProof` function is returning the result of the `createProof_mutation` function + * call. + */ + + async createProof(inputVariables?: createProof_mutationMutationVariables) { + try { + return await this.sdk.createProof_mutation(inputVariables); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `createProofMessage` is an asynchronous function that takes a `requestId` as a + * parameter and uses it to call the `createProofMessage_mutation` method from the `sdk`. + * @param {string} requestId - The `requestId` parameter is a string that represents the unique + * identifier of a request. It is used as input to the `createProofMessage_mutation` function to + * create a proof message. + * @returns the result of the `createProofMessage_mutation` method call. + */ + async createProofMessage(requestId: string) { + try { + return await this.sdk.createProofMessage_mutation({ + requestId: requestId, + }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getProofs` is an asynchronous function that queries proofs and returns the result. + * @param {proofs_queryQueryVariables} [variables] - The `variables` parameter is an optional object + * that contains the variables needed for the `proofs_query` function. These variables can be used to + * filter or customize the query results. + * @returns the result of the `proofs_query` method call. + */ + async getProofs({ + filter, + order, + skip, + take, + }: proofs_queryQueryVariables = {}) { + try { + return await this.sdk.proofs_query({ + filter, + order, + skip, + take, + }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getProofsByPDAIds` retrieves proofs by PDA IDs using a GraphQL query. + * @param {proofsByPDAIds_queryQueryVariables} variables - The `variables` parameter is an object that + * contains the necessary variables for the `proofsByPDAIds_query` query. These variables are used to + * specify the criteria for retrieving proofs by PDA IDs. The specific properties and their types + * depend on the GraphQL schema and the requirements of the `proof + * @returns the result of the `proofsByPDAIds_query` method call. + */ + async getProofsByPDAIds({ + pdaIds, + skip, + take, + }: proofsByPDAIds_queryQueryVariables) { + try { + return await this.sdk.proofsByPDAIds_query({ pdaIds, skip, take }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getReceivedProofs` is an asynchronous function that retrieves received proofs using + * the `receivedProofs_query` method from an SDK, and it handles any errors that occur during the + * process. + * @param {receivedProofs_queryQueryVariables} [variables] - The `variables` parameter is an optional + * object that contains any variables needed for the `receivedProofs_query` function. These variables + * can be used to filter or customize the query results. + * @returns the result of the `receivedProofs_query` method call. + */ + async getReceivedProofs({ + order, + organizationId, + skip, + take, + }: receivedProofs_queryQueryVariables = {}) { + try { + return await this.sdk.receivedProofs_query({ + order, + organizationId, + skip, + take, + }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getReceivedProofsCount` is an asynchronous function that retrieves the count of + * received proofs for a given organization ID using a query from an SDK. + * @param {string} [organizationId] - The organizationId parameter is an optional string that + * represents the ID of an organization. It is used to filter the received proofs count based on the + * organization. If no organizationId is provided, the function will return the received proofs count + * for all organizations. + * @returns the result of the `receivedProofsCount_query` method call. + */ + async getReceivedProofsCount(organizationId?: string) { + try { + return await this.sdk.receivedProofsCount_query({ organizationId }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + /** + * The function `getSentProofs` is an asynchronous function that retrieves sent proofs using the + * `sentProofs_query` method from an SDK, and it handles any errors that occur. + * @param {sentProofs_queryQueryVariables} [variables] - The `variables` parameter is an optional + * object that contains any variables you want to pass to the `sentProofs_query` function. These + * variables can be used to filter or customize the query results. + * @returns the result of the `sentProofs_query` method call. + */ + + async getSentProofs({ + order, + skip, + take, + }: sentProofs_queryQueryVariables = {}) { + try { + return await this.sdk.sentProofs_query({ order, skip, take }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getSentProofsCount` is an asynchronous function that retrieves the count of sent + * proofs. + * @param {sentProofsCount_queryQueryVariables} [variables] - The `variables` parameter is an optional + * object that contains any variables needed for the `sentProofsCount_query` query. These variables + * can be used to filter or customize the query results. + * @returns the result of the `sentProofsCount_query` function call. + */ + async getSentProofsCount( + queryVariables?: sentProofsCount_queryQueryVariables, + ) { + try { + return await this.sdk.sentProofsCount_query(queryVariables); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } +} diff --git a/src/request/request.ts b/src/request/request.ts new file mode 100644 index 0000000..796e834 --- /dev/null +++ b/src/request/request.ts @@ -0,0 +1,183 @@ +import { + DataRequestSchemaInput, + FilterDataRequestInput, + Sdk, + requestsReceived_queryQueryVariables, + requestsSent_queryQueryVariables, +} from '../../.mesh'; +import { errorHandler } from '../utils/errorHandler'; + +export class Request { + private sdk: Sdk; + + constructor(sdk: Sdk) { + this.sdk = sdk; + } + + /** + * The function `createDataRequest` is an asynchronous function that takes an input of type + * `DataRequestSchemaInput` and calls the `createDataRequest_mutation` method of the `sdk` object, + * returning the result. + * @param {DataRequestSchemaInput} input - The `input` parameter is an object of type + * `DataRequestSchemaInput`. It is used to provide the necessary data for creating a data request. The + * specific properties and their types within the `DataRequestSchemaInput` object would depend on the + * requirements of the `createDataRequest_mutation` function + * @returns the result of the `this.sdk.createDataRequest_mutation({ input })` method call. + */ + async createDataRequest(inputSchema: DataRequestSchemaInput) { + try { + return this.sdk.createDataRequest_mutation({ input: inputSchema }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getDataRequest` is an asynchronous function that retrieves data using a request ID and + * throws an error if there is any. + * @param {string} requestId - The `requestId` parameter is a string that represents the unique + * identifier of a data request. It is used to query the data request using the `dataRequest_query` + * method of the `sdk` object. + * @returns The `getDataRequest` function is returning the result of the `dataRequest_query` method + * call. + */ + async getDataRequest(requestId: string) { + try { + return await this.sdk.dataRequest_query({ requestId }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getDataRequestCount` is an asynchronous function that makes a data request count + * query using the `dataRequestCount_query` method from the `sdk` object, and returns the result. + * @param {dataRequestCount_queryQueryVariables} [variables] - The `variables` parameter is an + * optional object that contains any variables needed for the `dataRequestCount_query` query. These + * variables can be used to filter or customize the data request count query. + * @returns the result of the `dataRequestCount_query` method call. + */ + async getDataRequestCount(filterVariables?: FilterDataRequestInput) { + try { + return await this.sdk.dataRequestCount_query({ filter: filterVariables }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getDataRequestStatus` is an asynchronous function that queries the status of a data + * request using a provided request ID. + * @param {string} requestId - The `requestId` parameter is a string that represents the unique + * identifier of a data request. + * @returns the result of the `dataRequestStatus_query` method call, which is a Promise. + */ + async getDataRequestStatus(requestId: string) { + try { + return await this.sdk.dataRequestStatus_query({ requestId }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getDataRequests` is an asynchronous function that makes a query to retrieve data + * requests, and it handles any errors that occur during the query. + * @param {dataRequests_queryQueryVariables} [variables] - The `variables` parameter is an optional + * object that contains any variables needed for the `dataRequests_query` function. These variables can + * be used to filter or customize the data requests that are being queried. + * @returns The `getDataRequests` function is returning the result of the `dataRequests_query` function + * call. + */ + async getDataRequests(filterVariables?: FilterDataRequestInput) { + try { + return await this.sdk.dataRequests_query({ filter: filterVariables }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getRequestsReceived` is an asynchronous function that retrieves requests received + * using the `requestsReceived_query` method from the `sdk` object. + * @param {requestsReceived_queryQueryVariables} [variables] - The `variables` parameter is an + * optional object that contains variables to be passed to the `requestsReceived_query` function. + * These variables can be used to filter or customize the query results. + * @returns the result of the `requestsReceived_query` method call. + */ + async getRequestsReceived({ + filter, + order, + skip, + take, + }: requestsReceived_queryQueryVariables = {}) { + try { + return await this.sdk.requestsReceived_query({ + filter, + order, + skip, + take, + }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getRequestsReceivedCount` is an asynchronous function that retrieves the count of + * requests received, and it handles any errors that occur during the process. + * @param {requestsReceivedCount_queryQueryVariables} [variables] - The "variables" parameter is an + * optional parameter that allows you to pass any variables needed for the + * "requestsReceivedCount_query" query. It is of type "requestsReceivedCount_queryQueryVariables". + * @returns the result of the `requestsReceivedCount_query` method call. + */ + async getRequestsReceivedCount(filterVariables?: FilterDataRequestInput) { + try { + return await this.sdk.requestsReceivedCount_query({ + filter: filterVariables, + }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getRequestsSent` is an asynchronous function that retrieves requests sent using the + * `requestsSent_query` method from the `sdk` object. + * @param {requestsSent_queryQueryVariables} [variables] - The `variables` parameter is an optional + * object that contains any variables you want to pass to the `requestsSent_query` function. These + * variables can be used to customize the query and retrieve specific data. If you don't need to pass + * any variables, you can omit this parameter. + * @returns the result of the `requestsSent_query` method call. + */ + async getRequestsSent({ + filter, + order, + skip, + take, + }: requestsSent_queryQueryVariables = {}) { + try { + return await this.sdk.requestsSent_query({ filter, order, skip, take }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getRequestsSentCount` is an asynchronous function that retrieves the count of + * requests sent, and it handles any errors that occur during the process. + * @param {requestsSentCount_queryQueryVariables} [variables] - The "variables" parameter is an + * optional object that contains any variables needed for the "requestsSentCount_query" query. These + * variables can be used to filter or customize the query results. + * @returns the result of the `requestsSentCount_query` method call. + */ + async getRequestsSentCount(filterVariables?: FilterDataRequestInput) { + try { + return await this.sdk.requestsSentCount_query({ + filter: filterVariables, + }); + } catch (error: any) { + throw new Error(errorHandler(error)); + } + } +} diff --git a/test/data-model.test.ts b/test/data-model.test.ts new file mode 100644 index 0000000..1888108 --- /dev/null +++ b/test/data-model.test.ts @@ -0,0 +1,98 @@ +import { Gateway } from '../src/Gateway'; +let api: Gateway; + +beforeAll(() => { + const apiKey = process.env.API_KEY; + const token = process.env.BEARER_TOKEN; + + if (!apiKey || !token) { + throw new Error( + 'APIKEY or TOKEN is not defined in the environment variables.', + ); + } + + api = new Gateway({ + apiKey: apiKey, + token: token, + }); +}); + +describe('data model function tests', () => { + it('create data model', async () => { + const { createDataModel } = await api.dataModel.createDataModel({ + schema: { + type: 'object', + properties: { + name: { type: 'string', title: 'User name' }, + age: { type: 'number', minimum: 18, title: 'User Age' }, + }, + required: ['name', 'age'], + additionalProperties: false, + }, + description: 'Test description', + permissions: 'ALL', + title: 'Test', + }); + + expect(createDataModel?.title).toEqual('Test'); + }, 40000); + + it('get the data model', async () => { + const { createDataModel } = await api.dataModel.createDataModel({ + schema: { + type: 'object', + properties: { + name: { type: 'string', title: 'User name' }, + age: { type: 'number', minimum: 18, title: 'User Age' }, + }, + required: ['name', 'age'], + additionalProperties: false, + }, + description: 'test for get data model query', + permissions: 'ALL', + title: '1212', + }); + + const { dataModel } = await api.dataModel.getDataModel(createDataModel?.id); + + expect(dataModel.id).toEqual(createDataModel.id); + }); + + it('gets data moldel', async () => { + const { dataModels } = await api.dataModel.getDataModels(); + + expect(dataModels.length).toBeGreaterThanOrEqual(0); + }, 5000); + + it('models count', async () => { + const { dataModelsCount } = await api.dataModel.getDataModelsCount(); + expect(dataModelsCount).toBeGreaterThanOrEqual(0); + }, 2000); + + it('data model meta data', async () => { + const { dataModelsMetadata } = await api.dataModel.getDataModelMetaData(); + expect(dataModelsMetadata.tags.length).toBeGreaterThanOrEqual(0); + }); + + it('find issuer by data model id', async () => { + const { issuersByDataModel } = await api.dataModel.getIssuersByDataModel( + process.env.DATAMODEL_ID as string, + ); + + }); + + it('get total issuers by data model', async () => { + const { getTotalofIssuersByDataModel } = + await api.dataModel.getTotalofIssuersByDataModel( + process.env.DATAMODEL_ID as string, + ); + + }); + + it('get issuers by data model count', async () => { + const { issuersByDataModelCount } = + await api.dataModel.getIssuersByDataModelCount( + process.env.DATAMODEL_ID as string, + ); + }); +}); diff --git a/test/proof.test.ts b/test/proof.test.ts new file mode 100644 index 0000000..c89408e --- /dev/null +++ b/test/proof.test.ts @@ -0,0 +1,63 @@ +import { Gateway } from '../src/Gateway'; +let api: Gateway; + +beforeAll(() => { + const apiKey = process.env.API_KEY; + const token = process.env.BEARER_TOKEN; + + if (!apiKey || !token) { + throw new Error( + 'APIKEY or TOKEN is not defined in the environment variables.', + ); + } + + api = new Gateway({ + apiKey: apiKey, + token: token, + }); +}); + +describe('proofs related test', () => { + it('create proof', async () => { + const {} = await api.proof.createProof({}); + }); + + it('get proof using data model id', async () => { + const { proof } = await api.proof.getProof(process.env.PROOF_ID as string); + expect(proof.id).toEqual(process.env.PROOF_ID); + }, 8000); + + it('get proofs', async () => { + const { proofs } = await api.proof.getProofs(); + expect(proofs.length).toBeGreaterThanOrEqual(0); + }); + + it('get proofs by pda id', async () => { + const { proofsByPDAIds } = await api.proof.getProofsByPDAIds({ + pdaIds: [process.env.PDA_ID as string], + }); + + expect(proofsByPDAIds.length).toBeGreaterThanOrEqual(0); + }); + + it('get received proofs for user', async () => { + const { receivedProofs } = await api.proof.getReceivedProofs(); + + expect(receivedProofs.length).toBeGreaterThanOrEqual(0); + }); + + it('get received proof count', async () => { + const { receivedProofsCount } = await api.proof.getReceivedProofsCount(); + expect(receivedProofsCount).toBeGreaterThanOrEqual(0); + }); + + it('get sent proofs', async () => { + const { sentProofs } = await api.proof.getSentProofs(); + expect(sentProofs.length).toBeGreaterThanOrEqual(0); + }); + + it('get sent proofs count', async () => { + const { sentProofsCount } = await api.proof.getSentProofsCount(); + expect(sentProofsCount).toBeGreaterThanOrEqual(0); + }); +}); diff --git a/test/request.test.ts b/test/request.test.ts new file mode 100644 index 0000000..1f79e8e --- /dev/null +++ b/test/request.test.ts @@ -0,0 +1,86 @@ +import { Gateway } from '../src/Gateway'; +let api: Gateway; + +beforeAll(() => { + const apiKey = process.env.API_KEY; + const token = process.env.BEARER_TOKEN; + + if (!apiKey || !token) { + throw new Error( + 'APIKEY or TOKEN is not defined in the environment variables.', + ); + } + + api = new Gateway({ + apiKey: apiKey, + token: token, + }); +}); + +describe('unit test related to the request queries', () => { + it('create data request', async () => { + const { createDataRequest } = await api.request.createDataRequest({ + dataRequestTemplateId: process.env.DATAREQUEST_TEMPLATE_ID as string, + owner: { + type: 'GATEWAY_ID', + value: 'sid', + }, + dataUse: 'Because I can', + }); + + expect(createDataRequest.dataUse).toEqual('Because I can'); + }, 8000); + + it('get request using id', async () => { + const { dataRequest } = await api.request.getDataRequest( + process.env.DATAREQUEST_ID as string, + ); + + expect(dataRequest.id).toEqual(process.env.DATAREQUEST_ID); + }); + + it('get request count', async () => { + const { dataRequestCount } = await api.request.getDataRequestCount(); + + expect(dataRequestCount).toBeGreaterThanOrEqual(0); + }); + + it('get data request status', async () => { + const { dataRequestStatus } = await api.request.getDataRequestStatus( + process.env.DATAREQUEST_ID as string, + ); + expect(dataRequestStatus).toEqual('EXPIRED'); + }); + + it('get data requests', async () => { + const { dataRequests } = await api.request.getDataRequests({ + dataTemplateIds: [process.env.DATAREQUEST_TEMPLATE_ID as string], + }); + + expect(dataRequests.length).toBeGreaterThanOrEqual(0); + }, 8000); + + it('get requests received', async () => { + const { requestsReceived } = await api.request.getRequestsReceived(); + + expect(requestsReceived.length).toBeGreaterThanOrEqual(0); + }, 8000); + + it('get requests received count', async () => { + const { requestsReceivedCount } = + await api.request.getRequestsReceivedCount(); + + expect(requestsReceivedCount).toBeGreaterThanOrEqual(0); + }); + + it('get requests sent', async () => { + const { requestsSent } = await api.request.getRequestsSent(); + expect(requestsSent.length).toBeGreaterThanOrEqual(0); + }, 8000); + + it('get requests sent count', async () => { + const { requestsSentCount } = await api.request.getRequestsSentCount(); + + expect(requestsSentCount).toBeGreaterThanOrEqual(0); + }); +});