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 (ns adl-support.core
(:require [clojure.core.memoize :as memo] (:require [clojure.core.memoize :as memo]
[clojure.data.json :as json]
[clojure.java.io :as io] [clojure.java.io :as io]
[clojure.string :refer [split join]] [clojure.string :refer [split join]]
[clojure.tools.logging])) [clojure.tools.logging]))
@ -36,12 +37,15 @@
vr (if vr (if
(string? v) (string? v)
(try (try
(read-string v) (json/read-str v)
(catch Exception _ nil)))] (catch Exception _ nil)))]
(cond (cond
(nil? v) {} (nil? v) {}
(= 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 true
{(keyword k) v}))) {(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." "The international dialing prefix to use, if none is specified."
"44") "44")

View file

@ -10,7 +10,10 @@
(let [expected {:id 67 :offset 0 :limit 50} (let [expected {:id 67 :offset 0 :limit 50}
actual (massage-params {:params {:id "0" :offset "1000" :limit "150"} actual (massage-params {:params {:id "0" :offset "1000" :limit "150"}
:form-params {:id "67" :offset "0" :limit "50"}})] :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 (deftest compose-exception-reason-tests