diff --git a/src/routes/common/entities/address-info.entity.spec.ts b/src/routes/common/entities/address-info.entity.spec.ts new file mode 100644 index 0000000000..d2a0d1f9e1 --- /dev/null +++ b/src/routes/common/entities/address-info.entity.spec.ts @@ -0,0 +1,48 @@ +import { AddressInfo } from '@/routes/common/entities/address-info.entity'; +import { faker } from '@faker-js/faker'; + +describe('AddressInfo entity', () => { + it('should build an AddressInfo', () => { + const value = faker.finance.ethereumAddress(); + const name = faker.word.words(); + const logoUri = faker.internet.url({ appendSlash: false }); + + const actual = new AddressInfo(value, name, logoUri); + + expect(actual.value).toStrictEqual(value); + expect(actual.name).toStrictEqual(name); + expect(actual.logoUri).toStrictEqual(logoUri); + }); + + it('should build an AddressInfo with null name and null logoUri if not provided', () => { + const value = faker.finance.ethereumAddress(); + + const actual = new AddressInfo(value); + + expect(actual.value).toStrictEqual(value); + expect(actual.name).toStrictEqual(null); + expect(actual.logoUri).toStrictEqual(null); + }); + + it('should build an AddressInfo with null name and null logoUri if they are null', () => { + const value = faker.finance.ethereumAddress(); + + const actual = new AddressInfo(value, null, null); + + expect(actual.value).toStrictEqual(value); + expect(actual.name).toStrictEqual(null); + expect(actual.logoUri).toStrictEqual(null); + }); + + it('should build an AddressInfo with null name and null logoUri if empty strings are passed in', () => { + const value = faker.finance.ethereumAddress(); + const name = ''; + const logoUri = ''; + + const actual = new AddressInfo(value, name, logoUri); + + expect(actual.value).toStrictEqual(value); + expect(actual.name).toStrictEqual(null); + expect(actual.logoUri).toStrictEqual(null); + }); +}); diff --git a/src/routes/common/entities/address-info.entity.ts b/src/routes/common/entities/address-info.entity.ts index fbcffa2736..044a784c30 100644 --- a/src/routes/common/entities/address-info.entity.ts +++ b/src/routes/common/entities/address-info.entity.ts @@ -14,7 +14,7 @@ export class AddressInfo { logoUri: string | null = null, ) { this.value = value; - this.name = name; - this.logoUri = logoUri; + this.name = name === '' ? null : name; + this.logoUri = logoUri === '' ? null : logoUri; } }