-
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
Showing
4 changed files
with
379 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,55 @@ | ||
import { DataModel } from '../../src/v3/data-model/data-model'; | ||
import { | ||
dataModelStub, | ||
dataModelMetaDataStub, | ||
dataModelCreateStub, | ||
} from '../../test/stubs/v3/data-model.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,131 @@ | ||
import { | ||
DataModel, | ||
CreateDataModelInput, | ||
DataModelsMetadata, | ||
} from '../../../gatewaySdk/sources/GatewayV3'; | ||
|
||
export const dataModelStub = ( | ||
overrideDataModel?: Partial<DataModel>, | ||
): DataModel => ({ | ||
PDAs: [], | ||
allowedOrganizations: [], | ||
allowedUsers: [], | ||
createdAt: '2023-11-29T18:00:55.650Z', | ||
description: | ||
'Net promoter score (NPS) is a market research metric that is based on a single survey question asking respondents to rate the likelihood that they would recommend a company, product, or a service to a friend or colleague. The NPS is a proprietary instrument developed by Fred Reichheld, who owns the registered NPS trademark in conjunction with Bain & Company and Satmetrix. Its popularity and broad use have been attributed to its simplicity and transparent methodology.', | ||
featured: false, | ||
group: { | ||
id: 'd4339c71-f414-4dfd-9213-003317e06862', | ||
createdAt: '2023-11-29T18:00:55.650Z', | ||
dataModels: [], | ||
official: false, | ||
}, | ||
verified: false, | ||
uniqueIssuersCount: 1, | ||
title: 'Net promoter score ', | ||
tags: ['Research', 'Testing'], | ||
schema: { | ||
type: 'object', | ||
default: {}, | ||
title: 'Root Schema', | ||
required: ['score'], | ||
properties: { | ||
score: { | ||
type: 'integer', | ||
default: 10, | ||
title: 'Score', | ||
examples: ['Fill from 0 up to 10'], | ||
}, | ||
testimony: { | ||
type: 'string', | ||
title: 'Testimony', | ||
examples: ['Tell us what your experience was like'], | ||
}, | ||
recommendation: { | ||
type: 'boolean', | ||
title: 'Would you recommend this?', | ||
}, | ||
keywords: { | ||
type: 'array', | ||
title: 'Keywords about your experience', | ||
}, | ||
}, | ||
}, | ||
|
||
id: 'c22d65f0-b7b1-48a9-8c13-a01e32df1f1f', | ||
organization: null, | ||
pdas: [], | ||
pdasIssuedCount: 2, | ||
...overrideDataModel, | ||
}); | ||
|
||
export const dataModelCreateStub = ( | ||
overrideDataModelCreateStub?: CreateDataModelInput, | ||
): CreateDataModelInput => ({ | ||
data: { | ||
description: | ||
'Net promoter score (NPS) is a market research metric that is based on a single survey question asking respondents to rate the likelihood that they would recommend a company, product, or a service to a friend or colleague. The NPS is a proprietary instrument developed by Fred Reichheld, who owns the registered NPS trademark in conjunction with Bain & Company and Satmetrix. Its popularity and broad use have been attributed to its simplicity and transparent methodology.', | ||
|
||
title: 'Net promoter score ', | ||
schema: { | ||
type: 'object', | ||
default: {}, | ||
title: 'Root Schema', | ||
required: ['score'], | ||
properties: { | ||
score: { | ||
type: 'integer', | ||
default: 10, | ||
title: 'Score', | ||
examples: ['Fill from 0 up to 10'], | ||
}, | ||
testimony: { | ||
type: 'string', | ||
title: 'Testimony', | ||
examples: ['Tell us what your experience was like'], | ||
}, | ||
recommendation: { | ||
type: 'boolean', | ||
title: 'Would you recommend this?', | ||
}, | ||
keywords: { | ||
type: 'array', | ||
title: 'Keywords about your experience', | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
signature: '0xd2FEB1aCf86d28cdc21dd733066d158737DaCa8d', | ||
signingKey: 'test', | ||
signingCipher: 'ED25519', | ||
...overrideDataModelCreateStub, | ||
}); | ||
|
||
export const dataModelMetaDataStub = ( | ||
overideDataModelMetaData?: DataModelsMetadata, | ||
): DataModelsMetadata => ({ | ||
tags: [ | ||
'Research', | ||
'Testing', | ||
'Developers', | ||
'Education', | ||
'Music', | ||
'Listening', | ||
'Consumer', | ||
'Finance', | ||
'Banking', | ||
'Credit Card', | ||
'Social', | ||
'Score', | ||
'Earn', | ||
'Marketing', | ||
'Infrastructure', | ||
'Tests', | ||
], | ||
issuedCount: { | ||
min: 0, | ||
max: 14, | ||
}, | ||
...overideDataModelMetaData, | ||
}); |
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(); | ||
}); | ||
}); |