chore(user-emails): use random email in tests

This commit is contained in:
Alessandro Magionami
2024-07-05 11:26:46 +02:00
parent cf269f5cb0
commit 0c5276fd39
@@ -4,6 +4,11 @@ import { beforeEachContext } from '@/test/hooks'
import { expect } from 'chai'
import { getUserByEmail } from '../../repositories/users'
import { UserRecord } from '../../helpers/types'
import crs from 'crypto-random-string'
function createRandomEmail() {
return `${crs({ length: 6 })}@example.org`
}
describe('Core @user-emails', () => {
before(async () => {
@@ -15,27 +20,29 @@ describe('Core @user-emails', () => {
})
it('should return user if user-email does not exist', async () => {
const email = createRandomEmail()
await createUser({
name: 'John Doe',
email: 'test@example.org',
email,
password: 'sn3aky-1337-b1m'
})
const user = (await getUserByEmail('test@example.org')) as UserRecord
expect(user.name).to.eq('John Doe')
expect(user.email).to.eq('test@example.org')
expect(user.email).to.eq(email)
})
it('should return user merged with user-email', async () => {
const email = createRandomEmail()
await createUser({
name: 'John Doe',
email: 'test1@example.org',
email,
password: 'sn3aky-1337-b1m'
})
const user = (await getUserByEmail('test@example.org')) as UserRecord
const user = (await getUserByEmail(email)) as UserRecord
expect(user.name).to.eq('John Doe')
expect(user.email).to.eq('test@example.org')
expect(user.email).to.eq(email)
})
})
})