Skip to content

Commit

Permalink
fix: Greater test data cleanup timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Oct 23, 2023
1 parent 6cc76b1 commit 8dcea6d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ interface OrganizationRepository : JpaRepository<Organization, Long> {
"""
select o
from Organization o
left join fetch o.basePermission bp
left join o.memberRoles mr on mr.user.id = :userId
left join o.projects p
left join p.permissions perm on perm.user.id = :userId
where (perm is not null or mr is not null) and o.id <> :exceptOrganizationId
group by mr.id, o.id
group by mr.id, o.id, bp.id
order by mr.id asc nulls last
"""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,12 @@ interface UserAccountRepository : JpaRepository<UserAccount, Long> {
"""
)
fun findDisabled(id: Long): UserAccount

@Query("""
from UserAccount ua
left join fetch ua.emailVerification
left join fetch ua.permissions
where ua.id = :id
""")
fun findWithFetchedEmailVerificationAndPermissions(id: Long): UserAccount?
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,31 +140,35 @@ class UserAccountService(
@Transactional
fun delete(userAccount: UserAccount) {
traceLogMeasureTime("deleteUser") {
userAccount.emailVerification?.let {
val toDelete =
userAccountRepository.findWithFetchedEmailVerificationAndPermissions(userAccount.id)
?: throw NotFoundException()

toDelete.emailVerification?.let {
entityManager.remove(it)
}
userAccount.apiKeys?.forEach {
toDelete.apiKeys?.forEach {
entityManager.remove(it)
}
userAccount.pats?.forEach {
toDelete.pats?.forEach {
entityManager.remove(it)
}
userAccount.permissions.forEach {
toDelete.permissions.forEach {
entityManager.remove(it)
}
userAccount.preferences?.let {
toDelete.preferences?.let {
entityManager.remove(it)
}
organizationService.getAllSingleOwnedByUser(userAccount).forEach {
organizationService.getAllSingleOwnedByUser(toDelete).forEach {
it.preferredBy.removeIf { preferences ->
preferences.userAccount.id == userAccount.id
}
organizationService.delete(it)
}
userAccount.organizationRoles.forEach {
toDelete.organizationRoles.forEach {
entityManager.remove(it)
}
userAccountRepository.softDeleteUser(userAccount, currentDateProvider.date)
userAccountRepository.softDeleteUser(toDelete, currentDateProvider.date)
applicationEventPublisher.publishEvent(OnUserCountChanged(this))
}
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/common/apiCalls/testData/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const cleanTestData = (
options?: ArgumentTypes<typeof cy.request>[0]
) => {
return internalFetch(`e2e-data/${resource}/clean`, {
timeout: 20000,
timeout: 40000,
...options,
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Organization Invitations', () => {
visit();
});

it.only('generates invitations', () => {
it('generates invitations', () => {
generateInvitation('MEMBER').should('contain', 'http://');

generateInvitation('OWNER');
Expand Down
4 changes: 0 additions & 4 deletions e2e/cypress/e2e/organizations/organizationsMembers.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ describe('Organization Members', () => {
.should('be.visible');
});

after(() => {
organizationTestData.clean();
});

const visit = () => {
cy.visit(`${HOST}/organizations/tolgee/members`);
};
Expand Down

0 comments on commit 8dcea6d

Please sign in to comment.