Reset and Send verification email (#6301)
This commit is contained in:
committed by
Antonio Davi Macedo Coelho de Castro
parent
55c51c3e7d
commit
576631f09e
@@ -285,6 +285,7 @@ describe('ParseGraphQLServer', () => {
|
|||||||
user1 = new Parse.User();
|
user1 = new Parse.User();
|
||||||
user1.setUsername('user1');
|
user1.setUsername('user1');
|
||||||
user1.setPassword('user1');
|
user1.setPassword('user1');
|
||||||
|
user1.setEmail('user1@user1.user1');
|
||||||
await user1.signUp();
|
await user1.signUp();
|
||||||
|
|
||||||
user2 = new Parse.User();
|
user2 = new Parse.User();
|
||||||
@@ -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('user1@user1.user1');
|
||||||
|
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: 'user1@user1.user1',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
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('user1@user1.user1');
|
||||||
|
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: 'user1@user1.user1',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.data.sendVerificationEmail.clientMutationId).toEqual(
|
||||||
|
clientMutationId
|
||||||
|
);
|
||||||
|
expect(result.data.sendVerificationEmail.ok).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Session Token', () => {
|
describe('Session Token', () => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
import { GraphQLNonNull, GraphQLString, GraphQLBoolean } from 'graphql';
|
||||||
import { mutationWithClientMutationId } from 'graphql-relay';
|
import { mutationWithClientMutationId } from 'graphql-relay';
|
||||||
import UsersRouter from '../../Routers/UsersRouter';
|
import UsersRouter from '../../Routers/UsersRouter';
|
||||||
import * as objectsMutations from '../helpers/objectsMutations';
|
import * as objectsMutations from '../helpers/objectsMutations';
|
||||||
@@ -93,16 +93,18 @@ const load = parseGraphQLSchema => {
|
|||||||
const { username, password } = args;
|
const { username, password } = args;
|
||||||
const { config, auth, info } = context;
|
const { config, auth, info } = context;
|
||||||
|
|
||||||
const { sessionToken } = (await usersRouter.handleLogIn({
|
const { sessionToken } = (
|
||||||
body: {
|
await usersRouter.handleLogIn({
|
||||||
username,
|
body: {
|
||||||
password,
|
username,
|
||||||
},
|
password,
|
||||||
query: {},
|
},
|
||||||
config,
|
query: {},
|
||||||
auth,
|
config,
|
||||||
info,
|
auth,
|
||||||
})).response;
|
info,
|
||||||
|
})
|
||||||
|
).response;
|
||||||
|
|
||||||
info.sessionToken = sessionToken;
|
info.sessionToken = sessionToken;
|
||||||
|
|
||||||
@@ -171,6 +173,105 @@ const load = parseGraphQLSchema => {
|
|||||||
);
|
);
|
||||||
parseGraphQLSchema.addGraphQLType(logOutMutation.type, true, true);
|
parseGraphQLSchema.addGraphQLType(logOutMutation.type, true, true);
|
||||||
parseGraphQLSchema.addGraphQLMutation('logOut', logOutMutation, 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 };
|
export { load };
|
||||||
|
|||||||
Reference in New Issue
Block a user