File tree Expand file tree Collapse file tree 2 files changed +85
-0
lines changed
flix_web/graphql/schemas/mutations Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Original file line number Diff line number Diff line change 1+ defmodule FlixWeb.GraphQL.Schemas.Mutations.AccountsTest do
2+ use FlixWeb.ConnCase , async: true
3+
4+ import Flix.Support.Factory
5+
6+ alias Flix.Accounts
7+
8+ describe "new session with valid arguments" do
9+ test "create session" do
10+ user_params = build ( :user )
11+
12+ { :ok , user } = Accounts . register_user ( user_params )
13+
14+ operation = """
15+ mutation Signin($email: String!) {
16+ signin(
17+ email: $email,
18+ password: "1qaz2wsx3edc"
19+ )
20+ {
21+ token
22+ user {
23+ id
24+ email
25+ }
26+ }
27+ }
28+ """
29+
30+ response =
31+ post (
32+ build_conn ( ) ,
33+ "/api" ,
34+ query: operation ,
35+ variables: % { "email" => user . email }
36+ )
37+
38+ assert % {
39+ "data" => % {
40+ "signin" => % {
41+ "token" => token ,
42+ "user" => _user_data
43+ }
44+ }
45+ } = json_response ( response , 200 )
46+
47+ assert { :ok , % { id: user . id } } == FlixWeb.AuthToken . verify ( token )
48+ end
49+ end
50+ end
Original file line number Diff line number Diff line change 1+ defmodule Flix.Support.Factory do
2+ use ExMachina.Ecto , repo: Flix.Repo
3+
4+ alias Flix.Accounts
5+ alias Flix.Accounts.User
6+ alias Flix.Accounts.UserToken
7+
8+ def user_factory do
9+ % {
10+ name: sequence ( :name , & "User #{ & 1 } " ) ,
11+ email: sequence ( :email , & "email#{ & 1 } @example.com" ) ,
12+ password: "1qaz2wsx3edc" ,
13+ username: sequence ( :username , & "username#{ & 1 } " ) ,
14+ admin: false
15+ }
16+
17+ # {:ok, user} = Accounts.register_user(params)
18+
19+ # Ecto.Multi.new()
20+ # |> Ecto.Multi.update(:user, User.confirm_changeset(user))
21+ # |> Ecto.Multi.delete_all(:tokens, UserToken.user_and_contexts_query(user, ["confirm"]))
22+
23+ # user
24+ end
25+
26+ # derived factory
27+ def admin_user_factory do
28+ struct! (
29+ user_factory ( ) ,
30+ % {
31+ admin: true
32+ }
33+ )
34+ end
35+ end
You can’t perform that action at this time.
0 commit comments