summaryrefslogtreecommitdiffstats
path: root/model/search_params_test.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2018-10-05 22:25:34 +0800
committerGitHub <noreply@github.com>2018-10-05 22:25:34 +0800
commit69e10651c97c7d7b30aa69a0155c8d3293e2b9bd (patch)
tree5f430cdb9c9226d622ad393f6fdbf8c7d30ae9fe /model/search_params_test.go
parentcba33137d25336cd5a5bcfd1d68695b584714f56 (diff)
downloadchat-69e10651c97c7d7b30aa69a0155c8d3293e2b9bd.tar.gz
chat-69e10651c97c7d7b30aa69a0155c8d3293e2b9bd.tar.bz2
chat-69e10651c97c7d7b30aa69a0155c8d3293e2b9bd.zip
[MM-12484] Fix return search posts on date filters (#9568)
* fix return search posts on date filters * add name to test cases
Diffstat (limited to 'model/search_params_test.go')
-rw-r--r--model/search_params_test.go114
1 files changed, 114 insertions, 0 deletions
diff --git a/model/search_params_test.go b/model/search_params_test.go
index 49480352e..297ca2a45 100644
--- a/model/search_params_test.go
+++ b/model/search_params_test.go
@@ -5,6 +5,9 @@ package model
import (
"testing"
+ "time"
+
+ "github.com/stretchr/testify/assert"
)
func TestSplitWords(t *testing.T) {
@@ -301,3 +304,114 @@ func TestParseSearchParams(t *testing.T) {
t.Fatalf("Incorrect output from parse search params: %v", sp)
}
}
+
+func TestGetOnDateMillis(t *testing.T) {
+ for _, testCase := range []struct {
+ Name string
+ Input string
+ StartOnDate int64
+ EndOnDate int64
+ }{
+ {
+ Name: "Valid date",
+ Input: "2018-08-01",
+ StartOnDate: 1533081600000,
+ EndOnDate: 1533167999999,
+ },
+ {
+ Name: "Valid date but requires padding of zero",
+ Input: "2018-8-1",
+ StartOnDate: 1533081600000,
+ EndOnDate: 1533167999999,
+ },
+ {
+ Name: "Invalid date, date not exist",
+ Input: "2018-02-29",
+ StartOnDate: 0,
+ EndOnDate: 0,
+ },
+ {
+ Name: "Invalid date, not date format",
+ Input: "holiday",
+ StartOnDate: 0,
+ EndOnDate: 0,
+ },
+ } {
+ t.Run(testCase.Name, func(t *testing.T) {
+ sp := &SearchParams{OnDate: testCase.Input, TimeZoneOffset: 0}
+ startOnDate, endOnDate := sp.GetOnDateMillis()
+ assert.Equal(t, testCase.StartOnDate, startOnDate)
+ assert.Equal(t, testCase.EndOnDate, endOnDate)
+ })
+ }
+}
+
+func TestGetBeforeDateMillis(t *testing.T) {
+ for _, testCase := range []struct {
+ Name string
+ Input string
+ BeforeDate int64
+ }{
+ {
+ Name: "Valid date",
+ Input: "2018-08-01",
+ BeforeDate: 1533081599999,
+ },
+ {
+ Name: "Valid date but requires padding of zero",
+ Input: "2018-8-1",
+ BeforeDate: 1533081599999,
+ },
+ {
+ Name: "Invalid date, date not exist",
+ Input: "2018-02-29",
+ BeforeDate: 0,
+ },
+ {
+ Name: "Invalid date, not date format",
+ Input: "holiday",
+ BeforeDate: 0,
+ },
+ } {
+ t.Run(testCase.Name, func(t *testing.T) {
+ sp := &SearchParams{BeforeDate: testCase.Input, TimeZoneOffset: 0}
+ beforeDate := sp.GetBeforeDateMillis()
+ assert.Equal(t, testCase.BeforeDate, beforeDate)
+ })
+ }
+}
+
+func TestGetAfterDateMillis(t *testing.T) {
+ for _, testCase := range []struct {
+ Name string
+ Input string
+ AfterDate int64
+ }{
+ {
+ Name: "Valid date",
+ Input: "2018-08-01",
+ AfterDate: 1533168000000,
+ },
+ {
+ Name: "Valid date but requires padding of zero",
+ Input: "2018-8-1",
+ AfterDate: 1533168000000,
+ },
+ {
+ Name: "Invalid date, date not exist",
+ Input: "2018-02-29",
+ AfterDate: GetStartOfDayMillis(time.Now().Add(time.Hour*24), 0),
+ },
+ {
+ Name: "Invalid date, not date format",
+ Input: "holiday",
+ AfterDate: GetStartOfDayMillis(time.Now().Add(time.Hour*24), 0),
+ },
+ } {
+ t.Run(testCase.Name, func(t *testing.T) {
+ sp := &SearchParams{AfterDate: testCase.Input, TimeZoneOffset: 0}
+ afterDate := sp.GetAfterDateMillis()
+ assert.Equal(t, testCase.AfterDate, afterDate)
+ })
+ }
+}