Fix concurrency issue in TeamService.test.ts

This commit is contained in:
Jerko Steiner 2019-09-14 10:30:44 +07:00
parent d532ac82f0
commit 1fde923dbf
2 changed files with 8 additions and 4 deletions

View File

@ -78,7 +78,7 @@ describe('team', () => {
const client = getClient() const client = getClient()
const team = await client.create({name: 'test'}) const team = await client.create({name: 'test'})
const teamId = team.id const teamId = team.id
const {userId} = await test.registerAccount('test2@user.com') const {userId} = await test.registerAccount(test.createTestUsername(2))
await client.addUser({userId, teamId, roleId: 1}) await client.addUser({userId, teamId, roleId: 1})
}) })
}) })
@ -88,7 +88,7 @@ describe('team', () => {
const client = getClient() const client = getClient()
const team = await client.create({name: 'test'}) const team = await client.create({name: 'test'})
const teamId = team.id const teamId = team.id
const {userId} = await test.registerAccount('test2@user.com') const {userId} = await test.registerAccount(test.createTestUsername(2))
await client.addUser({userId, teamId, roleId: 1}) await client.addUser({userId, teamId, roleId: 1})
await client.removeUser({userId, teamId, roleId: 1}) await client.removeUser({userId, teamId, roleId: 1})
}) })
@ -99,7 +99,7 @@ describe('team', () => {
const client = getClient() const client = getClient()
const team = await client.create({name: 'test'}) const team = await client.create({name: 'test'})
const teamId = team.id const teamId = team.id
const {userId} = await test.registerAccount('test2@user.com') const {userId} = await test.registerAccount(test.createTestUsername(2))
await client.addUser({userId, teamId, roleId: 1}) await client.addUser({userId, teamId, roleId: 1})
const {usersInTeam} = await client.findUsers(teamId) const {usersInTeam} = await client.findUsers(teamId)
expect(usersInTeam.length).toBe(2) expect(usersInTeam.length).toBe(2)

View File

@ -16,7 +16,7 @@ import {Server} from 'http'
import { IAppServer } from '../application/IAppServer' import { IAppServer } from '../application/IAppServer'
export class TestUtils<T extends IRoutes> { export class TestUtils<T extends IRoutes> {
readonly username = `test${process.env.JEST_WORKER_ID}@user.com` readonly username = this.createTestUsername()
readonly password = 'Password10' readonly password = 'Password10'
readonly app: IAppServer readonly app: IAppServer
@ -29,6 +29,10 @@ export class TestUtils<T extends IRoutes> {
this.transactionManager = this.bootstrap.database.transactionManager this.transactionManager = this.bootstrap.database.transactionManager
} }
createTestUsername(id = 1) {
return `test${process.env.JEST_WORKER_ID}_${id}@user.com`
}
/** /**
* Set up beforeEach and afterEach cases for jest tests. Helps create and * Set up beforeEach and afterEach cases for jest tests. Helps create and
* execute the tests in transaction, and rolls it back in the end. * execute the tests in transaction, and rolls it back in the end.