-
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.
- Loading branch information
1 parent
f65e7d0
commit a690a27
Showing
7 changed files
with
1,055 additions
and
0 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,50 @@ | ||
import { GraphQLClient } from 'graphql-request'; | ||
|
||
import { getSdk } from '../../gatewaySdk/sources/GatewayV3'; | ||
import { ActivityMockService } from '../__mocks__/v3/activity.mock'; | ||
import { activityStub } from '../stubs/v3/activity.stub'; | ||
import { Activity } from '../../src/v3/activity/activity'; | ||
|
||
let activity: Activity; | ||
|
||
beforeAll(() => { | ||
activity = new Activity(getSdk(new GraphQLClient(''))); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('ACTIVITY SERVICE TESTING', () => { | ||
it('get Activity count', async () => { | ||
const { getActivityCountMock } = ActivityMockService(activity); | ||
const { activitiesCount } = await activity.getActivityCount(); | ||
|
||
expect(activitiesCount).toBeGreaterThanOrEqual(10); | ||
expect(getActivityCountMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get Activity by id', async () => { | ||
const { getActivityMock } = ActivityMockService(activity); | ||
const { activity: activityResult } = await activity.getActivity( | ||
activityStub().id, | ||
); | ||
expect(activityResult.id).toEqual(activityStub().id); | ||
expect(getActivityMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get Activity by id => throw error', async () => { | ||
const { getActivityMock } = ActivityMockService(activity); | ||
expect(async () => await activity.getActivity('34')).rejects.toThrow( | ||
' should be atleast 2 length', | ||
); | ||
expect(getActivityMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get Activitys', async () => { | ||
const { getActivitysMock } = ActivityMockService(activity); | ||
const { activities } = await activity.getActivities(); | ||
expect(activities.length).toBeGreaterThanOrEqual(0); | ||
expect(getActivitysMock).toHaveBeenCalled(); | ||
}); | ||
}); |
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,180 @@ | ||
import { GraphQLClient } from 'graphql-request'; | ||
|
||
import { getSdk } from '../../gatewaySdk/sources/GatewayV3'; | ||
import { AuthMockService } from '../__mocks__/v3/auth.mock'; | ||
import { authStub } from '../stubs/v3/auth.stub'; | ||
import { Auth } from '../../src/v3/auth/auth'; | ||
import { SignCipherEnum } from '../../src/types'; | ||
|
||
let auth: Auth; | ||
|
||
beforeAll(() => { | ||
auth = new Auth(getSdk(new GraphQLClient(''))); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('AUTH SERVICE TESTING', () => { | ||
it('check username availability', async () => { | ||
const { checkUsernameAvailabilityMock } = AuthMockService(auth); | ||
|
||
const result = await auth.checkUsernameAvailability(authStub().username); | ||
|
||
expect(result).toEqual(true); | ||
expect(checkUsernameAvailabilityMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('check username availability to throw error', async () => { | ||
const { checkUsernameAvailabilityMock } = AuthMockService(auth); | ||
|
||
expect(async () => { | ||
await auth.checkUsernameAvailability(authStub({ username: '' }).username); | ||
}).rejects.toThrow(' should be atleast 2 length'); | ||
expect(checkUsernameAvailabilityMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('check did availability', async () => { | ||
const { checkDIDAvailabilityMock } = AuthMockService(auth); | ||
|
||
const result = await auth.checkDIDAvailability(authStub().did); | ||
|
||
expect(result).toEqual(true); | ||
expect(checkDIDAvailabilityMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('check did availability to throw error', async () => { | ||
const { checkDIDAvailabilityMock } = AuthMockService(auth); | ||
|
||
expect(async () => { | ||
await auth.checkDIDAvailability(authStub({ did: '' }).did); | ||
}).rejects.toThrow(` is not valid did`); | ||
expect(checkDIDAvailabilityMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('create user nonce', async () => { | ||
const { createUserNonceMock } = AuthMockService(auth); | ||
|
||
const nonce = await auth.createUserNonce({ | ||
did: authStub().did, | ||
signingKey: authStub().wallet, | ||
}); | ||
|
||
expect(nonce).toEqual(authStub().message); | ||
expect(createUserNonceMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('create user nonce to throw error', async () => { | ||
const { createUserNonceMock } = AuthMockService(auth); | ||
|
||
expect(async () => { | ||
await auth.createUserNonce({ | ||
did: authStub({ did: '' }).did, | ||
signingKey: authStub().wallet, | ||
}); | ||
}).rejects.toThrow(` is not valid did`); | ||
expect(createUserNonceMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('create user', async () => { | ||
const { createUserMock } = AuthMockService(auth); | ||
|
||
const result = await auth.createUser({ | ||
signature: authStub().signature, | ||
signingKey: authStub().wallet, | ||
}); | ||
|
||
expect(result).toEqual(authStub().jwt); | ||
expect(createUserMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('create user to throw error', async () => { | ||
const { createUserMock } = AuthMockService(auth); | ||
|
||
expect(async () => { | ||
await auth.createUser({ | ||
signature: authStub().signature, | ||
signingKey: authStub({ wallet: '' }).wallet, | ||
}); | ||
}).rejects.toThrow(` is invalid`); | ||
expect(createUserMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('create user to throw wrong wallet error', async () => { | ||
const { createUserMock } = AuthMockService(auth); | ||
|
||
expect(async () => { | ||
await auth.createUser({ | ||
signature: authStub().signature, | ||
signingKey: authStub().wallet, | ||
signingCipher: SignCipherEnum.ED25519, | ||
}); | ||
}).rejects.toThrow(''); | ||
expect(createUserMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('generate nonce', async () => { | ||
const { generateNonceMock } = AuthMockService(auth); | ||
|
||
const { generateNonce } = await auth.generateNonce(authStub().wallet); | ||
|
||
expect(generateNonce.message).toEqual(authStub().message); | ||
expect(generateNonceMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('generate nonce to throw error', async () => { | ||
const { generateNonceMock } = AuthMockService(auth); | ||
|
||
expect(async () => { | ||
await auth.generateNonce(authStub({ wallet: '' }).wallet); | ||
}).rejects.toThrow(` is invalid`); | ||
expect(generateNonceMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('generate nonce to throw wrong wallet error', async () => { | ||
const { generateNonceMock } = AuthMockService(auth); | ||
|
||
expect(async () => { | ||
await auth.generateNonce(authStub().wallet, SignCipherEnum.ED25519); | ||
}).rejects.toThrow(''); | ||
expect(generateNonceMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('refresh token', async () => { | ||
const { refreshTokenMock } = AuthMockService(auth); | ||
|
||
const jwt = await auth.refreshToken({ | ||
signature: authStub().signature, | ||
signingKey: authStub().wallet, | ||
}); | ||
|
||
expect(jwt).toEqual(authStub().jwt); | ||
expect(refreshTokenMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('refresh token to throw error', async () => { | ||
const { refreshTokenMock } = AuthMockService(auth); | ||
|
||
expect(async () => { | ||
await auth.refreshToken({ | ||
signature: authStub({ signature: '' }).signature, | ||
signingKey: authStub().wallet, | ||
}); | ||
}).rejects.toThrow(` should be atleast 2 length`); | ||
expect(refreshTokenMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('refresh token to throw wrong wallet error', async () => { | ||
const { refreshTokenMock } = AuthMockService(auth); | ||
|
||
expect(async () => { | ||
await auth.refreshToken({ | ||
signature: authStub().signature, | ||
signingKey: authStub().wallet, | ||
cipher: 'ED25519', | ||
}); | ||
}).rejects.toThrow(''); | ||
expect(refreshTokenMock).toHaveBeenCalled(); | ||
}); | ||
}); |
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,147 @@ | ||
import { getSdk } from '../../gatewaySdk/sources/GatewayV3'; | ||
import { DataModel } from '../../src/v3/data-model/data-model'; | ||
import { | ||
dataModelCreateStub, | ||
dataModelStub, | ||
dataModelMetaDataStub, | ||
} from '../stubs/v3/data-model.stub'; | ||
import { DataModelMockService } from '../__mocks__/v3/data-model.mock'; | ||
import { GraphQLClient } from 'graphql-request'; | ||
|
||
let dataModel: DataModel; | ||
|
||
beforeAll(() => { | ||
dataModel = new DataModel(getSdk(new GraphQLClient(''))); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('DATA MODEL CLASS METHODS TESTING', () => { | ||
it('create data model ', async () => { | ||
const { createDataModelMock } = DataModelMockService(dataModel); | ||
|
||
const { createDataModel } = await dataModel.createDataModel( | ||
dataModelCreateStub(), | ||
); | ||
|
||
expect(createDataModel.title).toEqual(dataModelCreateStub().data.title); | ||
expect(createDataModelMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('create data model -> throw error ', async () => { | ||
const { createDataModelMock } = DataModelMockService(dataModel); | ||
|
||
expect( | ||
async () => | ||
await dataModel.createDataModel({ | ||
data: { | ||
title: '', | ||
description: '', | ||
schema: undefined, | ||
}, | ||
signature: '', | ||
signingKey: '', | ||
signingCipher: 'ED25519', | ||
}), | ||
).rejects.toThrow(' should be atleast 2 length'); | ||
expect(createDataModelMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get data model', async () => { | ||
const { getDataModelMock } = DataModelMockService(dataModel); | ||
|
||
const { dataModel: rdataModel } = await dataModel.getDataModel( | ||
dataModelStub().id, | ||
); | ||
expect(rdataModel).toEqual(dataModelStub()); | ||
expect(getDataModelMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get data model -> throw error', async () => { | ||
const { getDataModelMock } = DataModelMockService(dataModel); | ||
|
||
expect(async () => await dataModel.getDataModel('wrong')).rejects.toThrow( | ||
'wrong is not valid', | ||
); | ||
expect(getDataModelMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get data models', async () => { | ||
const { getDataModelsMock } = DataModelMockService(dataModel); | ||
|
||
const { dataModels } = await dataModel.getDataModels(); | ||
|
||
expect(dataModels.length).toBeGreaterThanOrEqual(0); | ||
expect(getDataModelsMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get data models count', async () => { | ||
const { getDataModelsCountMock } = DataModelMockService(dataModel); | ||
const { dataModelsCount } = await dataModel.getDataModelsCount(); | ||
expect(dataModelsCount).toBeGreaterThanOrEqual(0); | ||
expect(getDataModelsCountMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get meta data of data models', async () => { | ||
const { getDataModelsMetaDataMock } = DataModelMockService(dataModel); | ||
const { dataModelsMetadata } = await dataModel.getDataModelsMetaData(); | ||
expect(dataModelsMetadata).toEqual(dataModelMetaDataStub()); | ||
expect(getDataModelsMetaDataMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get issuers by data model', async () => { | ||
const { getIssuersByDataModelMock } = DataModelMockService(dataModel); | ||
const { issuersByDataModel } = await dataModel.getIssuersByDataModel( | ||
dataModelStub().id, | ||
); | ||
|
||
expect(issuersByDataModel.length).toBeGreaterThanOrEqual(0); | ||
expect(getIssuersByDataModelMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get issuers by data model -> throw error', async () => { | ||
const { getIssuersByDataModelMock } = DataModelMockService(dataModel); | ||
expect( | ||
async () => await dataModel.getIssuersByDataModel('wrong'), | ||
).rejects.toThrow('wrong is not valid'); | ||
expect(getIssuersByDataModelMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get isssuers by data model count', async () => { | ||
const { getIssuersDataModelCountMock } = DataModelMockService(dataModel); | ||
const { issuersByDataModelCount } = | ||
await dataModel.getIssuersByDataModelCount(dataModelStub().id); | ||
expect(issuersByDataModelCount).toBeGreaterThanOrEqual(0); | ||
expect(getIssuersDataModelCountMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get isssuers by data model count -> throw error', async () => { | ||
const { getIssuersDataModelCountMock } = DataModelMockService(dataModel); | ||
expect( | ||
async () => await dataModel.getIssuersByDataModelCount('wrong'), | ||
).rejects.toThrow('wrong is not valid'); | ||
expect(getIssuersDataModelCountMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get total issuers by data model ', async () => { | ||
const { getTotalofIssuersByDataModelMock } = | ||
DataModelMockService(dataModel); | ||
const { getTotalofIssuersByDataModel } = | ||
await dataModel.getTotalofIssuersByDataModel(dataModelStub().id); | ||
|
||
expect(getTotalofIssuersByDataModel).toBeGreaterThanOrEqual(0); | ||
expect(getTotalofIssuersByDataModelMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get total issuers by data model -> throw error ', async () => { | ||
const { getTotalofIssuersByDataModelMock } = | ||
DataModelMockService(dataModel); | ||
|
||
expect( | ||
async () => await dataModel.getTotalofIssuersByDataModel('wrong'), | ||
).rejects.toThrow('wrong is not valid'); | ||
expect(getTotalofIssuersByDataModelMock).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.