Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock transactionentity manager with jest #6546

Closed
rubiin opened this issue Aug 11, 2020 · 1 comment
Closed

Mock transactionentity manager with jest #6546

rubiin opened this issue Aug 11, 2020 · 1 comment

Comments

@rubiin
Copy link

rubiin commented Aug 11, 2020

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[x] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

	await getManager().transaction(async transactionalEntityManager => {
				const userId = await transactionalEntityManager
					.getRepository(UserType)
					.save({
						user_type: dto.user_type,
						description: dto.description,
						created_by: userRequesting.idx,
					});

				const incomingPermissions = await getManager()
					.getRepository(Permission)
					.find({
						where: { idx: In(dto.permission) },
						select: ['id', 'base_name'],
					});

				console.log('incoming ', incomingPermissions);

				const permissionBulkAdd = [];

				for (const element of incomingPermissions) {
					const permission = new PermissionUserType();
					permission.idx = element.idx;
					permission.userType = userId;
					permission.base_name = element.base_name;
					permission.permission = element;
					permissionBulkAdd.push(permission);
				}

				await transactionalEntityManager
					.getRepository(PermissionUserType)
					.save(permissionBulkAdd);
			});
			return { statusCode: 200, message: 'User type Added' };
		}

I have to mock transactionentity manager but do not know how to for this snippet. I am using jest for testing

@imnotjames
Copy link
Contributor

We're tracking documentation issues for this in #5308


For questions, please check out the community slack or check TypeORM's documentation page on other support avenues - cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants