Skip to content

Commit

Permalink
test: 💍 update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantasdeveloper committed Oct 11, 2024
1 parent 848d316 commit a2103cc
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/claims/dto/claim.dto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('claimsDto', () => {
type: ClaimType.Affiliate,
scope: { type: 'Wrong', value: 123 },
},
['scope.type must be one of the following values: Identity, Ticker, Custom'],
['scope.type must be one of the following values: Identity, Ticker, Asset, Custom'],
],
[
'CustomerDueDiligence without `cddId`',
Expand Down
10 changes: 5 additions & 5 deletions src/identities/identities.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
} from '~/test-utils/service-mocks';
import { TickerReservationsService } from '~/ticker-reservations/ticker-reservations.service';

const { did, txResult, ticker } = testValues;
const { did, txResult, ticker, assetId } = testValues;

describe('IdentitiesController', () => {
let controller: IdentitiesController;
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('IdentitiesController', () => {
it('should return a paginated list of held Assets', async () => {
const mockResults = ['TICKER', 'TICKER2'];
const mockAssets = {
data: mockResults.map(asset => ({ ticker: asset })),
data: mockResults.map(asset => ({ id: asset })),
next: new BigNumber(2),
count: new BigNumber(2),
};
Expand Down Expand Up @@ -716,7 +716,7 @@ describe('IdentitiesController', () => {

const result = await controller.getIsTickerPreApproved({ did }, { ticker });

expect(result).toEqual({ ticker, did, isPreApproved: true });
expect(result).toEqual({ asset: ticker, did, isPreApproved: true });
});
});

Expand All @@ -735,7 +735,7 @@ describe('IdentitiesController', () => {
expect(result).toEqual({
total: paginatedResult.count,
next: paginatedResult.next,
results: [expect.objectContaining({ ticker, did, isPreApproved: true })],
results: [expect.objectContaining({ asset: assetId, did, isPreApproved: true })],
});
});

Expand All @@ -750,7 +750,7 @@ describe('IdentitiesController', () => {
expect(result).toEqual({
total: paginatedResult.count,
next: paginatedResult.next,
results: [expect.objectContaining({ ticker, did, isPreApproved: true })],
results: [expect.objectContaining({ asset: assetId, did, isPreApproved: true })],
});
});
});
Expand Down
8 changes: 5 additions & 3 deletions src/metadata/metadata.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { testValues } from '~/test-utils/consts';
import { createMockMetadataEntry, createMockTransactionResult } from '~/test-utils/mocks';
import { mockMetadataServiceProvider } from '~/test-utils/service-mocks';

const { assetId } = testValues;

describe('MetadataController', () => {
const { txResult } = testValues;
let controller: MetadataController;
Expand Down Expand Up @@ -56,7 +58,7 @@ describe('MetadataController', () => {
const result = await controller.getMetadata({ ticker });

expect(result).toEqual({
results: [new MetadataEntryModel({ asset: ticker, type, id })],
results: [new MetadataEntryModel({ asset: assetId, type, id })],
});
});
});
Expand Down Expand Up @@ -89,7 +91,7 @@ describe('MetadataController', () => {

expect(result).toEqual(
new MetadataDetailsModel({
asset: ticker,
asset: assetId,
type,
id,
...mockDetails,
Expand Down Expand Up @@ -129,7 +131,7 @@ describe('MetadataController', () => {
expect(result).toEqual(
expect.objectContaining({
transactions: [transaction],
metadata: new MetadataEntryModel({ asset: ticker, type, id }),
metadata: new MetadataEntryModel({ asset: assetId, type, id }),
})
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/nfts/nfts.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { mockTransactionsProvider, MockTransactionsService } from '~/test-utils/
import { TransactionsService } from '~/transactions/transactions.service';
import * as transactionsUtilModule from '~/transactions/transactions.util';

const { ticker, signer } = testValues;
const { ticker, signer, assetId } = testValues;

describe('NftService', () => {
let service: NftsService;
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('NftService', () => {
value: 'someValue',
name: 'some name',
specs: {},
ticker,
assetId,
},
];

Expand Down
2 changes: 2 additions & 0 deletions src/offline-submitter/offline-submitter.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { ISubmittableResult } from '@polkadot/types/types';
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { TransactionPayload } from '@polymeshassociation/polymesh-sdk/types';
import { when } from 'jest-when';
Expand Down Expand Up @@ -78,6 +79,7 @@ describe('OfflineSubmitterService', () => {
blockHash: '0x02',
transactionHash: '0x03',
transactionIndex: new BigNumber(1),
result: 'someResult' as unknown as ISubmittableResult,
});

mockPolymeshService.polymeshApi.network = networkMock;
Expand Down
7 changes: 4 additions & 3 deletions src/settlements/settlements.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ describe('SettlementsController', () => {
to: new MockPortfolio(),
amount: new BigNumber(100),
asset: {
ticker: 'TICKER',
id: 'TICKER',
},
},
{
from: new MockPortfolio(),
to: new MockPortfolio(),
nfts: [createMock<Nft>({ id: new BigNumber(1) })],
asset: {
ticker: 'TICKER',
id: 'TICKER',
},
},
{
Expand All @@ -94,6 +94,7 @@ describe('SettlementsController', () => {

expect(result).toEqual({
...mockInstructionDetails,
venue: mockInstructionDetails.venue.id,
mediators: [{ identity: mediatorDid, status: AffirmationStatus.Pending }],
legs: [
...[mockLegs.data[0], mockLegs.data[1]].map(({ from, to, amount, nfts, asset }) => ({
Expand All @@ -104,7 +105,7 @@ describe('SettlementsController', () => {
amount,
nfts,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
asset: (asset as any).ticker,
asset: (asset as any).id,
type: LegType.onChain,
})),
{
Expand Down
2 changes: 2 additions & 0 deletions src/test-utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const options = { signer, processMode: ProcessMode.Submit };
const did = '0x01'.padEnd(66, '0');
const dryRun = false;
const ticker = 'TICKER';
const assetId = '0xa3616b82e8e1080aedc952ea28b9db8b';

const user = new UserModel({
id: '-1',
Expand Down Expand Up @@ -107,6 +108,7 @@ export const testValues = {
txResult,
dryRun,
ticker,
assetId,
};

export const extrinsic = {
Expand Down
3 changes: 2 additions & 1 deletion src/test-utils/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export class MockPolymesh {
}

export class MockAsset {
id = '0xa3616b82e8e1080aedc952ea28b9db8b';
ticker = 'TICKER';
public details = jest.fn();
public getIdentifiers = jest.fn();
Expand Down Expand Up @@ -484,7 +485,7 @@ export function createMockMetadataEntry(
partial: PartialFuncReturn<MetadataEntry> = {
id: new BigNumber(1),
type: MetadataType.Local,
asset: { ticker: 'TICKER' },
asset: { id: testValues.assetId, ticker: 'TICKER' },
}
): DeepMocked<MetadataEntry> {
return createMock<MetadataEntry>(partial);
Expand Down

0 comments on commit a2103cc

Please sign in to comment.