-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
test_helpers.ex
156 lines (132 loc) · 3.2 KB
/
test_helpers.ex
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
defmodule Grapevine.TestHelpers do
alias Grapevine.Accounts
alias Grapevine.Achievements
alias Grapevine.Applications
alias Grapevine.Authorizations
alias Grapevine.Channels
alias Grapevine.Games
alias Grapevine.Gauges
alias Grapevine.Repo
def create_channel(attributes \\ %{}) do
attributes =
Map.merge(
%{
name: "grapevine",
desription: "A channel"
},
attributes
)
{:ok, channel} = Channels.create(attributes)
channel
end
def create_user(attributes \\ %{}) do
{:ok, user} = Accounts.register(user_attributes(attributes))
user
end
def user_struct(attributes \\ %{}) do
struct(Accounts.User, user_attributes(attributes))
end
def user_attributes(attributes) do
Map.merge(
%{
username: "adminuser",
email: "admin@example.com",
password: "password",
password_confirmation: "password"
},
attributes
)
end
def create_game(user, attributes \\ %{}) do
{:ok, game} = Games.register(user, game_attributes(attributes))
{:ok, game} =
game
|> Ecto.Changeset.change()
|> Ecto.Changeset.put_change(:cover_key, UUID.uuid4())
|> Ecto.Changeset.put_change(:cover_extension, ".png")
|> Repo.update()
game
end
def game_struct(attributes \\ %{}) do
struct(Games.Game, game_attributes(attributes))
end
def game_attributes(attributes) do
Map.merge(
%{
name: "A MUD",
short_name: "AM"
},
attributes
)
end
def create_connection(game, attributes \\ %{}) do
attributes =
Map.merge(
%{
type: "telnet",
host: "localhost",
port: "5555"
},
attributes
)
{:ok, connection} = Games.create_connection(game, attributes)
connection
end
def create_application(attributes \\ %{}) do
attributes =
Map.merge(
%{
name: "Grapevine",
short_name: "Grapevine"
},
attributes
)
{:ok, application} = Applications.create(attributes)
application
end
def presence_state(game, state) do
Map.merge(
%{
game: game,
supports: [],
channels: [],
players: []
},
state
)
end
def create_achievement(game, attributes \\ %{}) do
attributes =
Map.merge(
%{
"title" => "Adventuring",
"description" => "You made it to level 2!",
"points" => 10
},
attributes
)
{:ok, achievement} = Achievements.create(game, attributes)
achievement
end
def create_authorization(user, game) do
{:ok, authorization} = Authorizations.start_auth(user, game, %{
"state" => "my+state",
"redirect_uri" => "https://example.com/oauth/callback",
"scope" => "profile"
})
{:ok, authorization} = Authorizations.authorize(authorization)
authorization
end
def create_gauge(game, attributes) do
attributes = Map.merge(%{
name: "HP",
package: "Char 1",
message: "Char.Vitals",
value: "hp",
max: "maxhp",
color: "red"
}, attributes)
{:ok, gauge} = Gauges.create(game, attributes)
gauge
end
end