_ap857_
10/18/2023, 3:26 AM@Mutation(() => AdminUser)
@UseGuards(new AuthGuard())
async addAdminUser(
@Args('registrationInput') registrationInput: RegistrationInput,
) {
const { email, password, role } = registrationInput;
const response = await EmailPassword.signUp('public', email, password);
if (response.status === 'EMAIL_ALREADY_EXISTS_ERROR') {
LoggerService.logger.error('Email already exists');
throw new BadRequestException('Email already exists');
}
if (response.status === 'OK') {
// do more additional work, for example:
// userService.setUserStatus(response.user.id, role);
}
}
Following is my testing code. When I run the test I get following error “Initialisation not done. Did you forget to call the SuperTokens.init function?” .
To resolve this I have to call following code, where http://localhost:3567 is the supertokens core URI. Which means I need to have running docker container for this unit test, which I want to avoid?
beforeEach(async () => {
supertokens.init({
supertokens: {
connectionURI: 'http://localhost:3567',
},
appInfo: {
apiDomain: 'api.supertokens.io',
appName: 'SuperTokens',
websiteDomain: 'supertokens.io',
},
recipeList: [EmailPassword.init()],
});
});
it(‘when user with email is already exists’ , async () => {
jest.mock('supertokens-node/recipe/emailpassword', () => {
return {
EmailPassword: {
signUp: jest
.fn()
.mockReturnValueOnce({ status: 'EMAIL_ALREADY_EXISTS_ERROR' }),
},
};
});
await registrationResolver.addAdminUser({
email: ’sample@email.com’,
role: AdminRole.ADMIN,
} as RegistrationInput);
});