Skip to content

Commit ff18932

Browse files
author
David Revelo
committed
Add sign up test
1 parent 5022745 commit ff18932

6 files changed

Lines changed: 29 additions & 10 deletions

File tree

app/views/devise/mailer/confirmation_instructions.html.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22

33
<p><%= t '.confirm_link_msg' %> </p>
44

5-
<p><%= link_to t('.confirm_account_link'), confirmation_url(@resource, {confirmation_token: @token, config: message['client-config'].to_s, redirect_url: message['redirect-url']}).html_safe %></p>

lib/graphql_devise/rails/routes.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,22 @@ def mount_graphql_devise_for(resource, opts = {})
2020

2121
default_mutations = {
2222
login: GraphqlDevise::Mutations::Login,
23-
logout: GraphqlDevise::Mutations::Logout
23+
logout: GraphqlDevise::Mutations::Logout,
24+
signUp: GraphqlDevise::Mutations::SignUp
2425
}.freeze
2526

2627
default_mutations.each do |action, mutation|
2728
used_mutation = if mutation_options[action].present?
2829
mutation_options[action]
2930
else
3031
new_mutation = Class.new(mutation)
31-
new_mutation.graphql_name("#{resource}#{action.to_s.titleize}")
32+
new_mutation.graphql_name("#{resource}#{action.to_s.camelize(:upper)}")
3233
new_mutation.field(:authenticable, authenticable_type, null: true)
3334

3435
new_mutation
3536
end
3637

37-
GraphqlDevise::Types::MutationType.field("#{mapping_name}_#{action}", mutation: used_mutation)
38+
GraphqlDevise::Types::MutationType.field("#{mapping_name}_#{action.to_s.underscore}", mutation: used_mutation)
3839
end
3940

4041
devise_scope mapping_name.to_sym do
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Mutations
2+
class SignUp < GraphqlDevise::Mutations::SignUp
3+
field :user, Types::UserType, null: true
4+
5+
def resolve(email:, **attrs)
6+
original_payload = super
7+
original_payload.merge(user: original_payload[:authenticable])
8+
end
9+
end
10+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p><%= t(:welcome).capitalize + ' ' + @email %>!</p>
2+
3+
<p><%= t '.confirm_link_msg' %> </p>
4+

spec/dummy/config/routes.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Rails.application.routes.draw do
22
mount_graphql_devise_for 'User', at: 'api/v1', mutations: {
3-
login: Mutations::Login
3+
login: Mutations::Login,
4+
signUp: Mutations::SignUp
45
}
56
end

spec/requests/mutations/sign_up_spec.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
let(:query) do
1111
<<~GRAPHQL
1212
mutation {
13-
signUp(
13+
userSignUp(
1414
email: "#{email}"
1515
name: "#{name}"
1616
password: "#{password}"
@@ -19,7 +19,7 @@
1919
) {
2020
success
2121
errors
22-
authenticable {
22+
user {
2323
email
2424
name
2525
}
@@ -41,9 +41,13 @@
4141
expect(user).not_to be_active_for_authentication
4242
expect(user.confirmed_at).to be_nil
4343
expect(user.valid_password?(password)).to be_truthy
44-
expect(json_response.dig(:data, :signUp, :authenticable)).to include(
45-
email: email,
46-
name: name
44+
expect(json_response.dig(:data, :userSignUp)).to include(
45+
success: true,
46+
errors: [],
47+
user: {
48+
email: email,
49+
name: name
50+
}
4751
)
4852
end
4953
end

0 commit comments

Comments
 (0)