Passed
Pull Request — main (#166)
by Yume
02:09
created

domain/oauth_test.go   A

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 62
dl 0
loc 103
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B domain_test.TestDiscordLogin_ToUser 0 46 8
B domain_test.TestGithubLogin_ToUser 0 46 8
1
package domain_test
2
3
import (
4
	"testing"
5
6
	"github.com/memnix/memnix-rest/domain"
7
)
8
9
func TestGithubLogin_ToUser(t *testing.T) {
10
	githubLogin := &domain.GithubLogin{
11
		Login:     "testuser",
12
		Email:     "[email protected]",
13
		AvatarURL: "https://example.com/avatar.png",
14
		ID:        123,
15
	}
16
17
	expected := domain.User{
18
		Username:      "testuser",
19
		Email:         "[email protected]",
20
		Permission:    domain.PermissionUser,
21
		Avatar:        "https://example.com/avatar.png",
22
		Oauth:         true,
23
		OauthProvider: "github",
24
		OauthID:       "123",
25
	}
26
27
	user := githubLogin.ToUser()
28
29
	if user.Username != expected.Username {
30
		t.Errorf("Expected username to be %s, but got %s", expected.Username, user.Username)
31
	}
32
33
	if user.Email != expected.Email {
34
		t.Errorf("Expected email to be %s, but got %s", expected.Email, user.Email)
35
	}
36
37
	if user.Permission != expected.Permission {
38
		t.Errorf("Expected permission to be %s, but got %s", expected.Permission, user.Permission)
39
	}
40
41
	if user.Avatar != expected.Avatar {
42
		t.Errorf("Expected avatar to be %s, but got %s", expected.Avatar, user.Avatar)
43
	}
44
45
	if user.Oauth != expected.Oauth {
46
		t.Errorf("Expected oauth to be %v, but got %v", expected.Oauth, user.Oauth)
47
	}
48
49
	if user.OauthProvider != expected.OauthProvider {
50
		t.Errorf("Expected oauth provider to be %s, but got %s", expected.OauthProvider, user.OauthProvider)
51
	}
52
53
	if user.OauthID != expected.OauthID {
54
		t.Errorf("Expected oauth ID to be %s, but got %s", expected.OauthID, user.OauthID)
55
	}
56
}
57
58
func TestDiscordLogin_ToUser(t *testing.T) {
59
	discordLogin := &domain.DiscordLogin{
60
		Username: "testuser",
61
		Email:    "[email protected]",
62
		ID:       "123",
63
		Avatar:   "avatar123",
64
	}
65
66
	expected := domain.User{
67
		Username:      "testuser",
68
		Email:         "[email protected]",
69
		Permission:    domain.PermissionUser,
70
		Avatar:        "https://cdn.discordapp.com/avatars/123/avatar123.png",
71
		Oauth:         true,
72
		OauthProvider: "discord",
73
		OauthID:       "123",
74
	}
75
76
	user := discordLogin.ToUser()
77
78
	if user.Username != expected.Username {
79
		t.Errorf("Expected username to be %s, but got %s", expected.Username, user.Username)
80
	}
81
82
	if user.Email != expected.Email {
83
		t.Errorf("Expected email to be %s, but got %s", expected.Email, user.Email)
84
	}
85
86
	if user.Permission != expected.Permission {
87
		t.Errorf("Expected permission to be %s, but got %s", expected.Permission, user.Permission)
88
	}
89
90
	if user.Avatar != expected.Avatar {
91
		t.Errorf("Expected avatar to be %s, but got %s", expected.Avatar, user.Avatar)
92
	}
93
94
	if user.Oauth != expected.Oauth {
95
		t.Errorf("Expected oauth to be %v, but got %v", expected.Oauth, user.Oauth)
96
	}
97
98
	if user.OauthProvider != expected.OauthProvider {
99
		t.Errorf("Expected oauth provider to be %s, but got %s", expected.OauthProvider, user.OauthProvider)
100
	}
101
102
	if user.OauthID != expected.OauthID {
103
		t.Errorf("Expected oauth ID to be %s, but got %s", expected.OauthID, user.OauthID)
104
	}
105
}
106