diff --git a/.gitignore b/.gitignore index aa755d4..f10241d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ dist/ *.tgz coverage/ .DS_STORE -gatewaySdk/ \ No newline at end of file +gatewaySdk/ +src/testing.ts \ No newline at end of file diff --git a/__mocks__/auth.mock.ts b/__mocks__/auth.mock.ts index 65f94ed..4829048 100644 --- a/__mocks__/auth.mock.ts +++ b/__mocks__/auth.mock.ts @@ -1,6 +1,6 @@ import { Auth } from '../src/auth/auth'; import { authStub } from '../test/stubs/auth.stub'; -import { pdaStub } from '../test/stubs/pda.stub'; +import { pdaStub } from '../test/stubs/pda/pda.stub'; export const AuthMockService = (auth: Auth) => ({ checkUsernameAvailabilityMock: jest diff --git a/__mocks__/pda.mock.ts b/__mocks__/pda/pda.mock.ts similarity index 90% rename from __mocks__/pda.mock.ts rename to __mocks__/pda/pda.mock.ts index 08e8259..0bcabb3 100644 --- a/__mocks__/pda.mock.ts +++ b/__mocks__/pda/pda.mock.ts @@ -1,5 +1,5 @@ -import { PDA } from '../src/pda/pda'; -import { pdaStub } from '../test/stubs/pda.stub'; +import { PDA } from '../../src/pda/pda'; +import { pdaStub } from '../../test/stubs/pda/pda.stub'; export const PDAMockService = (pda: PDA) => ({ createPDAMock: jest.spyOn(pda.sdk, 'createPDA_mutation').mockResolvedValue({ diff --git a/__mocks__/pda/pdav3.mock.ts b/__mocks__/pda/pdav3.mock.ts new file mode 100644 index 0000000..2fdf3d4 --- /dev/null +++ b/__mocks__/pda/pdav3.mock.ts @@ -0,0 +1,31 @@ +import { PDA } from '../../src/pda/pdav3'; +import { pdaStub } from '../../test/stubs/pda/pdav3.stub'; + +export const PDAMockService = (pda: PDA) => ({ + // createPDAMock: jest.spyOn(pda.sdk, 'createPDA_mutation').mockResolvedValue({ + // createPDA: pdaStub(), + // }), + // changePDAStatusMock: jest + // .spyOn(pda.sdk, 'changePDAStatus_mutation') + // .mockResolvedValue({ + // changePDAStatus: pdaStub({ status: 'Suspended' }), + // }), + // pdaCountMock: jest + // .spyOn(pda.sdk, 'PDACount_query') + // .mockResolvedValue({ PDACount: 10 }), + getPDAMock: jest.spyOn(pda.sdk, 'PDA_query').mockResolvedValue({ + PDA: pdaStub(), + }), + // pdasMock: jest + // .spyOn(pda.sdk, 'PDAs_query') + // .mockResolvedValue({ PDAs: [pdaStub()] }), + // issuedCountPDAMock: jest + // .spyOn(pda.sdk, 'issuedPDAsCount_query') + // .mockResolvedValue({ issuedPDAsCount: 10 }), + // issuedPDAMock: jest + // .spyOn(pda.sdk, 'issuedPDAs_query') + // .mockResolvedValue({ issuedPDAs: [pdaStub()] }), + // updatePDAMock: jest + // .spyOn(pda.sdk, 'updatePDA_mutation') + // .mockResolvedValue({ updatePDA: pdaStub() }), +}); diff --git a/src/Gateway.ts b/src/Gateway.ts index f936191..a084692 100644 --- a/src/Gateway.ts +++ b/src/Gateway.ts @@ -9,7 +9,11 @@ import { Request } from './request/request'; import { DataModel } from './data-model/data-model'; import { User } from './user/user'; import { Transaction } from './transaction/transaction'; -import { checkVersion, clientTimingWrapper, urlsChecker } from './utils/helper'; +import { + checkVersion, + clientTimingWrapper, + parameterChecker, +} from './utils/helper'; export { AuthType, @@ -43,11 +47,7 @@ export class Gateway { url: string; logging?: boolean; }) { - if (!apiKey) throw new Error('No apikey found!'); - if (!token) throw new Error('No token found!'); - if (!url) throw new Error('No url found!.Enter either testnet or prod'); - - urlsChecker(url); + parameterChecker(apiKey, token, url); checkVersion(); diff --git a/src/GatewayV3.ts b/src/GatewayV3.ts new file mode 100644 index 0000000..20c9262 --- /dev/null +++ b/src/GatewayV3.ts @@ -0,0 +1,33 @@ +import { GraphQLClient } from 'graphql-request'; +import { Sdk, getSdk } from '../gatewaySdk/sources/GatewayV3'; +import { + checkVersion, + clientTimingWrapper, + parameterChecker, +} from './utils/helper'; + +export class GatewayV3 { + private sdk: Sdk; + + constructor({ + apiKey, + token, + url, + logging = false, + }: { + apiKey: string; + token: string; + url: string; + logging?: boolean; + }) { + parameterChecker(apiKey, token, url); + + checkVersion(); + + const client = new GraphQLClient(url, { + headers: { Authorization: `Bearer ${token}`, 'X-Api-Key': apiKey }, + }); + + this.sdk = getSdk(client, logging ? clientTimingWrapper : undefined); + } +} diff --git a/src/pda/pdav3.ts b/src/pda/pdav3.ts new file mode 100644 index 0000000..5a960d5 --- /dev/null +++ b/src/pda/pdav3.ts @@ -0,0 +1,144 @@ +import { + CreatePDAInput, + FilterPDAInput, + issuedPDAs_queryQueryVariables, + PDACount_queryQueryVariables, + PDAs_queryQueryVariables, + PDAStatus, + Sdk, + UpdatePDAInput, +} from '../../gatewaySdk/sources/GatewayV3'; +import { errorHandler } from '../utils/errorHandler'; +import { isUUIDValid, validateObjectProperties } from '../utils/validators'; + +export class PDA { + public sdk: Sdk; + + constructor(sdk: Sdk) { + this.sdk = sdk; + } + + /** + * The function `getPDA` is an asynchronous function that takes an `id` parameter and returns a + * Promise that resolves to a `PDA_queryQuery` object. + * @param {string} id - A string representing the ID of the PDA that you + * want to query. + * @returns The function `getPda` is returning a Promise that resolves to a `PDA_queryQuery` object. + */ + async getPDA(id: string) { + try { + isUUIDValid(id); + return await this.sdk.PDA_query({ id }); + } catch (error) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getPDACount` is an asynchronous function that retrieves the count of PDAs + * based on an optional filter. + * @param {FilterPDAInput} [filter] - The `filter` parameter is an optional input that allows you to + * specify criteria for filtering the PDAs before counting them. It is + * of type `FilterPDAInput`. + * @returns a Promise that resolves to a number. + */ + async getPDACount(filter?: PDACount_queryQueryVariables) { + try { + return (await this.sdk.PDACount_query(filter)).PDACount; + } catch (error) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getPDAs` retrieves PDAs based on the provided filter, order, skip, and take + * parameters. + * @param {PDAs_queryQueryVariables} - - `filter`: An object that contains filter criteria for the query. + * @returns a Promise that resolves to a value of type PDAs_queryQuery. + */ + async getPDAs(variables?: PDAs_queryQueryVariables) { + try { + return await this.sdk.PDAs_query(variables); + } catch (error) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getIssuedPDAs` retrieves issued PDAs based on the provided filter, order, skip, and + * take parameters. + * @param {issuedPDAs_queryQueryVariables} - - `filter`: An object that contains filter criteria for the query. It is + * used to specify conditions that the returned PDAs must meet. + * @returns a Promise that resolves to an object of type `issuedPDAs_queryQuery`. + */ + async getIssuedPDAs(variables?: issuedPDAs_queryQueryVariables) { + try { + return await this.sdk.issuedPDAs_query(variables); + } catch (error) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `getIssuedPDAsCount` is an asynchronous function that retrieves the count of issued + * PDAs based on an optional filter. + * @param {FilterPDAInput} [filter] - The `filter` parameter is an optional input that allows you to + * specify criteria for filtering the issued PDAs. It is of type `FilterPDAInput`. + * @returns a Promise that resolves to a number. + */ + async getIssuedPDAsCount(filter?: FilterPDAInput) { + try { + return (await this.sdk.issuedPDAsCount_query({ filter })).issuedPDAsCount; + } catch (error) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `changePDAStatus` is an asynchronous function that takes an `id` and a `status` as + * parameters and returns a Promise that resolves to a `changePDAStatus_mutationMutation` object. + * @param - - `id`: The ID of the PDA whose status needs to be changed. + * @returns a Promise that resolves to a `changePDAStatus_mutationMutation` object. + */ + async changePDAStatus({ id, status }: { id: string; status: PDAStatus }) { + try { + isUUIDValid(id); + return await this.sdk.changePDAStatus_mutation({ input: { id, status } }); + } catch (error) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function creates a PDA using the provided input and returns the result. + * @param {CreatePDAInput} pdaInput - The `pdaInput` parameter is an object that contains the input + * data for creating a PDA . It is of type `CreatePDAInput`. + * @returns the result of the `createPDA_mutation` method call, which is a Promise. + */ + async createPDA(pdaInput: CreatePDAInput) { + try { + validateObjectProperties(pdaInput); + return await this.sdk.createPDA_mutation({ input: pdaInput }); + } catch (error) { + throw new Error(errorHandler(error)); + } + } + + /** + * The function `updatePDA` updates a PDA using the provided input and returns + * the result of the mutation. + * @param {UpdatePDAInput} updatedPDA - The parameter `updatedPDA` is of type `UpdatePDAInput`. It is + * an input object that contains the data to update a PDA. The specific + * properties and their types within `UpdatePDAInput` would depend on the implementation of the + * `updatePDA_m + * @returns a Promise that resolves to an object of type `updatePDA_mutationMutation`. + */ + async updatePDA(updatedPDA: UpdatePDAInput) { + try { + validateObjectProperties(updatedPDA); + return await this.sdk.updatePDA_mutation({ input: updatedPDA }); + } catch (error) { + throw new Error(errorHandler(error)); + } + } +} diff --git a/src/testing.ts b/src/testing.ts index 2b98b84..6cd687c 100644 --- a/src/testing.ts +++ b/src/testing.ts @@ -18,7 +18,8 @@ import { Gateway } from './Gateway'; const testMutationsAndQueries = async () => { const gatewayInstance = new Gateway({ apiKey: 'm9Y5ntNcTlwQ2LbRpYr6K_VhxJXuZJ6Q', - token: '', + token: + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwcm90b2NvbF9pZCI6IjNmOGUxZDUwLWQ2OWYtNGFkNS1iYjI2LWNiZDI3YmQ1M2UxOCIsInByb3RvY29sX2hhc2giOiI0MDIyMDU4MThjYWMxMDljZWJkNzE4ZDZlZTE5YzcyMWViNWU2N2JlMmNkODg2NTljMzZiMjYwMzMwNzhlNzI3ZjhmZjcwYzNkOTU5YjI3ZWNkZWRmNTA2NzI3NjZlODciLCJwcm90b2NvbF93YWxsZXQiOiI2NjE3NmYyMTQ1MzMwMjQyODZhMDdjNjIiLCJwcm90b2NvbF9zaWduZXIiOiJkOWM4NWJmMi1iZTMyLTRmZDQtYjU4MS1hZWM3YmIyYmU2ZmEiLCJhdXRoIjp7ImlkIjoiMzkyMWU5ZWMtNDRmZS00NDhmLWFjNWMtNjdjZWQxNGFjMjI0IiwidHlwZSI6IldBTExFVCJ9LCJjcnlwdG8iOnsicHVibGljUGVtIjoiLS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS1cclxuTUlJQ0lqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FnOEFNSUlDQ2dLQ0FnRUFwTWErMXZmblhCa2owNmdiVUk3clxyXG5IeW1kS3FiSEJwa0RQbUx4SHlHL0VWWEx4N3dKaVA2OHpyOGJlcjloMGdWMWQ4ZGVIdlpBRVJGWXZXbTdIakVrXHJcblNpdE9RdEI0Vm1RajBrTjFWa2VldGN1VU90ZURFVEFlRjhZa3F2cVpLS2hQN1RZV3BCQkQyRVpybHIyWUhINlVcclxuY2FZbmhuRGtnWkZhQnZ3bFRUOTNOTkJmVGwrSlJIb25OaFNhNGdneFdUT296Nmh4aVA1K25GMGJpTHpRa1hNU1xyXG5PMmNHd1NIdCtFVlFMNDViOEd4MDE2QzY4MGJkSEdXcEE0bGQrVmtEZkVmNWRSMDZuK1ZaWWxBZFcrZURrWURyXHJcbmFWMjdIZWxYSXhiWFRidW90aXlsbU5SYzJZU24rMWpaWFBreXkyTDk3Q3hjQTlsRjBvS255WFFKSEpOS0NtcFRcclxubDVYOHovdjV0eGYzM3NOMHRoZ1d4QjU4aFJTcUFtQnExbnRJZVkvNUpna24zelhLREFQM3FnNGtFdXRDNWRDTVxyXG5QZ1J6MTBVMmtJVHRVbHdxTXpLbUszaG5mbHF2MVljaTZyb010a1ZqVGM3M2FOTWswYUxwVTVhejBGd3d2R3F4XHJcbmF1S1lqcXFlTG5sdGduVTZiL0pvd2Yvckx3WitEQ0FMTmRGYzBmaFlJUG9Lc3dHOGdwMHVwNG5OV2diMUMrZ2JcclxuWEQ2T1piTnFacDFlMUhWdGVSU21nT3BWQ2huTm4rVW5rK0Rta3c0cVNoamVnQkpnaEM0d2YrT25IU1Jqek9iK1xyXG5pQ25ObnhFK21xdDlDcmw2NjIxbmFzSmpTWTZaazVLeVBQRk9YaUJkVkR6c3Jobkw4Ym5WbXRCWGtpcFZXMDZvXHJcblQ2M1pyVjBtajJKWEZxNTh1dFhlemtVQ0F3RUFBUT09XHJcbi0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLVxyXG4ifSwidHlwZSI6ImF1dGhfdG9rZW4iLCJpYXQiOjE3MTQwNTQ4MDV9.Lce0NCBvjuLD3uYy1O7tkP0cuSvNzFdWdTccIVP6IFQ', url: 'https://develop.protocol.mygateway.xyz/graphql', logging: true, }); diff --git a/src/utils/helper.ts b/src/utils/helper.ts index eb45e22..dd2eb77 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -42,7 +42,15 @@ export const checkVersion = async () => { } }; -export const urlsChecker = (url: string): boolean => { +export const parameterChecker = ( + apiKey: string, + token: string, + url: string, +): boolean => { + if (!apiKey) throw new Error('No apikey found!'); + if (!token) throw new Error('No token found!'); + if (!url) + throw new Error('No url found!.Use either sandbox or production url'); const urls = [ 'https://protocol.mygateway.xyz/graphql', 'https://sandbox.protocol.mygateway.xyz/graphql', @@ -51,5 +59,5 @@ export const urlsChecker = (url: string): boolean => { ]; if (urls.includes(url)) return true; - else throw new Error('No valid url found!'); + else throw new Error('No valid url found!. Use sandbox or production url'); }; diff --git a/test/auth.test.ts b/test/auth.test.ts index 176ee3b..6edaaf5 100644 --- a/test/auth.test.ts +++ b/test/auth.test.ts @@ -3,7 +3,7 @@ import { AuthMockService } from '../__mocks__/auth.mock'; import { authStub } from './stubs/auth.stub'; import { AuthType } from '../src/types'; import { GraphQLClient } from 'graphql-request'; -import { getSdk } from '../gatewaySdk'; +import { getSdk } from '../gatewaySdk/sources/GatewayV2'; let auth: Auth; diff --git a/test/data-model.test.ts b/test/data-model.test.ts index d6f1095..7d950b0 100644 --- a/test/data-model.test.ts +++ b/test/data-model.test.ts @@ -1,4 +1,4 @@ -import { getSdk } from '../gatewaySdk'; +import { getSdk } from '../gatewaySdk/sources/GatewayV2'; import { DataModel } from '../src/data-model/data-model'; import { dataModelCreateStub, diff --git a/test/dataRequestsTemplate.test.ts b/test/dataRequestsTemplate.test.ts index 2463fcd..78eb3ea 100644 --- a/test/dataRequestsTemplate.test.ts +++ b/test/dataRequestsTemplate.test.ts @@ -1,5 +1,5 @@ import { GraphQLClient } from 'graphql-request'; -import { getSdk } from '../gatewaySdk'; +import { getSdk } from '../gatewaySdk/sources/GatewayV2'; import { DataRequestTemplateMockService } from '../__mocks__/dataRequestTemplate.mock'; import { DataRequestTemplate } from '../src/dataRequestsTemplate/dataRequestsTemplate'; import { diff --git a/test/organization.test.ts b/test/organization.test.ts index fb54e83..3d0ce4a 100644 --- a/test/organization.test.ts +++ b/test/organization.test.ts @@ -1,5 +1,5 @@ import { GraphQLClient } from 'graphql-request'; -import { getSdk } from '../gatewaySdk'; +import { getSdk } from '../gatewaySdk/sources/GatewayV2'; import { OrganizationMockService } from '../__mocks__/organization.mock'; import { Organization } from '../src/organization/organization'; import { diff --git a/test/pda.test.ts b/test/pda/pda.test.ts similarity index 93% rename from test/pda.test.ts rename to test/pda/pda.test.ts index dd47fed..578e196 100644 --- a/test/pda.test.ts +++ b/test/pda/pda.test.ts @@ -1,10 +1,11 @@ -import { PDAStatus } from '../src/types'; -import { PDA } from '../src/pda/pda'; -import { getSdk } from '../gatewaySdk'; -import { pdaCreateStub, pdaStub } from './stubs/pda.stub'; -import { PDAMockService } from '../__mocks__/pda.mock'; import { GraphQLClient } from 'graphql-request'; +import { PDAStatus } from '../../src/types'; +import { PDA } from '../../src/pda/pda'; +import { getSdk } from '../../gatewaySdk/sources/GatewayV2'; +import { pdaCreateStub, pdaStub } from '../stubs/pda/pda.stub'; +import { PDAMockService } from '../../__mocks__/pda/pda.mock'; + let pda: PDA; beforeAll(() => { diff --git a/test/pda/pdav3.test.ts b/test/pda/pdav3.test.ts new file mode 100644 index 0000000..5e3afbe --- /dev/null +++ b/test/pda/pdav3.test.ts @@ -0,0 +1,149 @@ +import { GraphQLClient } from 'graphql-request'; + +import { PDAStatus } from '../../src/types'; +import { PDA } from '../../src/pda/pdav3'; +import { getSdk } from '../../gatewaySdk/sources/GatewayV3'; +import { pdaCreateStub, pdaStub } from '../stubs/pda/pda.stub'; +import { PDAMockService } from '../../__mocks__/pda/pdav3.mock'; + +let pda: PDA; + +beforeAll(() => { + pda = new PDA(getSdk(new GraphQLClient(''))); +}); + +afterAll(() => { + jest.resetAllMocks(); +}); + +describe('PDA SERVICE TESTING', () => { + // it('pda create', async () => { + // const { createPDAMock: createPDAMutationMock } = PDAMockService(pda); + + // const { createPDA } = await pda.createPDA(pdaCreateStub()); + + // expect(createPDA.id).toBe(pdaStub().id); + // expect(createPDAMutationMock).toHaveBeenCalled(); + // }); + + // it('pda create to throw error', async () => { + // const { createPDAMock: createPDAMutationMock } = PDAMockService(pda); + + // expect( + // async () => await pda.createPDA(pdaCreateStub({ title: '' })), + // ).rejects.toThrow(' should be atleast 2 length'); + + // expect(createPDAMutationMock).toHaveBeenCalled(); + // }); + + // it('pda update status', async () => { + // const { changePDAStatusMock } = PDAMockService(pda); + + // const { changePDAStatus } = await pda.changePDAStatus({ + // id: pdaStub().id, + // status: PDAStatus.Suspended, + // }); + + // expect(changePDAStatus.status).toEqual(PDAStatus.Suspended); + // expect(changePDAStatusMock).toHaveBeenCalled(); + // }); + + // it('pda update status to throw error', async () => { + // const { changePDAStatusMock } = PDAMockService(pda); + + // expect( + // async () => + // await pda.changePDAStatus({ + // id: pdaStub({ id: 'f17ac10b-58cc-4372-a567' }).id, + // status: PDAStatus.Suspended, + // }), + // ).rejects.toThrow(''); + + // expect(changePDAStatusMock).toHaveBeenCalled(); + // }); + + it('get pda', async () => { + const { getPDAMock } = PDAMockService(pda); + + const { PDA } = await pda.getPDA(pdaStub().id); + + expect(PDA?.id).toEqual(pdaStub().id); + expect(getPDAMock).toHaveBeenCalled(); + }); + + // it('get pda to throw error', async () => { + // const { getPDAMock } = PDAMockService(pda); + + // expect( + // async () => await pda.getPDA(pdaStub({ id: '' }).id), + // ).rejects.toThrow(''); + + // expect(getPDAMock).toHaveBeenCalled(); + // }); + + // it('pda count', async () => { + // const { pdaCountMock } = PDAMockService(pda); + + // const count = await pda.getPDACount(); + + // expect(count).toBeGreaterThanOrEqual(0); + // expect(pdaCountMock).toHaveBeenCalled(); + // }); + + // it('pdas', async () => { + // const { pdasMock } = PDAMockService(pda); + + // const { PDAs } = await pda.getPDAs({ + // filter: { dataModelIds: [pdaCreateStub().dataModelId] }, + // skip: 0, + // take: 10, + // }); + + // expect(PDAs.length).toBeGreaterThanOrEqual(0); + // expect(pdasMock).toHaveBeenCalled(); + // }); + + // it('issued pdas count', async () => { + // const { issuedCountPDAMock } = PDAMockService(pda); + + // const count = await pda.getIssuedPDAsCount(); + + // expect(count).toBeGreaterThanOrEqual(0); + // expect(issuedCountPDAMock).toHaveBeenCalled(); + // }); + + // it('issued pdas', async () => { + // const { issuedPDAMock } = PDAMockService(pda); + + // const { issuedPDAs } = await pda.getIssuedPDAs(); + + // expect(issuedPDAs.length).toBeGreaterThanOrEqual(0); + // expect(issuedPDAMock).toHaveBeenCalled(); + // }); + + // it('update pda', async () => { + // const { updatePDAMock } = PDAMockService(pda); + + // const { updatePDA } = await pda.updatePDA({ + // id: pdaStub().id, + // title: pdaStub().dataAsset?.title, + // }); + + // expect(updatePDA.dataAsset?.title).toBe(pdaStub().dataAsset?.title); + // expect(updatePDAMock).toHaveBeenCalled(); + // }); + + // it('update pda to throw error', async () => { + // const { updatePDAMock } = PDAMockService(pda); + + // expect( + // async () => + // await pda.updatePDA({ + // id: pdaStub().id, + // title: pdaCreateStub({ title: '' }).title, + // }), + // ).rejects.toThrow(''); + + // expect(updatePDAMock).toHaveBeenCalled(); + // }); +}); diff --git a/test/proof.test.ts b/test/proof.test.ts index d62d481..6944af1 100644 --- a/test/proof.test.ts +++ b/test/proof.test.ts @@ -1,5 +1,5 @@ import { Proof } from '../src/proof/proof'; -import { getSdk } from '../gatewaySdk'; +import { getSdk } from '../gatewaySdk/sources/GatewayV2'; import { proofStub, createProofMessage, @@ -7,7 +7,7 @@ import { requestId, } from './stubs/proof.stub'; import { ProofMockService } from '../__mocks__/proof.mock'; -import { pdaStub } from './stubs/pda.stub'; +import { pdaStub } from './stubs/pda/pda.stub'; import { GraphQLClient } from 'graphql-request'; let proof: Proof; diff --git a/test/request.test.ts b/test/request.test.ts index 862e4ec..9474813 100644 --- a/test/request.test.ts +++ b/test/request.test.ts @@ -1,5 +1,5 @@ import { Request } from '../src/request/request'; -import { getSdk } from '../gatewaySdk'; +import { getSdk } from '../gatewaySdk/sources/GatewayV2'; import { RequestMockService } from '../__mocks__/request.mock'; import { requestStub } from './stubs/request.stub'; import { GraphQLClient } from 'graphql-request'; diff --git a/test/stubs/pda.stub.ts b/test/stubs/pda/pda.stub.ts similarity index 92% rename from test/stubs/pda.stub.ts rename to test/stubs/pda/pda.stub.ts index 4981af1..58aac52 100644 --- a/test/stubs/pda.stub.ts +++ b/test/stubs/pda/pda.stub.ts @@ -1,8 +1,8 @@ import { CreatePDAInput, PrivateDataAsset, -} from '../../gatewaySdk/sources/GatewayV2'; -import { UserIdentifierType } from '../../src/types'; +} from '../../../gatewaySdk/sources/GatewayV2'; +import { UserIdentifierType } from '../../../src/types'; export const pdaStub = (overridePDA?: any): PrivateDataAsset => ({ arweaveUrl: 'https://arweave.net/test', diff --git a/test/stubs/pda/pdav3.stub.ts b/test/stubs/pda/pdav3.stub.ts new file mode 100644 index 0000000..9f7b067 --- /dev/null +++ b/test/stubs/pda/pdav3.stub.ts @@ -0,0 +1,45 @@ +import { + CreatePDAInput, + PrivateDataAsset, +} from '../../../gatewaySdk/sources/GatewayV3'; +import { UserIdentifierType } from '../../../src/types'; + +export const pdaStub = (overridePDA?: any): PrivateDataAsset => ({ + arweaveUrl: 'https://arweave.net/test', + claimHash: '3e0e527bfcdf531ac7e7333f57f9b8eb7a7cf7388c92920b35c778df1f98673b', + id: 'f47ac10b-58cc-4372-a567-0e02b2c3d479', + issuanceDate: new Date('2021-01-01T12:00:00Z'), + lastUpdated: new Date('2021-01-01T12:00:00Z'), + status: 'Valid', + dataAsset: { + description: 'test', + title: 'test', + claim: { gatewayUse: 'test' }, + expirationDate: new Date('2021-01-01T12:00:00Z'), + claimArray: [], + dataModel: {}, + issuer: {}, + owner: {}, + }, + expirationDate: new Date('2021-01-01T12:00:00Z'), + hash: '9c10c15ea609ca3598a35b551e2ebe4827e8fb99b5da8443c0cf84ff20872a1b', + issuerHash: + 'a86d21a712aebd1e6d5a4cb02a6a4a30f41e319a670b401c0bf0fc04c617e0f1', + ownerHash: '65f18a8b37cbf73d8b201345ed1ccf983e0a571b69b2eef17465a26e3b187700', + ...overridePDA, +}); + +export const pdaCreateStub = (overridePDA?: any): CreatePDAInput => ({ + dataModelId: 'f47ac10b-58cc-4372-a567-0e02b2c3d471', + description: 'test', + title: 'test', + claim: { + gatewayUse: 'test', + }, + owner: { + type: UserIdentifierType.GATEWAY_ID, + value: 'sid', + }, + expirationDate: new Date('2021-01-01T12:00:0'), + ...overridePDA, +}); diff --git a/test/transaction.test.ts b/test/transaction.test.ts index 29f5a8b..9d26ced 100644 --- a/test/transaction.test.ts +++ b/test/transaction.test.ts @@ -1,5 +1,5 @@ import { Transaction } from '../src/transaction/transaction'; -import { getSdk } from '../gatewaySdk'; +import { getSdk } from '../gatewaySdk/sources/GatewayV2'; import { TransactionMockService } from '../__mocks__/transaction.mock'; import { transactionStub } from './stubs/transaction.stub'; import { GraphQLClient } from 'graphql-request'; diff --git a/test/user.test.ts b/test/user.test.ts index 9a42a23..718609b 100644 --- a/test/user.test.ts +++ b/test/user.test.ts @@ -1,5 +1,5 @@ import { GraphQLClient } from 'graphql-request'; -import { getSdk } from '../gatewaySdk'; +import { getSdk } from '../gatewaySdk/sources/GatewayV2'; import { UserMockService } from '../__mocks__/user.mock'; import { UserIdentifierType } from '../src/types'; import { User } from '../src/user/user';