Skip to content

Commit

Permalink
[explorer] fix: display metadata values correctly #1122
Browse files Browse the repository at this point in the history
* [explorer] fix: update config for metadata section

* [explorer] feat: add metadata service unit test
  • Loading branch information
AnthonyLaw authored Oct 6, 2022
1 parent 3cd1ba5 commit f0965c9
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 13 deletions.
113 changes: 113 additions & 0 deletions __tests__/infrastructure/MetadataService.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { MetadataService } from '../../src/infrastructure';

// Arrange:
jest.mock('../../src/infrastructure/http', () => {
const {
MosaicId,
Address,
MetadataType,
UInt64
} = require('symbol-sdk');

const commonMetadataEntryProperties = {
version: 1,
compositeHash: '24E125C7CC30B258778B370A05F4D41104C59C899FD9C67DD0B043F7A39CD7C7',
sourceAddress: Address.createFromRawAddress('TCG72DW2OS6GQJRTUKTYCEPVYOAB33HIM2TDRPI'),
scopedMetadataKey: UInt64.fromHex('0000676E69746172'),
targetAddress: Address.createFromRawAddress('TAEYC7NUBWLJDTWDQSD7PGPZ3J7BB6S6ZRWH6VY')
};

return {
createRepositoryFactory: {
createMetadataRepository: () => {
return {
search: () => {
return {
toPromise: () => {
return {
data: [
{
id: '633AF9E4464297FBEB0D3C78',
metadataEntry: {
...commonMetadataEntryProperties,
metadataType: MetadataType.Mosaic,
value: 'mosaic metadata',
targetId: new MosaicId('3DCE9365EAF9ED2F')
}
},
{
id: '633AF986464297FBEB0D3C0C',
metadataEntry: {
...commonMetadataEntryProperties,
metadataType: MetadataType.Namespace,
value: 'namespace metadata',
targetId: new MosaicId('88F51D7777385EA4')
}
},
{
id: '633AF6E0464297FBEB0D38AE',
metadataEntry: {
...commonMetadataEntryProperties,
metadataType: MetadataType.Account,
value: 'account metadata'
}
}
],
isLastPage: true,
pageNumber: 1,
pageSize: 10
};
}
};
}
};
}
}
};
});

describe('MetadataService', () => {
describe('searchMetadatas', () => {
it('returns pagination metadatas dto', async () => {
// Arrange + Act:
const { isLastPage, pageNumber, pageSize, data } = await MetadataService.searchMetadatas({});

// Assert:
const commonMetadataEntryDto= {
version: 1,
compositeHash: '24E125C7CC30B258778B370A05F4D41104C59C899FD9C67DD0B043F7A39CD7C7',
scopedMetadataKey: '0000676E69746172',
sourceAddress: 'TCG72DW2OS6GQJRTUKTYCEPVYOAB33HIM2TDRPI',
targetAddress: 'TAEYC7NUBWLJDTWDQSD7PGPZ3J7BB6S6ZRWH6VY'
};

expect(isLastPage).toBe(true);
expect(pageNumber).toBe(1);
expect(pageSize).toBe(10);
expect(data.length).toBe(3);
expect(data).toEqual([
{
...commonMetadataEntryDto,
metadataId: '633AF9E4464297FBEB0D3C78',
metadataType: 'Mosaic',
targetId: '3DCE9365EAF9ED2F',
value: 'mosaic metadata'
},
{
...commonMetadataEntryDto,
metadataId: '633AF986464297FBEB0D3C0C',
metadataType: 'Namespace',
targetId: '88F51D7777385EA4',
value: 'namespace metadata'
},
{
...commonMetadataEntryDto,
metadataId: '633AF6E0464297FBEB0D38AE',
metadataType: 'Account',
targetId: 'N/A',
value: 'account metadata'
}
]);
});
});
});
4 changes: 2 additions & 2 deletions src/config/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ export const metadata = [
value: {}
},
{
label: 'Address Alias',
label: 'Account',
icon: 'mdi-account',
value: {
metadataType: MetadataType.Account
}
},
{
label: 'Mosaic Alias',
label: 'Mosaic',
icon: 'mdi-circle',
value: {
metadataType: MetadataType.Mosaic
Expand Down
7 changes: 4 additions & 3 deletions src/config/pages/account-detail.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,15 @@
"type": "CardTable",
"title": "metadataEntriesTitle",
"managerGetter": "account/metadatas",
"pagination": "client",
"pageSize": 5,
"pagination": "server",
"hideOnError": true,
"hasFilter":true,
"hideDependOnGetter": "account/info",
"fields": [
"scopedMetadataKey",
"senderAddress",
"targetId",
"metadataType",
"sourceAddress",
"targetAddress",
"value"
]
Expand Down
8 changes: 4 additions & 4 deletions src/config/pages/mosaic-detail.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
"managerGetter": "mosaic/metadatas",
"errorMessage": "metadataEntriesError",
"pagination": "server",
"hasFilter": true,
"hideOnError": true,
"hasFilter": false,
"fields": [
"scopedMetadataKey",
"targetId",
"senderAddress",
"sourceAddress",
"targetAddress",
"metadataValue"
"value"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions src/config/pages/namespace-detail.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
"managerGetter": "namespace/metadatas",
"errorMessage": "metadataEntriesError",
"pagination": "server",
"hasFilter": true,
"hideOnError": true,
"hasFilter": false,
"fields": [
"scopedMetadataKey",
"targetId",
"senderAddress",
"sourceAddress",
"targetAddress",
"metadataValue"
"value"
]
},
{
Expand Down

0 comments on commit f0965c9

Please sign in to comment.