I have a problem while performing functional tests on nest app. Testing app is builded with nest Test.createTestingModule.
describe('createResetPasswordToken', () => {
it('should create reset password token based on provided data', async () => {
const user = await createTestUser({ app: app(), data: { email: '[email protected]' } });
const data: ResetPasswordTokenDto = {
userId: user.id,
token: 'some-token',
tokenExpiry: add(new Date(), {
minutes: resetPasswordConsts.RESET_PASSWORD_TOKEN_EXPIRY_TIME_IN_MINUTES,
}),
};
const resetPasswordToken = await resetPasswordService.createResetPasswordToken(data);
expect(resetPasswordToken).toMatchObject(data);
}, 300000);
});
Error:
Foreign key constraint failed on the field: ResetPasswordToken_userId_fkey (index)
It seems like user data is not available in database when I try to create resetPasswordToken with userId foreign key, despite the fact that there are awaits and const user is returned.
Adding short timeout between creating user and token fixes this issue, but it's not long term solution. Test works fine in github actions and while debuging.