Skip to content

Commit

Permalink
Cannot add event that's in the past
Browse files Browse the repository at this point in the history
  • Loading branch information
johncowie committed Feb 10, 2013
1 parent 020048a commit 7c8e1c7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/nuotl_twitter/messages.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
:duration-error "Invalid duration."
:unapproved "You are unauthorized to use this service."
:too-short-error "Tweet is too short to have all the required parts."
:in-past-error "Your event cannot start in the past."
:success "Your event tweet was successful!"
})

(defn get-message [s]
(messages s))
(if-let [message (messages s)]
message
"Unknown error."
))
10 changes: 9 additions & 1 deletion src/nuotl_twitter/parsing/tweet.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,13 @@
(dissoc (merge m {:start start :end end}) :date :time :duration)
)))

(defn check-if-in-past [m]
(if ( > (compare (clj-time/now) (m :start)) 0)
(throw (Exception. (str :in-past-error)))
m
))

(defn parse-tweet [text]
(infer-end-date (parse-tweet-text text)))
(check-if-in-past
(infer-end-date
(parse-tweet-text text))))
7 changes: 4 additions & 3 deletions test/nuotl_twitter/parsing/tweet_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[nuotl-twitter.dao :as dao]))

(facts
(against-background (dao/get-area-ids) => '("n" "cf"))
(against-background (dao/get-area-ids) => '("n" "cf")
(t/now) => (t/date-time 2013 1 1))
(p/parse-tweet "@nuotl") => (throws Exception ":too-short-error")
(p/parse-tweet "@nuotl X X X X TEXT") => (throws Exception ":date-error")
(p/parse-tweet "@nuotl 1/2/2013 X X X TEXT") => (throws Exception ":time-error")
Expand All @@ -22,6 +23,6 @@
(p/parse-tweet "@nuotl 20/4/2013 15PM 8H CF TEXT") => {:start (t/date-time 2013 4 20 15 0 0)
:end (t/date-time 2013 4 20 23 0 0)
:area :cf
:text "TEXT"
}
:text "TEXT"}
(p/parse-tweet "@nuotl 31/12/2012 11PM 2H N TEXT") => (throws Exception ":in-past-error")
)
11 changes: 11 additions & 0 deletions test/nuotl_twitter/processor_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
(dao/get-tweeter 22) => (assoc (create-tweeter 22) :approved "Y")
(dao/get-area-ids) => '("n")
(dao/add-tweeter (create-tweeter 22) true) => anything
(t/now) => (t/date-time 2013 1 1)
(dao/add-event {:_id 1234
:text "Hello World"
:start (t/date-time 2013 1 25 6 0 0)
Expand Down Expand Up @@ -57,3 +58,13 @@
(dao/get-area-ids) => '("n"))
(p/process-tweet (create-tweet "@nuotl 25/1/2013 6am 3h X Hello World" 22)) => (throws Exception (str :area-error))
)

(facts
(against-background
(dao/get-tweeter 22) => (assoc (create-tweeter 22) :approved "Y")
(dao/get-area-ids) => '("n")
(dao/add-tweeter (create-tweeter 22) true) => anything
(t/now) => (t/date-time 2013 1 1 10 0 0)
(dao/add-event anything) => anything)
(p/process-tweet (create-tweet "@nuotl 1/1/2013 9am 1h N Hello World" 22)) => (throws Exception (str :in-past-error))
)

0 comments on commit 7c8e1c7

Please sign in to comment.