From 25e2a58ef3631e0edd563869383efd2dfbb58a12 Mon Sep 17 00:00:00 2001 From: Siddharth9890 Date: Tue, 12 Dec 2023 15:34:02 +0530 Subject: [PATCH] feat: done with user,data request template mocks and stubs --- __mocks__/dataRequestTemplate.mock.ts | 23 +++ __mocks__/organization.mock.ts | 27 +++ __mocks__/pda.mock.ts | 8 +- __mocks__/user.mock.ts | 25 +++ .../dataRequestsTemplate.ts | 5 +- src/organization/organization.ts | 6 +- src/user/user.ts | 12 +- test/auth.test.ts | 1 - test/dataRequestsTemplate.test.ts | 133 +++++++------ test/organization.test.ts | 182 +++++++++--------- test/pda.test.ts | 2 +- test/stubs/dataRequestTemplate.stub.ts | 54 ++++++ test/stubs/organization.stub.ts | 22 +++ test/stubs/user.stub.ts | 22 +++ test/user.test.ts | 138 ++++++------- 15 files changed, 414 insertions(+), 246 deletions(-) create mode 100644 __mocks__/dataRequestTemplate.mock.ts create mode 100644 __mocks__/organization.mock.ts create mode 100644 __mocks__/user.mock.ts create mode 100644 test/stubs/dataRequestTemplate.stub.ts create mode 100644 test/stubs/organization.stub.ts create mode 100644 test/stubs/user.stub.ts diff --git a/__mocks__/dataRequestTemplate.mock.ts b/__mocks__/dataRequestTemplate.mock.ts new file mode 100644 index 0000000..750a0c7 --- /dev/null +++ b/__mocks__/dataRequestTemplate.mock.ts @@ -0,0 +1,23 @@ +import { DataRequestTemplate } from '../src/dataRequestsTemplate/dataRequestsTemplate'; +import { dataRequestTemplateStub } from '../test/stubs/dataRequestTemplate.stub'; + +export const dataRequestTemplateMockService = (dataRequestTemplate: DataRequestTemplate) => ({ + createDataRequestTemplateMock: jest + .spyOn(dataRequestTemplate.sdk, 'createDataRequestTemplate_mutation') + .mockResolvedValue({ + createDataRequestTemplate: dataRequestTemplateStub(), + }), + getDataRequestTemplateMock: jest + .spyOn(dataRequestTemplate.sdk, 'dataRequestTemplate_query') + .mockResolvedValue({ + dataRequestTemplate: dataRequestTemplateStub(), + }), + getDataRequestTemplatesMock: jest + .spyOn(dataRequestTemplate.sdk, 'dataRequestTemplates_query') + .mockResolvedValue({ dataRequestTemplates: [dataRequestTemplateStub()] }), + getDataRequestsTemplateCount: jest + .spyOn(dataRequestTemplate.sdk, 'dataRequestTemplatesCount_query') + .mockResolvedValue({ + dataRequestTemplatesCount: 10, + }), +}); diff --git a/__mocks__/organization.mock.ts b/__mocks__/organization.mock.ts new file mode 100644 index 0000000..5d6b158 --- /dev/null +++ b/__mocks__/organization.mock.ts @@ -0,0 +1,27 @@ +import { Organization } from '../src/organization/organization'; +import { organizationStub } from '../test/stubs/organization.stub'; + +export const OrganizationMockService = (organization: Organization) => ({ + createOrganizationMock: jest + .spyOn(organization.sdk, 'createOrganization_mutation') + .mockResolvedValue({ + createOrganization: organizationStub(), + }), + getOrganizationMock: jest + .spyOn(organization.sdk, 'organization_query') + .mockResolvedValue({ + organization: organizationStub(), + }), + updateOrganizationMock: jest + .spyOn(organization.sdk, 'updateOrganization_mutation') + .mockResolvedValue({ + updateOrganization: organizationStub({ + description: 'updated description', + }), + }), + getOrganizationsMock: jest + .spyOn(organization.sdk, 'organizations_query') + .mockResolvedValue({ + organizations: [organizationStub()], + }), +}); diff --git a/__mocks__/pda.mock.ts b/__mocks__/pda.mock.ts index cbe705b..f71be47 100644 --- a/__mocks__/pda.mock.ts +++ b/__mocks__/pda.mock.ts @@ -2,11 +2,9 @@ import { PDA } from '../src/pda/pda'; import { pdaStub } from '../test/stubs/pda.stub'; export const PDAMockService = (pda: PDA) => ({ - createPDAMutationMock: jest - .spyOn(pda.sdk, 'createPDA_mutation') - .mockResolvedValue({ - createPDA: pdaStub(), - }), + createPDAMock: jest.spyOn(pda.sdk, 'createPDA_mutation').mockResolvedValue({ + createPDA: pdaStub(), + }), changePDAStatusMock: jest .spyOn(pda.sdk, 'changePDAStatus_mutation') .mockResolvedValue({ diff --git a/__mocks__/user.mock.ts b/__mocks__/user.mock.ts new file mode 100644 index 0000000..dfa9b0c --- /dev/null +++ b/__mocks__/user.mock.ts @@ -0,0 +1,25 @@ +import { Organization } from '../src/organization/organization'; +import { User } from '../src/user/user'; +import { organizationStub } from '../test/stubs/organization.stub'; +import { userStub } from '../test/stubs/user.stub'; + +export const UserMockService = (user: User) => ({ + meMock: jest.spyOn(user.sdk, 'me_query').mockResolvedValue({ + me: userStub(), + }), + getSingleUserMock: jest.spyOn(user.sdk, 'user_query').mockResolvedValue({ + user: userStub(), + }), + updateOrganizationMock: jest + .spyOn(organization.sdk, 'updateOrganization_mutation') + .mockResolvedValue({ + updateOrganization: organizationStub({ + description: 'updated description', + }), + }), + getOrganizationsMock: jest + .spyOn(organization.sdk, 'organizations_query') + .mockResolvedValue({ + organizations: [organizationStub()], + }), +}); diff --git a/src/dataRequestsTemplate/dataRequestsTemplate.ts b/src/dataRequestsTemplate/dataRequestsTemplate.ts index 0499892..112d850 100644 --- a/src/dataRequestsTemplate/dataRequestsTemplate.ts +++ b/src/dataRequestsTemplate/dataRequestsTemplate.ts @@ -4,9 +4,10 @@ import { TemplateSchemaInput, } from '../../.mesh'; import { errorHandler } from '../utils/errorHandler'; +import { isUUIDValid, validateObjectProperties } from '../utils/validators'; export class DataRequestTemplate { - private sdk: Sdk; + public sdk: Sdk; constructor(sdk: Sdk) { this.sdk = sdk; @@ -22,6 +23,7 @@ export class DataRequestTemplate { */ async createDataRequestTemplate(templateInput: TemplateSchemaInput) { try { + validateObjectProperties(templateInput); return await this.sdk.createDataRequestTemplate_mutation({ input: templateInput, }); @@ -39,6 +41,7 @@ export class DataRequestTemplate { */ async getDataRequestTemplate(id: string) { try { + isUUIDValid(id); return await this.sdk.dataRequestTemplate_query({ id }); } catch (error) { throw new Error(errorHandler(error)); diff --git a/src/organization/organization.ts b/src/organization/organization.ts index b0a56a2..27c4a95 100644 --- a/src/organization/organization.ts +++ b/src/organization/organization.ts @@ -8,9 +8,10 @@ import { } from '../../.mesh'; import { OrganizationIdentifierType } from '../types'; import { errorHandler } from '../utils/errorHandler'; +import { isStringValid, validateObjectProperties } from '../utils/validators'; export class Organization { - private sdk: Sdk; + public sdk: Sdk; constructor(sdk: Sdk) { this.sdk = sdk; @@ -28,6 +29,7 @@ export class Organization { */ async createOrganization(organizationInput: CreateOrganizationInput) { try { + validateObjectProperties(organizationInput); return await this.sdk.createOrganization_mutation({ input: organizationInput, }); @@ -97,6 +99,7 @@ export class Organization { */ async updateOrganization(updatedOrganization: UpdateOrganizationInput) { try { + validateObjectProperties(updatedOrganization); return await this.sdk.updateOrganization_mutation({ input: updatedOrganization, }); @@ -118,6 +121,7 @@ export class Organization { */ async getOrganization(type: OrganizationIdentifierType, value: string) { try { + isStringValid(value); return await this.sdk.organization_query({ input: { type, value } }); } catch (error) { throw new Error(errorHandler(error)); diff --git a/src/user/user.ts b/src/user/user.ts index 6ee71b3..fb5d570 100644 --- a/src/user/user.ts +++ b/src/user/user.ts @@ -7,9 +7,14 @@ import { } from '../../.mesh'; import { PDAFilter, UserIdentifierType } from '../types'; import { errorHandler } from '../utils/errorHandler'; +import { + isEmailValid, + isStringValid, + validateObjectProperties, +} from '../utils/validators'; export class User { - private sdk: Sdk; + public sdk: Sdk; constructor(sdk: Sdk) { this.sdk = sdk; @@ -43,6 +48,7 @@ export class User { value: string; }) { try { + isStringValid(value); return await this.sdk.user_query({ input: { type, value } }); } catch (error) { throw new Error(errorHandler(error)); @@ -124,6 +130,7 @@ export class User { */ async updateUser(updatedUser: UpdateUserInput) { try { + validateObjectProperties(updatedUser); return await this.sdk.updateUser_mutation({ input: updatedUser }); } catch (error) { throw new Error(errorHandler(error)); @@ -140,6 +147,7 @@ export class User { */ async updateMyDisplayName(displayName: string) { try { + isStringValid(displayName); return await this.sdk.updateMyDisplayName_mutation({ displayName }); } catch (error) { throw new Error(errorHandler(error)); @@ -156,6 +164,7 @@ export class User { */ async updateMyGatewayId(gatewayId: string) { try { + isStringValid(gatewayId); return await this.sdk.updateMyGatewayId_mutation({ gatewayId }); } catch (error) { throw new Error(errorHandler(error)); @@ -187,6 +196,7 @@ export class User { */ async updateNotificationEmail(email: string) { try { + isEmailValid(email); return (await this.sdk.updateNotificationEmail_mutation({ email })) .updateNotificationEmail; } catch (error) { diff --git a/test/auth.test.ts b/test/auth.test.ts index d4c6687..1e1466e 100644 --- a/test/auth.test.ts +++ b/test/auth.test.ts @@ -1,6 +1,5 @@ import { Auth } from '../src/auth/auth'; import { getMeshSDK } from '../.mesh'; -import { Chain } from '../src/types'; import { AuthMockService } from '../__mocks__/auth.mock'; import { authStub } from './stubs/auth.stub'; diff --git a/test/dataRequestsTemplate.test.ts b/test/dataRequestsTemplate.test.ts index 96b85f9..4c584fd 100644 --- a/test/dataRequestsTemplate.test.ts +++ b/test/dataRequestsTemplate.test.ts @@ -1,73 +1,70 @@ -// import dotenv from 'dotenv'; -// import { Gateway } from '../src/Gateway'; -// dotenv.config(); +import { getMeshSDK } from '../.mesh'; +import { dataRequestTemplateMockService } from '../__mocks__/dataRequestTemplate.mock'; +import { DataRequestTemplate } from '../src/dataRequestsTemplate/dataRequestsTemplate'; +import { + dataRequestTemplateCreateStub, + dataRequestTemplateStub, +} from './stubs/dataRequestTemplate.stub'; -// let api: Gateway; -// const DEFAULT_TIMEOUT = 10000; +let dataRequestTemplate: DataRequestTemplate; -// beforeAll(() => { -// api = new Gateway({ -// apiKey: process.env.API_KEY!, -// token: process.env.BEARER_TOKEN!, -// }); -// }); +beforeAll(() => { + dataRequestTemplate = new DataRequestTemplate(getMeshSDK()); +}); -// 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: process.env.DATAMODEL_ID!, -// required: true, -// claimValidations: { -// type: 'object', -// properties: { -// gatewayUse: { -// type: 'string', -// }, -// }, -// required: ['gatewayUse'], -// }, -// }, -// ], -// }); -// expect(createDataRequestTemplate.name).toEqual( -// 'Create Data Request Template Example', -// ); -// const { dataRequestTemplate } = -// await api.dataRequestTemplate.getDataRequestTemplate( -// createDataRequestTemplate.id, -// ); -// expect(dataRequestTemplate).toBeDefined(); -// }, -// DEFAULT_TIMEOUT, -// ); +afterAll(() => { + jest.resetAllMocks(); +}); -// it( -// 'get data request templates', -// async () => { -// const { dataRequestTemplates } = -// await api.dataRequestTemplate.getDataRequestTemplates({ -// skip: 0, -// take: 10, -// }); -// expect(dataRequestTemplates?.length).toBeGreaterThan(0); -// }, -// DEFAULT_TIMEOUT, -// ); +describe('Data Requests Template test', () => { + it('create data request template', async () => { + const { createDataRequestTemplateMock } = + dataRequestTemplateMockService(dataRequestTemplate); -// it( -// 'get data request templates count', -// async () => { -// const count = -// await api.dataRequestTemplate.getDataRequestsTemplateCount(); -// expect(count).toBeGreaterThan(0); -// }, -// DEFAULT_TIMEOUT, -// ); -// }); + const { createDataRequestTemplate } = + await dataRequestTemplate.createDataRequestTemplate( + dataRequestTemplateCreateStub(), + ); + + expect(createDataRequestTemplate.name).toEqual( + dataRequestTemplateCreateStub().title, + ); + expect(createDataRequestTemplateMock).toHaveBeenCalled(); + }); + + it('get data request template by id', async () => { + const { getDataRequestTemplateMock } = + dataRequestTemplateMockService(dataRequestTemplate); + + const res = await dataRequestTemplate.getDataRequestTemplate( + dataRequestTemplateStub().id, + ); + + expect(res.dataRequestTemplate?.id).toEqual(dataRequestTemplateStub().id); + expect(getDataRequestTemplateMock).toHaveBeenCalled(); + }); + + it('get data request templates', async () => { + const { getDataRequestTemplatesMock } = + dataRequestTemplateMockService(dataRequestTemplate); + + const { dataRequestTemplates } = + await dataRequestTemplate.getDataRequestTemplates({ + skip: 0, + take: 10, + }); + + expect(dataRequestTemplates?.length).toBeGreaterThan(0); + expect(getDataRequestTemplatesMock).toHaveBeenCalled(); + }); + + it('get data request templates count', async () => { + const { getDataRequestsTemplateCount } = + dataRequestTemplateMockService(dataRequestTemplate); + + const count = await dataRequestTemplate.getDataRequestsTemplateCount(); + + expect(count).toBeGreaterThan(0); + expect(getDataRequestsTemplateCount).toHaveBeenCalled(); + }); +}); diff --git a/test/organization.test.ts b/test/organization.test.ts index 1618a45..9fb34b2 100644 --- a/test/organization.test.ts +++ b/test/organization.test.ts @@ -1,86 +1,96 @@ -// import dotenv from 'dotenv'; -// import { Gateway } from '../src/Gateway'; -// import { -// OrganizationIdentifierType, -// OrganizationRole, -// UserIdentifierType, -// } from '../src/types'; -// dotenv.config(); -// const DEFAULT_TIMEOUT = 10000; - -// let api: Gateway; - -// beforeAll(() => { -// api = new Gateway({ -// apiKey: process.env.API_KEY!, -// token: process.env.BEARER_TOKEN!, -// }); -// }); - -// describe('ORGANIZATION SERVICE TESTING', () => { -// it( -// 'organization crud', -// async () => { -// let obj = { -// username: 'test_for_sdk_2', -// name: 'test org sdk 2', -// description: 'test organization', -// }; -// const { createOrganization } = -// await api.organization.createOrganization(obj); -// const { organization } = await api.organization.getOrganization( -// OrganizationIdentifierType.ORG_ID, -// createOrganization.id, -// ); -// expect(organization?.id).toEqual(createOrganization.id); -// let updatedOrgObj = { -// description: 'changed description for organization', -// id: createOrganization.id, -// }; -// const { updateOrganization } = -// await api.organization.updateOrganization(updatedOrgObj); -// expect(updateOrganization.description).toEqual(updatedOrgObj.description); -// }, -// DEFAULT_TIMEOUT, -// ); - -// it( -// 'member crud organization', -// async () => { -// let addMemberObj = { -// organization: { -// type: OrganizationIdentifierType.ORG_ID, -// value: process.env.ORGAINZATION_ID!, -// }, -// user: { type: UserIdentifierType.GATEWAY_ID, value: 'testing_sdk' }, -// }; -// let changeMemberRoleObj = { -// ...addMemberObj, -// role: OrganizationRole.Admin, -// }; -// const { addMemberToOrganization } = -// await api.organization.addMemberToOrganization(addMemberObj); -// expect(addMemberToOrganization).toBeDefined(); -// const { changeMemberRole } = -// await api.organization.changeMemberRole(changeMemberRoleObj); -// expect(changeMemberRole).toBeDefined(); -// const { removeMemberFromOrganization } = -// await api.organization.removeMemberFromOrganization(addMemberObj); -// expect(removeMemberFromOrganization).toBeDefined(); -// }, -// DEFAULT_TIMEOUT, -// ); - -// it( -// 'organizations', -// async () => { -// const { organizations } = await api.organization.getOrganizations({ -// filter: { verified: false }, -// skip: 0, -// take: 10, -// }); -// expect(organizations.length).toBeGreaterThanOrEqual(0); -// }, -// DEFAULT_TIMEOUT, -// ); -// }); +import { getMeshSDK } from '../.mesh'; +import { OrganizationMockService } from '../__mocks__/organization.mock'; +import { Organization } from '../src/organization/organization'; +import { + OrganizationIdentifierType, + OrganizationRole, + UserIdentifierType, +} from '../src/types'; +import { + organizationCreateStub, + organizationStub, +} from './stubs/organization.stub'; + +let organization: Organization; + +beforeAll(() => { + organization = new Organization(getMeshSDK()); +}); + +afterAll(() => { + jest.resetAllMocks(); +}); + +describe('ORGANIZATION SERVICE TESTING', () => { + it('organization create', async () => { + const { createOrganizationMock } = OrganizationMockService(organization); + + const { createOrganization } = await organization.createOrganization( + organizationCreateStub(), + ); + + expect(createOrganization.name).toEqual(organizationStub().name); + expect(createOrganizationMock).toHaveBeenCalled(); + }); + + it('get single organization', async () => { + const { getOrganizationMock } = OrganizationMockService(organization); + + const res = await organization.getOrganization( + OrganizationIdentifierType.ORG_ID, + organizationStub().id, + ); + + expect(res.organization?.id).toEqual(organizationStub().id); + expect(getOrganizationMock).toHaveBeenCalled(); + }); + + it('update organization', async () => { + const { updateOrganizationMock } = OrganizationMockService(organization); + + let updatedOrgObj = { + description: 'updated description', + id: organizationStub().id, + }; + const { updateOrganization } = + await organization.updateOrganization(updatedOrgObj); + + expect(updateOrganization.description).toEqual(updatedOrgObj.description); + expect(updateOrganizationMock).toHaveBeenCalled(); + }); + + it('member crud organization', async () => { + let addMemberObj = { + organization: { + type: OrganizationIdentifierType.ORG_ID, + value: process.env.ORGAINZATION_ID!, + }, + user: { type: UserIdentifierType.GATEWAY_ID, value: 'testing_sdk' }, + }; + let changeMemberRoleObj = { + ...addMemberObj, + role: OrganizationRole.Admin, + }; + const { addMemberToOrganization } = + await organization.addMemberToOrganization(addMemberObj); + expect(addMemberToOrganization).toBeDefined(); + const { changeMemberRole } = + await organization.changeMemberRole(changeMemberRoleObj); + expect(changeMemberRole).toBeDefined(); + const { removeMemberFromOrganization } = + await organization.removeMemberFromOrganization(addMemberObj); + expect(removeMemberFromOrganization).toBeDefined(); + }); + + it('organizations', async () => { + const { getOrganizationsMock } = OrganizationMockService(organization); + + const { organizations } = await organization.getOrganizations({ + skip: 0, + take: 10, + }); + + expect(organizations.length).toBeGreaterThanOrEqual(0); + expect(getOrganizationsMock).toHaveBeenCalled(); + }); +}); diff --git a/test/pda.test.ts b/test/pda.test.ts index 9430976..bfe65e9 100644 --- a/test/pda.test.ts +++ b/test/pda.test.ts @@ -16,7 +16,7 @@ afterAll(() => { describe('PDA SERVICE TESTING', () => { it('pda create', async () => { - const { createPDAMutationMock } = PDAMockService(pda); + const { createPDAMock: createPDAMutationMock } = PDAMockService(pda); const { createPDA } = await pda.createPDA(pdaCreateStub()); diff --git a/test/stubs/dataRequestTemplate.stub.ts b/test/stubs/dataRequestTemplate.stub.ts new file mode 100644 index 0000000..096d513 --- /dev/null +++ b/test/stubs/dataRequestTemplate.stub.ts @@ -0,0 +1,54 @@ +import { DataRequestTemplate, TemplateSchemaInput } from '../../.mesh'; + +export const dataRequestTemplateStub = ( + overrideDataRequestTemplate?: any, +): DataRequestTemplate => ({ + arweaveUrl: 'https://arweave.net/test', + createdAt: new Date('2021-01-01T12:00:00Z'), + dataModels: [ + { + id: 'f47ac20b-58cc-4372-a567-0e02b2c3d479', + required: true, + claimValidations: { + type: 'object', + properties: { + gatewayUse: { + type: 'string', + }, + }, + required: ['gatewayUse'], + }, + }, + ], + dataRequestsCount: 10, + description: 'test', + name: 'test', + revenueGenerated: 100, + uniqueVerifiersCount: 10, + schema: {}, + dataRequests: [], + id: 'f47ac20b-58cc-4372-a567-0e02b2c3d478', + tags: ['test'], + user: {}, + ...overrideDataRequestTemplate, +}); + +export const dataRequestTemplateCreateStub = (): TemplateSchemaInput => ({ + title: 'test', + description: 'test', + dataModels: [ + { + id: 'f47ac20b-58cc-4372-a567-0e02b2c3d479', + required: true, + claimValidations: { + type: 'object', + properties: { + gatewayUse: { + type: 'string', + }, + }, + required: ['gatewayUse'], + }, + }, + ], +}); diff --git a/test/stubs/organization.stub.ts b/test/stubs/organization.stub.ts new file mode 100644 index 0000000..5719429 --- /dev/null +++ b/test/stubs/organization.stub.ts @@ -0,0 +1,22 @@ +import { CreateOrganizationInput, Organization } from '../../.mesh'; + +export const organizationStub = ( + overrideOrganization?: Partial, +): Organization => ({ + id: 'f47ac10b-58cc-4372-a567-0e02b2c3d479', + createdAt: new Date('2021-01-01T12:00:00Z'), + updatedAt: new Date('2021-01-01T12:00:00Z'), + description: 'test', + name: 'test', + dataRequestTemplates: [], + usernameUpdatedAt: new Date('2021-01-01T12:00:00Z'), + verified: true, + verifierDataRequests: [], + ...overrideOrganization, +}); + +export const organizationCreateStub = (): CreateOrganizationInput => ({ + username: 'test_for_sdk_2', + name: 'test org sdk 2', + description: 'test organization', +}); diff --git a/test/stubs/user.stub.ts b/test/stubs/user.stub.ts new file mode 100644 index 0000000..8aeee9d --- /dev/null +++ b/test/stubs/user.stub.ts @@ -0,0 +1,22 @@ +import { User } from '../../.mesh'; + +export const userStub = (overrideUser?: Partial): User => ({ + id: 'f47ac10b-58cc-4372-a567-0e02b2c3d479', + createdAt: new Date('2021-01-01T12:00:00Z'), + updatedAt: new Date('2021-01-01T12:00:00Z'), + status: 'Valid', + credentialsExtraCredits: 10, + dataModelsExtraCredits: 10, + dataRequestTemplates: [], + gatewayIdLastupdate: new Date('2021-01-01T12:00:00Z'), + isCompleted: true, + issuedPDAs: [], + receivedPDAs: [], + receivedProofs: [], + recipientDataRequests: [], + verifierDataRequests: [], + roles: [], + gatewayId: 'testuser01', + email: 'testuser01@mygateway.xyz', + ...overrideUser, +}); diff --git a/test/user.test.ts b/test/user.test.ts index d71b137..3c00c45 100644 --- a/test/user.test.ts +++ b/test/user.test.ts @@ -1,93 +1,67 @@ -// import dotenv from 'dotenv'; -// import { Gateway } from '../src/Gateway'; -// import { UserIdentifierType } from '../src/types'; -// dotenv.config(); +import { getMeshSDK } from '../.mesh'; +import { UserIdentifierType } from '../src/types'; +import { User } from '../src/user/user'; -// const DEFAULT_TIMEOUT = 10000; +let user: User; -// let api: Gateway; +beforeAll(() => { + user = new User(getMeshSDK()); +}); -// beforeAll(() => { -// api = new Gateway({ -// apiKey: process.env.API_KEY!, -// token: process.env.BEARER_TOKEN!, -// }); -// }); +afterAll(() => { + jest.clearAllMocks(); +}); -// describe('USER Testing', () => { -// it( -// 'me', -// async () => { -// const { me } = await api.user.me(); -// expect(me.gatewayId).toEqual('sid'); -// }, -// DEFAULT_TIMEOUT, -// ); +describe('USER Testing', () => { + it('me', async () => { + const { me } = await user.me(); + expect(me.gatewayId).toEqual('sid'); + }); -// it( -// 'single user', -// async () => { -// const { user } = await api.user.getSingleUser({ -// type: UserIdentifierType.GATEWAY_ID, -// value: 'sid', -// }); -// expect(user?.gatewayId).toEqual('sid'); -// }, -// DEFAULT_TIMEOUT, -// ); + it('single user', async () => { + const res = await user.getSingleUser({ + type: UserIdentifierType.GATEWAY_ID, + value: 'sid', + }); + expect(res.user?.gatewayId).toEqual('sid'); + }); -// it( -// 'my pdas count', -// async () => { -// const count = await api.user.myPDACount({}); -// expect(count).toBeGreaterThanOrEqual(0); -// }, -// DEFAULT_TIMEOUT, -// ); + it('my pdas count', async () => { + const count = await user.myPDACount({}); + expect(count).toBeGreaterThanOrEqual(0); + }); -// it( -// 'my pdas', -// async () => { -// const { myPDAs } = await api.user.myPDAs({ -// skip: 0, -// take: 10, -// }); -// expect(myPDAs.length).toBeGreaterThanOrEqual(0); -// }, -// DEFAULT_TIMEOUT, -// ); + it('my pdas', async () => { + const { myPDAs } = await user.myPDAs({ + skip: 0, + take: 10, + }); + expect(myPDAs.length).toBeGreaterThanOrEqual(0); + }); -// it( -// 'my data models count', -// async () => { -// const count = await api.user.myDataModelsCount(); -// expect(count).toBeGreaterThanOrEqual(0); -// }, -// DEFAULT_TIMEOUT, -// ); + it('my data models count', async () => { + const count = await user.myDataModelsCount(); + expect(count).toBeGreaterThanOrEqual(0); + }); -// it( -// 'my data requests template count', -// async () => { -// const count = await api.user.myDataRequestTemplatesCount(); -// expect(count).toBeGreaterThanOrEqual(0); -// }, -// DEFAULT_TIMEOUT, -// ); + it('my data requests template count', async () => { + const count = await user.myDataRequestTemplatesCount(); + expect(count).toBeGreaterThanOrEqual(0); + }); -// it('update user', async () => { -// const { updateUser } = await api.user.updateUser({ -// displayName: 'siddharth9890', -// }); -// expect(updateUser.displayName).toEqual('siddharth9890'); -// }); + it('update user', async () => { + const { updateUser } = await user.updateUser({ + displayName: 'siddharth9890', + }); + expect(updateUser.displayName).toEqual('siddharth9890'); + }); -// it('update profile picture', async () => { -// const { updateMyProfilePicture } = await api.user.updateMyProfilePicture( -// 'https://www.tryodyssey.xyz/images/campaigns/lifi/odyssey_lifi.png', -// ); -// expect(updateMyProfilePicture).toEqual( -// 'https://www.tryodyssey.xyz/images/campaigns/lifi/odyssey_lifi.png', -// ); -// }); -// }); + it('update profile picture', async () => { + const { updateMyProfilePicture } = await user.updateMyProfilePicture( + 'https://www.tryodyssey.xyz/images/campaigns/lifi/odyssey_lifi.png', + ); + expect(updateMyProfilePicture).toEqual( + 'https://www.tryodyssey.xyz/images/campaigns/lifi/odyssey_lifi.png', + ); + }); +});