summaryrefslogtreecommitdiffstats
path: root/model/utils_test.go
diff options
context:
space:
mode:
authorDmitry Samuylov <dsamuylov@pharo.com>2018-08-28 13:09:32 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2018-08-28 13:09:32 -0400
commit42806ae965b861955235698f247df862fd655d09 (patch)
tree4a92f098976b089dc832f3f0dc5ecfc0392690ed /model/utils_test.go
parent61e27beabc9804fdcf59ed9df2180802175a4f70 (diff)
downloadchat-42806ae965b861955235698f247df862fd655d09.tar.gz
chat-42806ae965b861955235698f247df862fd655d09.tar.bz2
chat-42806ae965b861955235698f247df862fd655d09.zip
Feature/search after before on (#9219)
* initial implementation of after, before, on search flags allowing to restrict the search to a specific day or a date range * missed setting beforeDate in SearchParams in one place * fixed condition when only flags are used for search without any plain terms * changed date format used for after/before/on flags to be in ISO8601 format as suggested in PR comments, added a helper function to pad month and day with zeroes allowing the user user either format, with or without leading zeroes * corrected expected compare to date setting for the TestParseDateFilterToTimeISO8601 test * fixed a bug for the scenario when you only have the date flags without any terms, added a couple of tests for that scenario * updated the date filter logic to use parameters to construct the query instead of simply appending strings together, as suggested in the pull request comments * added search unit test using date flags * added a helper function to create a test post with a createat date manually set, updated the test for search using date flags to create test posts with different createat dates to be able to better test the functionality * MM-11817 Add support for after/before/on search flags with Elasticsearch * add support to search posts to perform the search in context of the client's timezone when filtering by createat date using on: after: before: flags * updated tests to match the new signature
Diffstat (limited to 'model/utils_test.go')
-rw-r--r--model/utils_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/model/utils_test.go b/model/utils_test.go
index d35146b30..f004fc216 100644
--- a/model/utils_test.go
+++ b/model/utils_test.go
@@ -4,9 +4,11 @@
package model
import (
+ "fmt"
"net/http"
"strings"
"testing"
+ "time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -30,6 +32,39 @@ func TestRandomString(t *testing.T) {
}
}
+func TestGetMillisForTime(t *testing.T) {
+ thisTimeMillis := int64(1471219200000)
+ thisTime := time.Date(2016, time.August, 15, 0, 0, 0, 0, time.UTC)
+
+ result := GetMillisForTime(thisTime)
+
+ if thisTimeMillis != result {
+ t.Fatalf(fmt.Sprintf("millis are not the same: %d and %d", thisTimeMillis, result))
+ }
+}
+
+func TestParseDateFilterToTimeISO8601(t *testing.T) {
+ testString := "2016-08-01"
+ compareTime := time.Date(2016, time.August, 1, 0, 0, 0, 0, time.UTC)
+
+ result := ParseDateFilterToTime(testString)
+
+ if result != compareTime {
+ t.Fatalf(fmt.Sprintf("parsed date doesn't match the expected result: parsed result %v and expected time %v", result, compareTime))
+ }
+}
+
+func TestParseDateFilterToTimeNeedZeroPadding(t *testing.T) {
+ testString := "2016-8-1"
+ compareTime := time.Date(2016, time.August, 1, 0, 0, 0, 0, time.UTC)
+
+ result := ParseDateFilterToTime(testString)
+
+ if result != compareTime {
+ t.Fatalf(fmt.Sprintf("parsed date doesn't match the expected result: parsed result %v and expected time %v", result, compareTime))
+ }
+}
+
func TestAppError(t *testing.T) {
err := NewAppError("TestAppError", "message", nil, "", http.StatusInternalServerError)
json := err.ToJson()