Skip to content

Commit

Permalink
Added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lowdisk17 committed Nov 25, 2024
1 parent c3e13af commit 6c48797
Showing 1 changed file with 123 additions and 3 deletions.
126 changes: 123 additions & 3 deletions tests/unit/assetApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ describe('Asset API', function () {
expect(res.data).to.have.property('providerCardId');
});

it('should return sendPurchase unsuccessful result if value is valid', async function () {
const request = httpMocks.createRequest({
method: 'GET',
url: 'test',
params: {
purchaseid: "58f9cce7-abcb-4468-96f1-d0bc75000ec4",
providerid: "idmoonpay"
}
});
const response = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req: request,
});
await assetApi.sendPurchase(request, response);
expect(JSON.parse(response._getData())).to.have.property('status');
expect(JSON.parse(response._getData())).to.have.property('data');
expect(JSON.parse(response._getData()).data).to.have.property('name');
expect(JSON.parse(response._getData()).data).to.have.property('message');
});

it('should return getAllPurchase successful result if value is valid', async function () {
const request = httpMocks.createRequest({
method: 'GET',
Expand Down Expand Up @@ -221,6 +241,26 @@ describe('Asset API', function () {
expect(res.data[0]).to.have.property('providerCardId');
});

it('should return getAllPurchase unsuccessful result if value is valid', async function () {
const request = httpMocks.createRequest({
method: 'GET',
url: 'test',
params: {
purchaseid: "58f9cce7-abcb-4468-96f1-d0bc75000ec4",
providerid: "idmoonpay"
}
});
const response = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req: request,
});
await assetApi.getAllPurchase(request, response);
expect(JSON.parse(response._getData())).to.have.property('status');
expect(JSON.parse(response._getData())).to.have.property('data');
expect(JSON.parse(response._getData()).data).to.have.property('name');
expect(JSON.parse(response._getData()).data).to.have.property('message');
});

it('should return getAllPurchaseDetails successful result if value is valid', async function () {
const request = httpMocks.createRequest({
method: 'POST',
Expand Down Expand Up @@ -268,6 +308,26 @@ describe('Asset API', function () {
expect(res.data.providers[0]).to.have.property('transactionFee');
});

it('should return getAllPurchaseDetails unsuccessful result if value is valid', async function () {
const request = httpMocks.createRequest({
method: 'GET',
url: 'test',
params: {
purchaseid: "58f9cce7-abcb-4468-96f1-d0bc75000ec4",
providerid: "idmoonpay"
}
});
const response = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req: request,
});
await assetApi.getAllPurchaseDetails(request, response);
expect(JSON.parse(response._getData())).to.have.property('status');
expect(JSON.parse(response._getData())).to.have.property('data');
expect(JSON.parse(response._getData()).data).to.have.property('name');
expect(JSON.parse(response._getData()).data).to.have.property('message');
});

it('should return getPurchaseDetailsOnSelectedAsset successful result if value is valid', async function () {
const request = httpMocks.createRequest({
method: 'POST',
Expand Down Expand Up @@ -320,6 +380,26 @@ describe('Asset API', function () {
expect(res.data.providers[0]).to.have.property('transactionFee');
});

it('should return getPurchaseDetailsOnSelectedAsset unsuccessful result if value is valid', async function () {
const request = httpMocks.createRequest({
method: 'GET',
url: 'test',
params: {
purchaseid: "58f9cce7-abcb-4468-96f1-d0bc75000ec4",
providerid: "idmoonpay"
}
});
const response = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req: request,
});
await assetApi.getPurchaseDetailsOnSelectedAsset(request, response);
expect(JSON.parse(response._getData())).to.have.property('status');
expect(JSON.parse(response._getData())).to.have.property('data');
expect(JSON.parse(response._getData()).data).to.have.property('name');
expect(JSON.parse(response._getData()).data).to.have.property('message');
});

it('should return createPurchaseDetails successful result if value is valid', async function () {
const request = httpMocks.createRequest({
method: 'POST',
Expand Down Expand Up @@ -378,7 +458,27 @@ describe('Asset API', function () {
expect(res.data).to.have.property('widget');
});

it('should return createPurchaseDetails successful result if value is valid', async function () {
it('should return createPurchaseDetails unsuccessful result if value is valid', async function () {
const request = httpMocks.createRequest({
method: 'GET',
url: 'test',
params: {
purchaseid: "58f9cce7-abcb-4468-96f1-d0bc75000ec4",
providerid: "idmoonpay"
}
});
const response = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req: request,
});
await assetApi.createPurchaseDetails(request, response);
expect(JSON.parse(response._getData())).to.have.property('status');
expect(JSON.parse(response._getData())).to.have.property('data');
expect(JSON.parse(response._getData()).data).to.have.property('name');
expect(JSON.parse(response._getData()).data).to.have.property('message');
});

it('should return getAllPurchaseStatus successful result if value is valid', async function () {
const request = httpMocks.createRequest({
method: 'POST',
url: 'test',
Expand All @@ -392,14 +492,34 @@ describe('Asset API', function () {
req: request,
});
await sinon
.stub(assetApi, 'createPurchaseDetails')
.stub(assetApi, 'getAllPurchaseStatus')
.returns({
"status": "success",
"data": "finished"
});
const res = await assetApi.createPurchaseDetails(request, response);
const res = await assetApi.getAllPurchaseStatus(request, response);
expect(res).to.have.property('status');
expect(res).to.have.property('data');
});

it('should return getAllPurchaseStatus unsuccessful result if value is valid', async function () {
const request = httpMocks.createRequest({
method: 'GET',
url: 'test',
params: {
purchaseid: "58f9cce7-abcb-4468-96f1-d0bc75000ec4",
providerid: "idmoonpay"
}
});
const response = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req: request,
});
await assetApi.getAllPurchaseStatus(request, response);
expect(JSON.parse(response._getData())).to.have.property('status');
expect(JSON.parse(response._getData())).to.have.property('data');
expect(JSON.parse(response._getData()).data).to.have.property('name');
expect(JSON.parse(response._getData()).data).to.have.property('message');
});
});
});

0 comments on commit 6c48797

Please sign in to comment.