-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Gateway-DAO/test/proof
- Loading branch information
Showing
15 changed files
with
1,234 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
Oops, something went wrong.