summaryrefslogtreecommitdiffstats
path: root/model/access_test.go
blob: e385c0586e20661947a548bb393f3dca7ec1a621 (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
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.

package model

import (
	"strings"
	"testing"
)

func TestAccessJson(t *testing.T) {
	a1 := AccessData{}
	a1.AuthCode = NewId()
	a1.Token = NewId()
	a1.RefreshToken = NewId()

	json := a1.ToJson()
	ra1 := AccessDataFromJson(strings.NewReader(json))

	if a1.Token != ra1.Token {
		t.Fatal("tokens didn't match")
	}
}

func TestAccessIsValid(t *testing.T) {
	ad := AccessData{}

	if err := ad.IsValid(); err == nil {
		t.Fatal("should have failed")
	}

	ad.AuthCode = NewId()
	if err := ad.IsValid(); err == nil {
		t.Fatal("should have failed")
	}

	ad.Token = NewId()
	if err := ad.IsValid(); err != nil {
		t.Fatal(err)
	}
}