From 319a770872a4395c57e54d473f1361f9a605962a Mon Sep 17 00:00:00 2001 From: m'hammed Date: Sun, 12 Nov 2017 17:08:21 +0100 Subject: [PATCH] [bug] fix #2329 Generate username as Unknown for nil and 0 public key --- src/status_im/utils/gfycat/core.cljs | 19 ++++++++++++++----- .../status_im/test/utils/gfycat/core.cljs | 4 +++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/status_im/utils/gfycat/core.cljs b/src/status_im/utils/gfycat/core.cljs index 286072a5e3..9cd932fca4 100644 --- a/src/status_im/utils/gfycat/core.cljs +++ b/src/status_im/utils/gfycat/core.cljs @@ -9,11 +9,20 @@ [gen vector] (str/capitalize (rnd/seeded-rand-nth gen vector))) +(defn- build-gfy + [public-key] + (let [gen (rnd/rand-gen public-key) + first-adjective (pick-random gen adjectives/data) + second-adjective (pick-random gen adjectives/data) + animal (pick-random gen animals/data)] + (str first-adjective " " second-adjective " " animal))) + +(def unknown-gfy "Unknown") + (defn generate-gfy ([public-key] - (let [gen (rnd/rand-gen public-key) - first-adjective (pick-random gen adjectives/data) - second-adjective (pick-random gen adjectives/data) - animal (pick-random gen animals/data)] - (str first-adjective " " second-adjective " " animal))) + (case public-key + nil unknown-gfy + "0" unknown-gfy + (build-gfy public-key))) ([] (generate-gfy (now-ms)))) diff --git a/test/cljs/status_im/test/utils/gfycat/core.cljs b/test/cljs/status_im/test/utils/gfycat/core.cljs index 9a0a2c06c2..aacab729cb 100644 --- a/test/cljs/status_im/test/utils/gfycat/core.cljs +++ b/test/cljs/status_im/test/utils/gfycat/core.cljs @@ -9,4 +9,6 @@ (is (= (gfy/generate-gfy "e63d083d2d7a13a14632983b5820529445ca8109") "Mediumvioletred Melodic Waterdogs") message) (is (= (gfy/generate-gfy "57348975ff9199ca636207a396b915d6b6a675b4") "Winged Fitting Mosquito") message) (is (= (gfy/generate-gfy "26cf649aebb252a75aebc588e0d9ce93789dbe0b") "Educated Upright Arcticseal") message) - (is (= (gfy/generate-gfy "e63d083d2d7a13a14632983b5820529445ca8109") "Mediumvioletred Melodic Waterdogs") message)) + (is (= (gfy/generate-gfy "e63d083d2d7a13a14632983b5820529445ca8109") "Mediumvioletred Melodic Waterdogs") message) + (is (= (gfy/generate-gfy nil) gfy/unknown-gfy) message) + (is (= (gfy/generate-gfy "0") gfy/unknown-gfy) message))