Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add applications unit tests #1321

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/graphql/schema/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -2058,9 +2058,18 @@ type MexPair {
"""Base symbol details."""
baseSymbol: String!

"""Mex pair deploy date in unix time."""
deployedAt: Float

"""Mex pair exchange details."""
exchange: String

"""Mex pair dual farms details."""
hasDualFarms: Boolean

"""Mex pair farms details."""
hasFarms: Boolean

"""Id details."""
id: String!

Expand Down Expand Up @@ -2094,6 +2103,9 @@ type MexPair {
"""Total value details."""
totalValue: String!

"""Mex pair trades count."""
tradesCount: Float

"""Mex pair type details."""
type: MexPairType!

Expand Down Expand Up @@ -2145,11 +2157,17 @@ type MexToken {
"""Mex token previous24hPrice."""
previous24hPrice: Float!

"""Mex token previous24hVolume."""
previous24hVolume: Float!

"""Mex token current price."""
price: Float!

"""Symbol for the mex token."""
symbol: String!

"""Mex token trades count."""
tradesCount: Float
}

"""MiniBlocks object type."""
Expand Down Expand Up @@ -3748,6 +3766,9 @@ type TokenDetailed {
"""Total traded value in the last 24h within the liquidity pools."""
totalVolume24h: Float!

"""Mex pair trades count."""
tradesCount: Float

"""Token transactions."""
transactions: Float

Expand Down Expand Up @@ -3952,6 +3973,9 @@ type TokenWithBalanceAccountFlat {
"""Total traded value in the last 24h within the liquidity pools."""
totalVolume24h: Float!

"""Mex pair trades count."""
tradesCount: Float

"""Token transactions."""
transactions: Float

Expand Down
112 changes: 112 additions & 0 deletions src/test/unit/services/applications.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { Test, TestingModule } from "@nestjs/testing";
import { QueryPagination } from "src/common/entities/query.pagination";
import { ElasticIndexerService } from "src/common/indexer/elastic/elastic.indexer.service";
import { ApplicationService } from "src/endpoints/applications/application.service";
import { ApplicationFilter } from "src/endpoints/applications/entities/application.filter";

describe('ApplicationService', () => {
let service: ApplicationService;
let indexerService: ElasticIndexerService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
ApplicationService,
{
provide: ElasticIndexerService,
useValue: {
getApplications: jest.fn(),
getApplicationCount: jest.fn(),
},
},
],
}).compile();

service = module.get<ApplicationService>(ApplicationService);
indexerService = module.get<ElasticIndexerService>(ElasticIndexerService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});

describe('getApplications', () => {
it('should return an array of applications', async () => {
const indexResult = [
{
address: 'erd1qqqqqqqqqqqqqpgq8372f63glekg7zl22tmx7wzp4drql25r6avs70dmp0',
deployer: 'erd1j770k2n46wzfn5g63gjthhqemu9r23n9tp7seu95vpz5gk5s6avsk5aams',
currentOwner: 'erd1j770k2n46wzfn5g63gjthhqemu9r23n9tp7seu95vpz5gk5s6avsk5aams',
initialCodeHash: 'kDh8hR9vyceELMUuy6JdAg0X90+ZaLeyVQS6tPbY82s=',
timestamp: 1724955216,
},
{
address: 'erd1qqqqqqqqqqqqqpgquc4v0pujmewzr26tm2gtawmsq4vsrm4mwmfs459g65',
deployer: 'erd1szcgm7vq3tmyxfgd4wd2k2emh59az8jq5jjpj9799a0k59u0wmfss4vw3v',
currentOwner: 'erd1szcgm7vq3tmyxfgd4wd2k2emh59az8jq5jjpj9799a0k59u0wmfss4vw3v',
initialCodeHash: 'kDiPwFRJhcB7TmeBbQvw1uWQ8vuhRSU6XF71Z4OybeQ=',
timestamp: 1725017514,
},
];

jest.spyOn(indexerService, 'getApplications').mockResolvedValue(indexResult);

const queryPagination = new QueryPagination;
const filter = new ApplicationFilter;
const result = await service.getApplications(queryPagination, filter);

expect(indexerService.getApplications)
.toHaveBeenCalledWith(filter, queryPagination);
expect(indexerService.getApplications)
.toHaveBeenCalledTimes(1);

expect(result).toEqual([
{
contract: "erd1qqqqqqqqqqqqqpgq8372f63glekg7zl22tmx7wzp4drql25r6avs70dmp0",
deployer: "erd1j770k2n46wzfn5g63gjthhqemu9r23n9tp7seu95vpz5gk5s6avsk5aams",
owner: "erd1j770k2n46wzfn5g63gjthhqemu9r23n9tp7seu95vpz5gk5s6avsk5aams",
codeHash: "kDh8hR9vyceELMUuy6JdAg0X90+ZaLeyVQS6tPbY82s=",
timestamp: 1724955216,
},
{
contract: "erd1qqqqqqqqqqqqqpgquc4v0pujmewzr26tm2gtawmsq4vsrm4mwmfs459g65",
deployer: "erd1szcgm7vq3tmyxfgd4wd2k2emh59az8jq5jjpj9799a0k59u0wmfss4vw3v",
owner: "erd1szcgm7vq3tmyxfgd4wd2k2emh59az8jq5jjpj9799a0k59u0wmfss4vw3v",
codeHash: "kDiPwFRJhcB7TmeBbQvw1uWQ8vuhRSU6XF71Z4OybeQ=",
timestamp: 1725017514,
},
]);
});

it('should return an empty array if no applications are found', async () => {
jest.spyOn(indexerService, 'getApplications').mockResolvedValue([]);

const queryPagination = new QueryPagination;
const filter = new ApplicationFilter;
const result = await service.getApplications(queryPagination, filter);

expect(indexerService.getApplications)
.toHaveBeenCalledWith(filter, queryPagination);
expect(indexerService.getApplications)
.toHaveBeenCalledTimes(1);

expect(result).toEqual([]);
});
});

describe('getApplicationsCount', () => {
it('should return total applications count', async () => {
jest.spyOn(indexerService, 'getApplicationCount').mockResolvedValue(2);

const filter = new ApplicationFilter;
const result = await service.getApplicationsCount(filter);

expect(indexerService.getApplicationCount)
.toHaveBeenCalledWith(filter);
expect(indexerService.getApplicationCount)
.toHaveBeenCalledTimes(1);

expect(result).toEqual(2);
});
});
});
Loading