@yoroi/portfolio
Version:
The Portfolio package of Yoroi SDK
99 lines (98 loc) • 4.87 kB
JavaScript
;
var _transformers = require("./transformers");
var _types = require("@yoroi/types");
var _token = require("../token.mocks");
var _tokenActivity = require("../token-activity.mocks");
var _tokenActivity2 = require("./token-activity.mocks");
var _tokenHistory = require("../token-history.mocks");
describe('transformers', () => {
describe('toSecondaryTokenInfos', () => {
it('should return an empty object if apiTokenInfosResponse is empty', () => {
const apiTokenInfosResponse = {};
const result = (0, _transformers.toSecondaryTokenInfos)(apiTokenInfosResponse);
expect(result).toEqual({});
});
it('should return the updated token info if the status code is not HttpStatusCode.NotModified', () => {
const apiTokenInfosResponse = {
[_token.tokenMocks.primaryETH.info.id]: [_types.Api.HttpStatusCode.NotModified, 123456]
};
const result = (0, _transformers.toSecondaryTokenInfos)(apiTokenInfosResponse);
expect(result).toEqual(apiTokenInfosResponse);
});
it('should return the original token info if the status code is HttpStatusCode.NotModified', () => {
const apiTokenInfosResponse = {
[_token.tokenMocks.rnftWhatever.info.id]: [_types.Api.HttpStatusCode.NotModified, 123456],
[_token.tokenMocks.nftCryptoKitty.info.id]: [_types.Api.HttpStatusCode.Ok, _token.tokenMocks.nftCryptoKitty.info, 'etag', 0]
};
const result = (0, _transformers.toSecondaryTokenInfos)(apiTokenInfosResponse);
expect(result).toEqual({
[_token.tokenMocks.rnftWhatever.info.id]: [_types.Api.HttpStatusCode.NotModified, 123456],
[_token.tokenMocks.nftCryptoKitty.info.id]: [200, _token.tokenMocks.nftCryptoKitty.info, 'etag', 0]
});
});
it('should return drop the record if unable to parse the token-info response', () => {
const apiTokenInfosResponse = {
[_token.tokenMocks.primaryETH.info.id]: [2000, _token.tokenMocks.primaryETH.info, 'etag', 0],
[_token.tokenMocks.nftCryptoKitty.info.id]: [_types.Api.HttpStatusCode.Ok, _token.tokenMocks.nftCryptoKitty.info, 'etag', 0]
};
const result = (0, _transformers.toSecondaryTokenInfos)(apiTokenInfosResponse);
expect(result).toEqual({
[_token.tokenMocks.nftCryptoKitty.info.id]: [200, _token.tokenMocks.nftCryptoKitty.info, 'etag', 0]
});
});
it('should return drop the record when the status code is HttpStatusCode.InternalServerError', () => {
const apiTokenInfosResponse = {
[_token.tokenMocks.rnftWhatever.info.id]: [_types.Api.HttpStatusCode.InternalServerError, 'Not found', 3600],
[_token.tokenMocks.nftCryptoKitty.info.id]: [_types.Api.HttpStatusCode.Ok, _token.tokenMocks.nftCryptoKitty.info, 'etag', 0]
};
const result = (0, _transformers.toSecondaryTokenInfos)(apiTokenInfosResponse);
expect(result).toEqual({
[_token.tokenMocks.nftCryptoKitty.info.id]: [200, _token.tokenMocks.nftCryptoKitty.info, 'etag', 0]
});
});
});
describe('toTokenActivity', () => {
it('should return an empty object if apiTokenActivity response is empty', () => {
const apiTokenInfosResponse = {};
expect((0, _transformers.toTokenActivity)(apiTokenInfosResponse)).toEqual({});
});
it('should return the data and deal with empty records', () => {
const responseWithEmptyRecords = {
..._tokenActivity2.duallahanTokenActivityMocks.api.responseSuccessDataOnly,
'token.4': undefined,
'token.5': [_types.Api.HttpStatusCode.InternalServerError, 'Not found']
};
const result = (0, _transformers.toTokenActivity)(responseWithEmptyRecords);
expect(result).toEqual(_tokenActivity.tokenActivityMocks.api.responseDataOnly);
});
});
describe('toTokenHistory', () => {
it('should return undefined if apiTokenHistory response is malformed', () => {
expect((0, _transformers.toTokenHistory)({
whatever: false
})).toEqual(undefined);
});
it('should return the data', () => {
const result = (0, _transformers.toTokenHistory)(_tokenHistory.tokenHistoryMocks.ftNamelessRaw);
expect(result).toEqual(_tokenHistory.tokenHistoryMocks.api.responseDataOnly);
});
});
});
describe('toDullahanRequest', () => {
it('success', () => {
const request = [['token.1', 'hash1'], ['token.2', 'hash2'], ['token.3', 'hash3']];
const result = (0, _transformers.toDullahanRequest)(request);
expect(result).toEqual(['token.1:hash1', 'token.2:hash2', 'token.3:hash3']);
});
});
describe('toProcessedMediaRequest', () => {
it('success', () => {
const request = 'token.1';
const result = (0, _transformers.toProcessedMediaRequest)(request);
expect(result).toEqual({
policy: 'token',
name: '1'
});
});
});
//# sourceMappingURL=transformers.test.js.map