diff options
author | George Goldberg <george@gberg.me> | 2017-04-20 14:58:54 +0100 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-04-20 09:58:54 -0400 |
commit | 55bbf15fc7a83d3cda1fe5bc037823cbbc4fc023 (patch) | |
tree | 312f6a9c42c8f153168df8f960b613666777f64a /model/password_recovery_test.go | |
parent | 8723f61f4540c74d5c755d7f9532f8fe199ccb6f (diff) | |
download | chat-55bbf15fc7a83d3cda1fe5bc037823cbbc4fc023.tar.gz chat-55bbf15fc7a83d3cda1fe5bc037823cbbc4fc023.tar.bz2 chat-55bbf15fc7a83d3cda1fe5bc037823cbbc4fc023.zip |
PLT-6112: Add some more unit tests to the model package (#6142)
* Unit Tests for model/push_response.go
* Unit tests for security_bulletin.go
* Unit tests for webrtc.go
* Unit tests for model/password_recovery.go
* Add missing headers.
* Unit tests for model/license.go
* Tidy up existing tests.
* Simplify JSON to/from tests.
* Fix gofmt
Diffstat (limited to 'model/password_recovery_test.go')
-rw-r--r-- | model/password_recovery_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/model/password_recovery_test.go b/model/password_recovery_test.go new file mode 100644 index 000000000..d64f430fc --- /dev/null +++ b/model/password_recovery_test.go @@ -0,0 +1,53 @@ +// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "strings" + "testing" +) + +func TestPasswordRecoveryIsValid(t *testing.T) { + // Valid example. + p := PasswordRecovery{ + UserId: NewId(), + Code: strings.Repeat("a", 128), + CreateAt: GetMillis(), + } + + if err := p.IsValid(); err != nil { + t.Fatal(err) + } + + // Various invalid ones. + p.UserId = "abc" + if err := p.IsValid(); err == nil { + t.Fatal("Should have failed validation") + } + + p.UserId = NewId() + p.Code = "abc" + if err := p.IsValid(); err == nil { + t.Fatal("Should have failed validation") + } + + p.Code = strings.Repeat("a", 128) + p.CreateAt = 0 + if err := p.IsValid(); err == nil { + t.Fatal("Should have failed validation") + } +} + +func TestPasswordRecoveryPreSave(t *testing.T) { + p := PasswordRecovery{ + UserId: NewId(), + } + + // Check it's valid after running PreSave + p.PreSave() + + if err := p.IsValid(); err != nil { + t.Fatal(err) + } +} |