Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ describe('ParseGraphQLServer', () => {
user1 = new Parse.User();
user1.setUsername('user1');
user1.setPassword('user1');
user1.setEmail('[email protected]');
await user1.signUp();

user2 = new Parse.User();
Expand Down Expand Up @@ -7149,6 +7150,89 @@ describe('ParseGraphQLServer', () => {
});
}
});

it('should send reset password', async () => {
const clientMutationId = uuidv4();
const emailAdapter = {
sendVerificationEmail: () => {},
sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => {},
};
parseServer = await global.reconfigureServer({
appName: 'test',
emailAdapter: emailAdapter,
publicServerURL: 'http://test.test',
});
const user = new Parse.User();
user.setUsername('user1');
user.setPassword('user1');
user.setEmail('[email protected]');
await user.signUp();
await Parse.User.logOut();
const result = await apolloClient.mutate({
mutation: gql`
mutation ResetPassword($input: ResetPasswordInput!) {
resetPassword(input: $input) {
clientMutationId
ok
}
}
`,
variables: {
input: {
clientMutationId,
email: '[email protected]',
},
},
});

expect(result.data.resetPassword.clientMutationId).toEqual(
clientMutationId
);
expect(result.data.resetPassword.ok).toBeTruthy();
});
it('should send verification email again', async () => {
const clientMutationId = uuidv4();
const emailAdapter = {
sendVerificationEmail: () => {},
sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => {},
};
parseServer = await global.reconfigureServer({
appName: 'test',
emailAdapter: emailAdapter,
publicServerURL: 'http://test.test',
});
const user = new Parse.User();
user.setUsername('user1');
user.setPassword('user1');
user.setEmail('[email protected]');
await user.signUp();
await Parse.User.logOut();
const result = await apolloClient.mutate({
mutation: gql`
mutation SendVerificationEmail(
$input: SendVerificationEmailInput!
) {
sendVerificationEmail(input: $input) {
clientMutationId
ok
}
}
`,
variables: {
input: {
clientMutationId,
email: '[email protected]',
},
},
});

expect(result.data.sendVerificationEmail.clientMutationId).toEqual(
clientMutationId
);
expect(result.data.sendVerificationEmail.ok).toBeTruthy();
});
});

describe('Session Token', () => {
Expand Down
123 changes: 112 additions & 11 deletions src/GraphQL/loaders/usersMutations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GraphQLNonNull, GraphQLString } from 'graphql';
import { GraphQLNonNull, GraphQLString, GraphQLBoolean } from 'graphql';
import { mutationWithClientMutationId } from 'graphql-relay';
import UsersRouter from '../../Routers/UsersRouter';
import * as objectsMutations from '../helpers/objectsMutations';
Expand Down Expand Up @@ -93,16 +93,18 @@ const load = parseGraphQLSchema => {
const { username, password } = args;
const { config, auth, info } = context;

const { sessionToken } = (await usersRouter.handleLogIn({
body: {
username,
password,
},
query: {},
config,
auth,
info,
})).response;
const { sessionToken } = (
await usersRouter.handleLogIn({
body: {
username,
password,
},
query: {},
config,
auth,
info,
})
).response;

info.sessionToken = sessionToken;

Expand Down Expand Up @@ -171,6 +173,105 @@ const load = parseGraphQLSchema => {
);
parseGraphQLSchema.addGraphQLType(logOutMutation.type, true, true);
parseGraphQLSchema.addGraphQLMutation('logOut', logOutMutation, true, true);

const resetPasswordMutation = mutationWithClientMutationId({
name: 'ResetPassword',
description:
'The resetPassword mutation can be used to reset the password of an existing user.',
inputFields: {
email: {
descriptions: 'Email of the user that should receive the reset email',
type: new GraphQLNonNull(GraphQLString),
},
},
outputFields: {
ok: {
description: "It's always true.",
type: new GraphQLNonNull(GraphQLBoolean),
},
},
mutateAndGetPayload: async ({ email }, context) => {
const { config, auth, info } = context;

await usersRouter.handleResetRequest({
body: {
email,
},
config,
auth,
info,
});

return { ok: true };
},
});

parseGraphQLSchema.addGraphQLType(
resetPasswordMutation.args.input.type.ofType,
true,
true
);
parseGraphQLSchema.addGraphQLType(resetPasswordMutation.type, true, true);
parseGraphQLSchema.addGraphQLMutation(
'resetPassword',
resetPasswordMutation,
true,
true
);

const sendVerificationEmailMutation = mutationWithClientMutationId({
name: 'SendVerificationEmail',
description:
'The sendVerificationEmail mutation can be used to send the verification email again.',
inputFields: {
email: {
descriptions:
'Email of the user that should receive the verification email',
type: new GraphQLNonNull(GraphQLString),
},
},
outputFields: {
ok: {
description: "It's always true.",
type: new GraphQLNonNull(GraphQLBoolean),
},
},
mutateAndGetPayload: async ({ email }, context) => {
try {
const { config, auth, info } = context;

await usersRouter.handleVerificationEmailRequest({
body: {
email,
},
config,
auth,
info,
});

return { ok: true };
} catch (e) {
parseGraphQLSchema.handleError(e);
}
},
});

parseGraphQLSchema.addGraphQLType(
sendVerificationEmailMutation.args.input.type.ofType,
true,
true
);
parseGraphQLSchema.addGraphQLType(
sendVerificationEmailMutation.type,
true,
true
);
parseGraphQLSchema.addGraphQLMutation(
'sendVerificationEmail',
sendVerificationEmailMutation,
true,
true
);
};

export { load };