Fixes to the phone tag

This commit is contained in:
Simon Brooke 2018-08-28 16:20:38 +01:00
parent 8598463ec7
commit 50d50aab94
3 changed files with 11 additions and 4 deletions

View file

@ -1,5 +1,6 @@
(ns adl-support.core
(:require [clojure.core.memoize :as memo]
[clojure.data.json :as json]
[clojure.java.io :as io]
[clojure.string :refer [split join]]
[clojure.tools.logging]))
@ -36,12 +37,15 @@
vr (if
(string? v)
(try
(read-string v)
(json/read-str v)
(catch Exception _ nil)))]
(cond
(nil? v) {}
(= v "") {}
(number? vr) {(keyword k) vr}
(and
(number? vr)
;; there's a problem that json/read-str will read "07777 888999" as 7777
(re-matches #"^[0-9.]+$" v)) {(keyword k) vr}
true
{(keyword k) v})))

View file

@ -20,7 +20,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def *default-international-dialing-prefix*
(def ^:dynamic *default-international-dialing-prefix*
"The international dialing prefix to use, if none is specified."
"44")

View file

@ -10,7 +10,10 @@
(let [expected {:id 67 :offset 0 :limit 50}
actual (massage-params {:params {:id "0" :offset "1000" :limit "150"}
:form-params {:id "67" :offset "0" :limit "50"}})]
(is (= expected actual) "Request with form params, params and form params differ"))))
(is (= expected actual) "Request with form params, params and form params differ"))
(let [expected {:phone "07777 888999"}
actual (massage-params {:params {:phone "07777 888999"}})]
(is (= expected actual) "A phone number with a space in needs to be treated as a string"))))
(deftest compose-exception-reason-tests