summaryrefslogtreecommitdiffstats
path: root/model/session_test.go
blob: 295f00076e080571222551504dc15f77450bc16d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package model

import (
	"strings"
	"testing"
	"time"
)

func TestSessionJson(t *testing.T) {
	session := Session{}
	session.PreSave()
	json := session.ToJson()
	rsession := SessionFromJson(strings.NewReader(json))

	if rsession.Id != session.Id {
		t.Fatal("Ids do not match")
	}

	session.Sanitize()

	if session.IsExpired() {
		t.Fatal("Shouldn't expire")
	}

	session.ExpiresAt = GetMillis()
	time.Sleep(10 * time.Millisecond)
	if !session.IsExpired() {
		t.Fatal("Should expire")
	}

	session.SetExpireInDays(10)
}