summaryrefslogtreecommitdiffstats
path: root/store/sql_recovery_store_test.go
blob: cf1048482fd3ce90d9b923bb902a3baecb03c30d (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package store

import (
	"github.com/mattermost/platform/model"
	"testing"
)

func TestSqlPasswordRecoveryGet(t *testing.T) {
	Setup()

	recovery := &model.PasswordRecovery{UserId: "12345678901234567890123456"}
	Must(store.PasswordRecovery().SaveOrUpdate(recovery))

	result := <-store.PasswordRecovery().Get(recovery.UserId)
	rrecovery := result.Data.(*model.PasswordRecovery)
	if rrecovery.Code != recovery.Code {
		t.Fatal("codes didn't match")
	}

	result2 := <-store.PasswordRecovery().GetByCode(recovery.Code)
	rrecovery2 := result2.Data.(*model.PasswordRecovery)
	if rrecovery2.Code != recovery.Code {
		t.Fatal("codes didn't match")
	}
}

func TestSqlPasswordRecoverySaveOrUpdate(t *testing.T) {
	Setup()

	recovery := &model.PasswordRecovery{UserId: "12345678901234567890123456"}

	if err := (<-store.PasswordRecovery().SaveOrUpdate(recovery)).Err; err != nil {
		t.Fatal(err)
	}

	// not duplicate, testing update
	if err := (<-store.PasswordRecovery().SaveOrUpdate(recovery)).Err; err != nil {
		t.Fatal(err)
	}
}

func TestSqlPasswordRecoveryDelete(t *testing.T) {
	Setup()

	recovery := &model.PasswordRecovery{UserId: "12345678901234567890123456"}
	Must(store.PasswordRecovery().SaveOrUpdate(recovery))

	if err := (<-store.PasswordRecovery().Delete(recovery.UserId)).Err; err != nil {
		t.Fatal(err)
	}
}