From d1c12a6dde0fea1ec2b200bf6e4c0bc08075c0ed Mon Sep 17 00:00:00 2001 From: Siddharth9890 Date: Wed, 8 Nov 2023 09:57:53 +0530 Subject: [PATCH] feat: added data request template queries and mutations and unit test --- custom-fetch.ts | 1 - src/Auth.ts | 15 ---- src/Gateway.ts | 7 +- .../dataRequestsTemplate.ts | 78 ++++++++++++++++++ test/dataRequestsTemplate.test.ts | 81 +++++++++++++++++++ 5 files changed, 163 insertions(+), 19 deletions(-) delete mode 100644 src/Auth.ts create mode 100644 src/dataRequestsTemplate/dataRequestsTemplate.ts create mode 100644 test/dataRequestsTemplate.test.ts diff --git a/custom-fetch.ts b/custom-fetch.ts index 336693f..9d3e8a3 100644 --- a/custom-fetch.ts +++ b/custom-fetch.ts @@ -20,6 +20,5 @@ export default function patchedFetch( headers.set('Authorization', `Bearer ${context?.token}`); headers.set('X-Api-Key', context?.apiKey); init.headers = headers; - console.log(url, init); return fetch(url, init); } diff --git a/src/Auth.ts b/src/Auth.ts deleted file mode 100644 index 7301f9e..0000000 --- a/src/Auth.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { createWalletNonce_mutationMutation } from '../.mesh'; - -export class Auth { - private sdk: any; - - constructor(sdk: any) { - this.sdk = sdk; - } - - async createWalletNounce( - wallet: string, - ): Promise { - return await this.sdk.createWalletNonce_mutation({ input: { wallet } }); - } -} diff --git a/src/Gateway.ts b/src/Gateway.ts index 0382041..fce9292 100644 --- a/src/Gateway.ts +++ b/src/Gateway.ts @@ -1,10 +1,11 @@ import { getMeshSDK, Sdk } from '../.mesh'; -import { PDA } from './pda/PDA'; +import { DataRequestTemplate } from './dataRequestsTemplate/dataRequestsTemplate'; +import { PDA } from './pda/pda'; export class Gateway { - // public auth: Auth; public pda: PDA; private sdk: Sdk; + public dataRequestTemplate: DataRequestTemplate; constructor({ apiKey, token }: { apiKey: string; token: string }) { if (!apiKey && !token) throw new Error('No token found'); @@ -12,7 +13,7 @@ export class Gateway { apiKey, token, }); - // this.auth = new Auth(); this.pda = new PDA(this.sdk); + this.dataRequestTemplate = new DataRequestTemplate(this.sdk); } } diff --git a/src/dataRequestsTemplate/dataRequestsTemplate.ts b/src/dataRequestsTemplate/dataRequestsTemplate.ts new file mode 100644 index 0000000..ad37812 --- /dev/null +++ b/src/dataRequestsTemplate/dataRequestsTemplate.ts @@ -0,0 +1,78 @@ +import { + FilterDataRequestTemplateInput, + Sdk, + TemplateSchemaInput, +} from '../../.mesh'; + +export class DataRequestTemplate { + private sdk: Sdk; + + constructor(sdk: Sdk) { + this.sdk = sdk; + } + + /** + * The function creates a data request template using the provided input. + * @param {TemplateSchemaInput} templateInput - The `templateInput` parameter is an object that + * contains the input data for creating a data request template. It should follow the + * `TemplateSchemaInput` schema, which defines the structure and properties of the template input. + * @returns the result of the `createDataRequestTemplate_mutation` method call, which is likely a + * promise that resolves to the result of the mutation. + */ + async createDataRequestTemplate(templateInput: TemplateSchemaInput) { + return await this.sdk.createDataRequestTemplate_mutation({ + input: templateInput, + }); + } + + /** + * The function `getDataRequestTemplate` is an asynchronous function that queries a data request + * template using an ID and returns the result. + * @param {string} id - The `id` parameter is a string that represents the unique identifier of the + * data request template that you want to retrieve. + * @returns the result of the `dataRequestTemplate_query` method call, which is a Promise. + */ + async getDataRequestTemplate(id: string) { + return await this.sdk.dataRequestTemplate_query({ id }); + } + + /** + * The function `getDataRequestTemplates` retrieves data request templates based on the provided + * filter, order, skip, and take parameters. + * @param - - `filter` is an optional parameter of type `FilterDataRequestTemplateInput` that allows + * you to specify conditions to filter the data request templates. + * @returns the result of the `dataRequestTemplates_query` method call, which is a Promise + * that resolves to the data request templates. + */ + async getDataRequestTemplates({ + filter, + order, + skip, + take, + }: { + filter?: FilterDataRequestTemplateInput; + order?: JSON; + skip: number; + take: number; + }) { + return await this.sdk.dataRequestTemplates_query({ + filter, + order, + skip, + take, + }); + } + + /** + * The function `getDataRequestsTemplateCount` is an asynchronous function that retrieves the count + * of data request templates based on an optional filter. + * @param {FilterDataRequestTemplateInput} [filter] - The `filter` parameter is an optional input + * that allows you to specify criteria for filtering the data request templates. It is of type + * `FilterDataRequestTemplateInput`. + * @returns the count of data request templates. + */ + async getDataRequestsTemplateCount(filter?: FilterDataRequestTemplateInput) { + return (await this.sdk.dataRequestTemplatesCount_query({ filter })) + .dataRequestTemplatesCount; + } +} diff --git a/test/dataRequestsTemplate.test.ts b/test/dataRequestsTemplate.test.ts new file mode 100644 index 0000000..e3c479b --- /dev/null +++ b/test/dataRequestsTemplate.test.ts @@ -0,0 +1,81 @@ +import { Gateway } from '../src/Gateway'; + +let api: Gateway; +const DEFAULT_TIMEOUT = 10000; + +beforeAll(() => { + api = new Gateway({ + apiKey: 'm9Y5ntNcTlwQ2LbRpYr6K_VhxJXuZJ6Q', + token: + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwcm90b2NvbF9pZCI6IjkwNzcwODA2LWFlMGMtNGExNS05MjYzLWU5MWJhYWY1ZDkzZiIsImF1dGgiOnsiaWQiOiJlMjJiOWZkNi05NjgzLTRjZDgtOGZlOS1lZWU0YzFmYTJjZjciLCJ0eXBlIjoiV0FMTEVUIn0sImNyeXB0byI6eyJwdWJsaWNQZW0iOiItLS0tLUJFR0lOIFBVQkxJQyBLRVktLS0tLVxyXG5NSUlDSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQWc4QU1JSUNDZ0tDQWdFQXpUdTJCWVVSS3VvM2V2MGx0MjUzXHJcblR3SDlGQkhUbU90dlRXYlQraTExSEF5WW5vUGx4UWV3M0cySnAvanNnS0cxbDN4WHBtdEEwVjlkUGxaUHhVS3BcclxueXM2cWNBdkhmaThpdm15dmk1WVhRYnQ4aE1rY3hKb1RzanZ4V092dTF1bjljVlVSUGkzOTJZTjVwV2lBOEdncVxyXG5zMjlvaGYzOVJDVnM4MkxGQlNCVkI0ZHRhRmJ1cnNlY0M1WStqZVB3UG9tLzJMUlpkTTJ3bFc3ZzhYVmNROUV4XHJcblVxSWpxS296YnVjYmpiT0Q2YXZnRm9JR3VpOVIxdzYrbWFLQmRPK1gxRU5tVGZURHhLclZNRFJtSHFOK0syY1ZcclxuK3NlTWEzcDBjT0VlTklOWjc2V2lhTlhwMjErZ0VSU3hIRkRNOVBjeEZYWGxGeVBEWE1oVkNVNm1xTDNXRmtjNFxyXG5uOTI0bC8zR09Sa1QzZmd4K1FqN2krNS9sU0ZQS2Q1R1U3bFN4VnVBb1hwYWQxUlFCWUxBZGo1dnJacjB5aUprXHJcbi94cjMzbVp6Q0NuN0ZhcW1JeDdSbU4vRk1Sc1JqRGdBd2FUb3RzZ05JZFVGZVZrRURCYm1EWnJtL0k5diswY0hcclxuczA0UCtxaG01b3JEaXFscGZoZVN0M3hqVit5a3Z3d0JIOElSeGdIQ0krZk1ZMThBbDBCSHlkckZhdldWbEVhY1xyXG4yRTFpbDFSdXU0OGxCVXliU0R4Y3Z5RXR5TU94N0ErY0dQcy93MGg5aUtZZy9OVnEvTFdwWjEzYmVzcS9QanpWXHJcbjR5ZnZaTkpyT3VxMXpkc29MdlVaUTVuMHJ1c21PekMyNlhMb3BpVlpUSWk3U1k4QzAvNFNlaVVvaU8vaVBFbnhcclxuOW5nL0RUMEsvQXlLbTBZQ1oxU2pwZ1VDQXdFQUFRPT1cclxuLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tXHJcbiJ9LCJ0eXBlIjoiYXV0aF90b2tlbiIsImlhdCI6MTY5ODIxMTg0N30.zUxmPhnrQlIEZ5pMzHBMFkcqPvjsIfs0er9Dylw5olE', + }); +}); + +describe('Data Requests Template test', () => { + // it( + // 'create data request template', + // async () => { + // const { createDataRequestTemplate } = + // await api.dataRequestTemplate.createDataRequestTemplate({ + // title: 'Create Data Request Template Example', + // description: 'Lorem ipsum dolor sit amet.', + // dataModels: [ + // { + // id: 'f4014d53-b30f-4490-9812-cea379a1b398', + // required: true, + // claimValidations: { + // type: 'object', + // properties: { + // gatewayUse: { + // type: 'string', + // }, + // }, + // required: ['gatewayUse'], + // }, + // }, + // ], + // }); + // expect(createDataRequestTemplate.name).toEqual( + // 'Create Data Request Template Example', + // ); + // }, + // DEFAULT_TIMEOUT, + // ); + + it( + 'get a single data request template', + async () => { + const { dataRequestTemplate } = + await api.dataRequestTemplate.getDataRequestTemplate( + 'ffc48b78-5543-4f78-8cb4-ea4821aa46d2', + ); + expect(dataRequestTemplate?.name).toEqual('Hello Gateway'); + }, + DEFAULT_TIMEOUT, + ); + + it( + 'get data request templates', + async () => { + const { dataRequestTemplates } = + await api.dataRequestTemplate.getDataRequestTemplates({ + skip: 0, + take: 10, + }); + console.log(dataRequestTemplates); + expect(dataRequestTemplates?.length).toBeGreaterThan(0); + }, + DEFAULT_TIMEOUT, + ); + + it( + 'get data request templates count', + async () => { + const count = await api.dataRequestTemplate.getDataRequestsTemplateCount({ + ids: ['ffc48b78-5543-4f78-8cb4-ea4821aa46d2'], + }); + expect(count).toBeGreaterThan(0); + }, + DEFAULT_TIMEOUT, + ); +});