Cap maximum number of days requested to mailserver

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
Andrea Maria Piana 2018-06-18 09:09:13 +02:00 committed by Igor Mandrigin
parent 810ca1f93a
commit a313557694
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
2 changed files with 11 additions and 5 deletions

View File

@ -253,7 +253,7 @@
(let [wnode (models.mailserver/fetch-current cofx)
web3 (:web3 db)
now-in-s (quot now 1000)
last-request (or
last-request (max
(get-in db [:account/account :last-request])
(- now-in-s seven-days))
request-messages-topics (get-request-messages-topics db)

View File

@ -81,10 +81,16 @@
cofx {:db db :now 1000000000}]
(testing "inbox is ready"
(testing "last-request is set"
(let [cofx-with-last-request (assoc-in cofx [:db :account/account :last-request] 2)
actual (inbox/request-messages cofx-with-last-request)]
(testing "it uses last request"
(is (= 2 (get-in actual [::inbox/request-messages :from]))))))
(testing "last request is > the 7 days ago"
(let [cofx-with-last-request (assoc-in cofx [:db :account/account :last-request] 400000)
actual (inbox/request-messages cofx-with-last-request)]
(testing "it uses last request"
(is (= 400000 (get-in actual [::inbox/request-messages :from]))))))
(testing "last request is < the 7 days ago"
(let [cofx-with-last-request (assoc-in cofx [:db :account/account :last-request] 2)
actual (inbox/request-messages cofx-with-last-request)]
(testing "it uses last 7 days"
(is (= 395200 (get-in actual [::inbox/request-messages :from])))))))
(testing "last-request is not set"
(let [actual (inbox/request-messages cofx)]
(testing "it defaults to the last 7 days"