Skip to content

Commit

Permalink
fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
cfaur09 committed Feb 28, 2024
1 parent af9a8fc commit c1d290a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
28 changes: 16 additions & 12 deletions src/test/unit/controllers/accounts.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,24 @@ describe('AccountController', () => {
});
});

it('should sort accounts by balance when "sort" query parameter is set to "balance"', async () => {
it('should sort accounts by balance when sort query parameter is set to balance', async () => {
const sortedAccountsList = createMockAccountsList(10).sort((a, b) => parseInt(a.balance) - parseInt(b.balance));
accountServiceMocks.getAccounts.mockReturnValue(sortedAccountsList);

const sort = 'balance';
await request(app.getHttpServer())
.get(`${path}?sort=${sort}`)
.expect(200)
.expect(response => {
const isSortedByBalance = response.body.every(
(account: { balance: string; }, i: number, arr: { balance: string; }[]) => i === 0 || parseInt(arr[i - 1].balance) <= parseInt(account.balance));
expect(isSortedByBalance).toBeTruthy();
});
.get(`/accounts?sort=${sort}`)
.expect(200);

expect(accountServiceMocks.getAccounts).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
sort: 'balance',
})
);
});

it('should return only smart contracts when "isSmartContract" query parameter is set to true', async () => {
it('should return only smart contracts when isSmartContract query parameter is set to true', async () => {
const smartContractsList = createMockAccountsList(5, undefined, true);
accountServiceMocks.getAccounts.mockReturnValue(smartContractsList);
await request(app.getHttpServer())
Expand All @@ -130,7 +132,7 @@ describe('AccountController', () => {
});
});

describe("GET /accounts/count", () => {
describe('GET /accounts/count', () => {
it('should return total accounts count', async () => {
accountServiceMocks.getAccountsCount.mockReturnValue(100);

Expand Down Expand Up @@ -193,7 +195,7 @@ describe('AccountController', () => {
});
});

describe("GET /accounts/c", () => {
describe('GET /accounts/c', () => {
it('should return total alternative accounts count', async () => {
accountServiceMocks.getAccountsCount.mockReturnValue(100);

Expand All @@ -206,7 +208,7 @@ describe('AccountController', () => {
});
});

describe("GET /accounts/:address", () => {
describe('GET /accounts/:address', () => {
const mockAccount = {
address: 'erd1vtlpm6sxxvmgt43ldsrpswjrfcsudmradylpxn9jkp66ra3rkz4qruzvfw',
balance: '707809',
Expand Down Expand Up @@ -258,6 +260,8 @@ describe('AccountController', () => {
.expect(response => {
expect(response.body).toEqual(mockAccountWithGuardianInfo);
expect(response.body.isGuarded).toStrictEqual(true);
expect(accountServiceMocks.getAccount).toHaveBeenCalledWith(
expect.any(String), undefined, true);
});
});

Expand Down
13 changes: 8 additions & 5 deletions src/test/unit/controllers/blocks.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,18 @@ describe("BlockController", () => {

it('should filter blocks by shard', async () => {
const shard = 1;
const filteredBlocksList = createMockBlocksList(5).map(block => ({ ...block, shard }));
const filteredBlocksList = createMockBlocksList(5);
blockServiceMock.getBlocks.mockResolvedValue(filteredBlocksList);

await request(app.getHttpServer())
.get(`${path}?shard=${shard}`)
.expect(200)
.expect(response => {
expect(response.body.every((block: { shard: number; }) => block.shard === shard)).toBeTruthy();
});
.expect(200);

expect(blockServiceMock.getBlocks).toHaveBeenCalledWith(
expect.objectContaining({ shard: 1 }),
expect.objectContaining({ from: 0, size: 25 }),
undefined
);
});

it('should paginate the blocks list', async () => {
Expand Down

0 comments on commit c1d290a

Please sign in to comment.