Skip to content

Commit

Permalink
Change AddressInfo empty string values to explicit nulls (#1494)
Browse files Browse the repository at this point in the history
Changes the behavior of `AddressInfo` to explicitly return `null` instead of an empty string for `AddressInfo.name` and `AddressInfo.logoUri`.
  • Loading branch information
hectorgomezv authored Apr 30, 2024
1 parent 93f6a75 commit 02bfbbd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/routes/common/entities/address-info.entity.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
4 changes: 2 additions & 2 deletions src/routes/common/entities/address-info.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 02bfbbd

Please sign in to comment.