-
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
caa6556
commit 679811c
Showing
8 changed files
with
283 additions
and
8 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,49 @@ | ||
import { Sdk } from '../gatewaySdk/sources/Gateway'; | ||
import { requestStub } from '../test/stubs/request.stub'; | ||
|
||
export const RequestMockService = (sdk: Sdk) => ({ | ||
createDataRequestMock: jest | ||
.spyOn(sdk, 'createDataRequestMutation') | ||
.mockResolvedValue({ | ||
createDataRequest: requestStub(), | ||
}), | ||
updateDataRequestMock: jest | ||
.spyOn(sdk, 'updateDataRequestMutation') | ||
.mockResolvedValue({ | ||
updateDataRequest: requestStub(), | ||
}), | ||
getDataRequestMock: jest.spyOn(sdk, 'dataRequestQuery').mockResolvedValue({ | ||
dataRequest: requestStub(), | ||
}), | ||
getDataRequestCountMock: jest | ||
.spyOn(sdk, 'dataRequestCountQuery') | ||
.mockResolvedValue({ | ||
dataRequestCount: 10, | ||
}), | ||
getDataRequestStatusMock: jest | ||
.spyOn(sdk, 'dataRequestStatusQuery') | ||
.mockResolvedValue({ | ||
dataRequestStatus: requestStub().status, | ||
}), | ||
getDataRequestsMock: jest.spyOn(sdk, 'dataRequestsQuery').mockResolvedValue({ | ||
dataRequests: [requestStub()], | ||
}), | ||
getRequestsReceivedMock: jest | ||
.spyOn(sdk, 'requestsReceivedQuery') | ||
.mockResolvedValue({ | ||
requestsReceived: [requestStub()], | ||
}), | ||
getRequestReceivedCountMock: jest | ||
.spyOn(sdk, 'requestsReceivedCountQuery') | ||
.mockResolvedValue({ | ||
requestsReceivedCount: 10, | ||
}), | ||
|
||
getRequestsSentMock: jest.spyOn(sdk, 'requestsSentQuery').mockResolvedValue({ | ||
requestsSent: [requestStub()], | ||
}), | ||
|
||
getRequestsSentCountMock: jest | ||
.spyOn(sdk, 'requestsSentCountQuery') | ||
.mockResolvedValue({ requestsSentCount: 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
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 |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import { GraphQLClient } from 'graphql-request'; | ||
import { getSdk, Sdk } from '../gatewaySdk/sources/Gateway'; | ||
import { ethers } from 'ethers'; | ||
import { Request } from '../src/modules/request/request'; | ||
import { ValidationService } from '../src/services/validator-service'; | ||
import { WalletService } from '../src/services/wallet-service'; | ||
import { | ||
createRequestStub, | ||
requestStub, | ||
updateRequestStub, | ||
} from './stubs/request.stub'; | ||
import { RequestMockService } from '../__mocks__/request.mock'; | ||
|
||
let request: Request; | ||
let sdk: Sdk; | ||
let wallet: ethers.Wallet; | ||
|
||
beforeAll(() => { | ||
sdk = getSdk(new GraphQLClient('')); | ||
wallet = ethers.Wallet.createRandom(); | ||
request = new Request( | ||
sdk, | ||
new ValidationService(), | ||
{ | ||
apiKey: '', | ||
token: '', | ||
url: '', | ||
walletPrivateKey: wallet.privateKey, | ||
}, | ||
new WalletService({ walletPrivateKey: wallet.privateKey }), | ||
); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('REQUEST SERVICE TESTING', () => { | ||
it('data request create', async () => { | ||
const { createDataRequestMock } = RequestMockService(sdk); | ||
|
||
const { createDataRequest } = | ||
await request.createDataRequest(createRequestStub()); | ||
|
||
expect(createDataRequest.id).toBe(requestStub().id); | ||
expect(createDataRequestMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('data request create -> throw error', async () => { | ||
const { createDataRequestMock } = RequestMockService(sdk); | ||
|
||
expect( | ||
async () => | ||
await request.createDataRequest(createRequestStub({ id: '' })), | ||
).rejects.toThrow(''); | ||
expect(createDataRequestMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('data request update', async () => { | ||
const { updateDataRequestMock } = RequestMockService(sdk); | ||
|
||
const { updateDataRequest } = | ||
await request.updateDataRequest(updateRequestStub()); | ||
|
||
expect(updateDataRequest.id).toBe(requestStub().id); | ||
expect(updateDataRequestMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('data request create -> throw error', async () => { | ||
const { updateDataRequestMock } = RequestMockService(sdk); | ||
|
||
expect( | ||
async () => | ||
await request.updateDataRequest(updateRequestStub({ id: '' })), | ||
).rejects.toThrow(''); | ||
expect(updateDataRequestMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get data request', async () => { | ||
const { getDataRequestMock } = RequestMockService(sdk); | ||
const { dataRequest } = await request.getDataRequest(requestStub().id); | ||
|
||
expect(dataRequest.id).toBe(requestStub().id); | ||
expect(getDataRequestMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get data request -> throw error', async () => { | ||
const { getDataRequestMock } = RequestMockService(sdk); | ||
|
||
expect(async () => await request.getDataRequest('wrong')).rejects.toThrow( | ||
'wrong is not valid', | ||
); | ||
expect(getDataRequestMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get data request count', async () => { | ||
const { getDataRequestCountMock } = RequestMockService(sdk); | ||
const { dataRequestCount } = await request.getDataRequestCount(); | ||
|
||
expect(dataRequestCount).toBeGreaterThanOrEqual(0); | ||
expect(getDataRequestCountMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get data request status', async () => { | ||
const { getDataRequestStatusMock } = RequestMockService(sdk); | ||
const { dataRequestStatus } = await request.getDataRequestStatus( | ||
requestStub().id, | ||
); | ||
|
||
expect(dataRequestStatus).toEqual(requestStub().status); | ||
expect(getDataRequestStatusMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get data request status -> throww message', async () => { | ||
const { getDataRequestStatusMock } = RequestMockService(sdk); | ||
|
||
expect( | ||
async () => await request.getDataRequestStatus('wrong'), | ||
).rejects.toThrow('wrong is not valid'); | ||
expect(getDataRequestStatusMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get data requests', async () => { | ||
const { getDataRequestMock } = RequestMockService(sdk); | ||
const { dataRequests } = await request.getDataRequests(); | ||
|
||
expect(dataRequests.length).toBeGreaterThanOrEqual(0); | ||
expect(getDataRequestMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get requests received', async () => { | ||
const { getRequestsReceivedMock } = RequestMockService(sdk); | ||
const { requestsReceived } = await request.getRequestsReceived(); | ||
|
||
expect(requestsReceived.length).toBeGreaterThanOrEqual(0); | ||
expect(getRequestsReceivedMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get requests recieved count', async () => { | ||
const { getRequestReceivedCountMock } = RequestMockService(sdk); | ||
const { requestsReceivedCount } = await request.getRequestsReceivedCount(); | ||
|
||
expect(requestsReceivedCount).toBeGreaterThanOrEqual(0); | ||
expect(getRequestReceivedCountMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get requests sent', async () => { | ||
const { getRequestsSentMock } = RequestMockService(sdk); | ||
const { requestsSent } = await request.getRequestsSent(); | ||
|
||
expect(requestsSent.length).toBeGreaterThanOrEqual(0); | ||
expect(getRequestsSentMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('get requests sent count', async () => { | ||
const { getDataRequestCountMock } = RequestMockService(sdk); | ||
const { requestsSentCount } = await request.getRequestsSentCount(); | ||
|
||
expect(requestsSentCount).toBeGreaterThanOrEqual(0); | ||
expect(getDataRequestCountMock).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,48 @@ | ||
import { | ||
DataRequest, | ||
DataRequestSchemaInput, | ||
UpdateDataRequestData, | ||
} from '../../gatewaySdk/sources/Gateway'; | ||
|
||
export const requestStub = (overrideDataRequest?: any): DataRequest => ({ | ||
id: '6188e5e1-dc9e-4b4a-837a-63e18c5f1ae5', | ||
arweaveUrl: 'https://arweave.net/Mrs7eYW4366sIOM4nZ9mKHU-XnftQ_RbfDS1Hx1EQWM', | ||
createdAt: '2023-12-12T18:46:12.932Z', | ||
data: { | ||
dataUse: | ||
'Give you a discount for the next "Taylor Swift - The Eras Tour" concert!', | ||
proofData: {}, | ||
schema: [{ id: '6188e5e1-dc9e-4b4a-837a-63e18c5f1ae5' }], | ||
}, | ||
|
||
owner: { | ||
did: 'did:gatewayId:rawatmanish12', | ||
}, | ||
verifierOrganization: true, | ||
verifier: { id: '6188e5e1-dc9e-4b4a-837a-63e18c5f1ae5' }, | ||
...overrideDataRequest, | ||
}); | ||
|
||
export const createRequestStub = ( | ||
overrideDataRequest?: any, | ||
): DataRequestSchemaInput => ({ | ||
id: '6188e5e1-dc9e-4b4a-837a-63e18c5f1ae5', | ||
data: { | ||
dataUse: 'Example data usage for the user.', | ||
owner: { type: 'USER_DID', value: 'did:gatewayid:mygateway:rawatmanish12' }, | ||
schema: [ | ||
{ | ||
id: '6188e5e1-dc9e-4b4a-837a-63e18c5f1ae5', | ||
}, | ||
], | ||
}, | ||
...overrideDataRequest, | ||
}); | ||
|
||
export const updateRequestStub = ( | ||
overrideDataRequest?: any, | ||
): UpdateDataRequestData => ({ | ||
requestId: '6188e5e1-dc9e-4b4a-837a-63e18c5f1ae5', | ||
status: 'EXPIRED', | ||
...overrideDataRequest | ||
}); |
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