Skip to content

Commit

Permalink
Merge pull request #14 from Gateway-DAO/test/proof
Browse files Browse the repository at this point in the history
  • Loading branch information
R11manish authored Jan 5, 2024
2 parents 4bf39b9 + 01f4ff5 commit cc6dc10
Show file tree
Hide file tree
Showing 15 changed files with 1,234 additions and 7 deletions.
55 changes: 55 additions & 0 deletions __mocks__/dataModel.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { DataModel } from '../src/data-model/data-model';
import {
dataModelStub,
dataModelMetaDataStub,
dataModelCreateStub,
} from '../test/stubs/dataModel.stub';

export const DataModelMockService = (dataModel: DataModel) => ({
createDataModelMock: jest
.spyOn(dataModel.sdk, 'createDataModel_mutation')
.mockResolvedValue({
createDataModel: dataModelStub(),
}),

getDataModelMock: jest
.spyOn(dataModel.sdk, 'dataModel_query')
.mockResolvedValue({
dataModel: dataModelStub(),
}),

getDataModelsMock: jest
.spyOn(dataModel.sdk, 'dataModels_query')
.mockResolvedValue({
dataModels: [dataModelStub()],
}),

getDataModelsCountMock: jest
.spyOn(dataModel.sdk, 'dataModelsCount_query')
.mockResolvedValue({
dataModelsCount: 10,
}),

getDataModelsMetaDataMock: jest
.spyOn(dataModel.sdk, 'dataModelsMetadata_query')
.mockResolvedValue({
dataModelsMetadata: dataModelMetaDataStub(),
}),

getIssuersByDataModelMock: jest
.spyOn(dataModel.sdk, 'issuersByDataModel_query')
.mockResolvedValue({
issuersByDataModel: [{ count: 10 }],
}),

getIssuersDataModelCountMock: jest
.spyOn(dataModel.sdk, 'issuersByDataModelCount_query')
.mockResolvedValue({
issuersByDataModelCount: 10,
}),
getTotalofIssuersByDataModelMock: jest
.spyOn(dataModel.sdk, 'getTotalofIssuersByDataModel_query')
.mockResolvedValue({
getTotalofIssuersByDataModel: 10,
}),
});
2 changes: 1 addition & 1 deletion __mocks__/dataRequestTemplate.mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataRequestTemplate } from '../src/dataRequestsTemplate/dataRequestsTemplate';
import { dataRequestTemplateStub } from '../test/stubs/dataRequestTemplate.stub';

export const dataRequestTemplateMockService = (
export const DataRequestTemplateMockService = (
dataRequestTemplate: DataRequestTemplate,
) => ({
createDataRequestTemplateMock: jest
Expand Down
54 changes: 54 additions & 0 deletions __mocks__/proof.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Proof } from '../src/proof/proof';
import { proofStub, createProofMessage } from '../test/stubs/proof.stub';

export const ProofMockService = (proof: Proof) => ({
getProofMock: jest.spyOn(proof.sdk, 'proof_query').mockResolvedValue({
proof: proofStub(),
}),

createProofMock: jest
.spyOn(proof.sdk, 'createProof_mutation')
.mockResolvedValue({
createProof: proofStub(),
}),

createProofMessageMock: jest
.spyOn(proof.sdk, 'createProofMessage_mutation')
.mockResolvedValue({
createProofMessage: createProofMessage,
}),

getProofsMock: jest.spyOn(proof.sdk, 'proofs_query').mockResolvedValue({
proofs: [proofStub()],
}),

getProofsByPDAIdsMock: jest
.spyOn(proof.sdk, 'proofsByPDAIds_query')
.mockResolvedValue({
proofsByPDAIds: [proofStub()],
}),

getReceivedProofsMock: jest
.spyOn(proof.sdk, 'receivedProofs_query')
.mockResolvedValue({
receivedProofs: [proofStub()],
}),

getReceivedProofsCountMock: jest
.spyOn(proof.sdk, 'receivedProofsCount_query')
.mockResolvedValue({
receivedProofsCount: 10,
}),

getSentProofsMock: jest
.spyOn(proof.sdk, 'sentProofs_query')
.mockResolvedValue({
sentProofs: [proofStub()],
}),

getSentProofsCountMock: jest
.spyOn(proof.sdk, 'sentProofsCount_query')
.mockResolvedValue({
sentProofsCount: 10,
}),
});
56 changes: 56 additions & 0 deletions __mocks__/request.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Request } from '../src/request/request';
import { requestStub } from '../test/stubs/request.stub';

export const RequestMockService = (request: Request) => ({
createDataRequestMock: jest
.spyOn(request.sdk, 'createDataRequest_mutation')
.mockResolvedValue({
createDataRequest: requestStub(),
}),

getDataRequestMock: jest
.spyOn(request.sdk, 'dataRequest_query')
.mockResolvedValue({
dataRequest: requestStub(),
}),

getDataRequestCountMock: jest
.spyOn(request.sdk, 'dataRequestCount_query')
.mockResolvedValue({
dataRequestCount: 10,
}),

getDataRequestStatusMock: jest
.spyOn(request.sdk, 'dataRequestStatus_query')
.mockResolvedValue({
dataRequestStatus: requestStub().status,
}),

getDataRequestsMock: jest
.spyOn(request.sdk, 'dataRequests_query')
.mockResolvedValue({
dataRequests: [requestStub()],
}),

getRequestsReceivedMock: jest
.spyOn(request.sdk, 'requestsReceived_query')
.mockResolvedValue({
requestsReceived: [requestStub()],
}),

getRequestReceivedCountMock: jest
.spyOn(request.sdk, 'requestsReceivedCount_query')
.mockResolvedValue({
requestsReceivedCount: 10,
}),

getRequestsSentMock: jest
.spyOn(request.sdk, 'requestsSent_query')
.mockResolvedValue({
requestsSent: [requestStub()],
}),

getRequestsSentCountMock: jest
.spyOn(request.sdk, 'requestsSentCount_query')
.mockResolvedValue({ requestsSentCount: 10 }),
});
11 changes: 10 additions & 1 deletion src/Gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,9 +35,12 @@ export class Gateway {
url,
});
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);
}
}
174 changes: 174 additions & 0 deletions src/data-model/data-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import {
CreateDataModelInput,
Sdk,
dataModels_queryQueryVariables,
FilterDataModelInput,
} from '../../.mesh';
import { errorHandler } from '../utils/errorHandler';
import { isUUIDValid, validateObjectProperties } from '../utils/validators';

/* The `DataModel` class is a TypeScript class that provides methods for creating and retrieving data
models. */

export class DataModel {
public 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 {
validateObjectProperties(createModelInput);
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 {
isUUIDValid(dataModelId);
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<FilterDataModelInput>`. 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<FloatRangeDto> | undefined} consumptionPrice - It is an optional property of
* type `InputMaybe<FloatRangeDto>`. This means that it can either be `undefined` or an object of type
* `FloatRangeDto`.
* @property {InputMaybe<OrganizationIdentificationInput> | undefined} organization - The
* "organization" property is an optional input that represents the identification of an organization.
* It can be of type "InputMaybe<OrganizationIdentificationInput>", 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 getDataModelsMetaData() {
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 {
isUUIDValid(id);
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 {
isUUIDValid(dataModelId);
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 {
isUUIDValid(dataModelId);
return await this.sdk.getTotalofIssuersByDataModel_query({ dataModelId });
} catch (error: any) {
throw new Error(errorHandler(error));
}
}
}
Loading

0 comments on commit cc6dc10

Please sign in to comment.