-
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.
feat: done with user,data request template mocks and stubs
- Loading branch information
1 parent
38a604f
commit 25e2a58
Showing
15 changed files
with
414 additions
and
246 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,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, | ||
}), | ||
}); |
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,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()], | ||
}), | ||
}); |
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,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()], | ||
}), | ||
}); |
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
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
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 |
---|---|---|
@@ -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(); | ||
}); | ||
}); |
Oops, something went wrong.