Normalize unset attribute value to empty string

This commit is contained in:
Simon Warta
2020-02-04 19:01:40 +01:00
parent ea12c9751a
commit f9734fb0f3
4 changed files with 12 additions and 7 deletions
+8 -3
View File
@@ -8,9 +8,14 @@ describe("logs", () => {
expect(attr).toEqual({ key: "a", value: "b" }); expect(attr).toEqual({ key: "a", value: "b" });
}); });
it("works for unset value", () => { it("works for empty value", () => {
const attr = parseAttribute({ key: "foobar", value: "" });
expect(attr).toEqual({ key: "foobar", value: "" });
});
it("normalized unset value to empty string", () => {
const attr = parseAttribute({ key: "amount" }); const attr = parseAttribute({ key: "amount" });
expect(attr).toEqual({ key: "amount", value: undefined }); expect(attr).toEqual({ key: "amount", value: "" });
}); });
}); });
@@ -68,7 +73,7 @@ describe("logs", () => {
}, },
{ {
key: "amount", key: "amount",
value: undefined, value: "",
}, },
], ],
} as const; } as const;
+2 -2
View File
@@ -3,7 +3,7 @@ import { isNonNullObject } from "@iov/encoding";
export interface Attribute { export interface Attribute {
readonly key: string; readonly key: string;
readonly value: string | undefined; readonly value: string;
} }
export interface Event { export interface Event {
@@ -27,7 +27,7 @@ export function parseAttribute(input: unknown): Attribute {
return { return {
key: key, key: key,
value: value, value: value || "",
}; };
} }
+1 -1
View File
@@ -225,7 +225,7 @@ describe("RestClient", () => {
.find(event => event.type === "message") .find(event => event.type === "message")
?.attributes.find(attr => attr.key === "contract_address"); ?.attributes.find(attr => attr.key === "contract_address");
if (!contractAddressAttr) throw new Error("Could not find contract_address attribute"); if (!contractAddressAttr) throw new Error("Could not find contract_address attribute");
contractAddress = contractAddressAttr.value || ""; contractAddress = contractAddressAttr.value;
const balance = (await client.authAccounts(contractAddress)).result.value.coins; const balance = (await client.authAccounts(contractAddress)).result.value.coins;
expect(balance).toEqual(transferAmount); expect(balance).toEqual(transferAmount);
+1 -1
View File
@@ -1,6 +1,6 @@
export interface Attribute { export interface Attribute {
readonly key: string; readonly key: string;
readonly value: string | undefined; readonly value: string;
} }
export interface Event { export interface Event {
readonly type: "message" | "transfer"; readonly type: "message" | "transfer";