From 881378cfecc2d9db8dc605ffdc7bee75e23d183c Mon Sep 17 00:00:00 2001 From: Robert Andasan Date: Mon, 25 Nov 2024 19:02:07 +0800 Subject: [PATCH] Added test cases for token --- tests/unit/tokenApi.spec.ts | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/unit/tokenApi.spec.ts diff --git a/tests/unit/tokenApi.spec.ts b/tests/unit/tokenApi.spec.ts new file mode 100644 index 0000000..7596472 --- /dev/null +++ b/tests/unit/tokenApi.spec.ts @@ -0,0 +1,46 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions */ +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-nocheck test suite +import chai from 'chai'; +import tokenService from '../../src/services/tokenService'; +import tokenApi from '../../src/apiServices/tokenApi'; +import sinon from 'sinon'; +import httpMocks from 'node-mocks-http'; + +const { expect, assert } = chai; + +describe('Token API', function () { + describe('Token API: Correctly verifies asset data', function () { + afterEach(function () { + sinon.restore(); + }); + + it('should return getTokenInfo successful result if value is valid', async function () { + const request = httpMocks.createRequest({ + method: 'GET', + url: 'test', + params: { + network: "eth", + address: "0x455e53cbb86018ac2b8092fdcd39d8444affc3f6" + } + }); + await sinon + .stub(tokenApi, 'getTokenInfo') + .returns({ + decimal: "18", + logo: "http://eth.svg", + name: "Ethereum", + symbol: "eth" + }); + const response = httpMocks.createResponse({ + eventEmiiter: require('events').EventEmitter, + req: request, + }); + const res = await tokenApi.getTokenInfo(request, res); + expect(res).to.have.property('decimal'); + expect(res).to.have.property('logo'); + expect(res).to.have.property('name'); + expect(res).to.have.property('symbol'); + }); + }); +});