mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
[PM-22974] Cascade delete NotificationStatus entities (#6011)
* cascade delete NotificationStatus entities * add userId to test for foreign constraint * add missing properties for Notification * add check for foreign key
This commit is contained in:
@ -5,6 +5,8 @@ using Bit.Core.Billing.Enums;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.NotificationCenter.Entities;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Vault.Entities;
|
||||
using Bit.Core.Vault.Enums;
|
||||
@ -976,8 +978,11 @@ public class CipherRepositoryTests
|
||||
[DatabaseTheory, DatabaseData]
|
||||
public async Task DeleteCipherWithSecurityTaskAsync_Works(
|
||||
IOrganizationRepository organizationRepository,
|
||||
IUserRepository userRepository,
|
||||
ICipherRepository cipherRepository,
|
||||
ISecurityTaskRepository securityTaskRepository)
|
||||
ISecurityTaskRepository securityTaskRepository,
|
||||
INotificationRepository notificationRepository,
|
||||
INotificationStatusRepository notificationStatusRepository)
|
||||
{
|
||||
var organization = await organizationRepository.CreateAsync(new Organization
|
||||
{
|
||||
@ -987,6 +992,14 @@ public class CipherRepositoryTests
|
||||
BillingEmail = ""
|
||||
});
|
||||
|
||||
var user = await userRepository.CreateAsync(new User
|
||||
{
|
||||
Name = "Test User",
|
||||
Email = $"test+{Guid.NewGuid()}@email.com",
|
||||
ApiKey = "TEST",
|
||||
SecurityStamp = "stamp",
|
||||
});
|
||||
|
||||
var cipher1 = new Cipher { Type = CipherType.Login, OrganizationId = organization.Id, Data = "", };
|
||||
await cipherRepository.CreateAsync(cipher1);
|
||||
|
||||
@ -1012,6 +1025,20 @@ public class CipherRepositoryTests
|
||||
};
|
||||
|
||||
await securityTaskRepository.CreateManyAsync(tasks);
|
||||
var notification = await notificationRepository.CreateAsync(new Notification
|
||||
{
|
||||
OrganizationId = organization.Id,
|
||||
UserId = user.Id,
|
||||
TaskId = tasks[1].Id,
|
||||
CreationDate = DateTime.UtcNow,
|
||||
RevisionDate = DateTime.UtcNow,
|
||||
});
|
||||
await notificationStatusRepository.CreateAsync(new NotificationStatus
|
||||
{
|
||||
NotificationId = notification.Id,
|
||||
UserId = user.Id,
|
||||
ReadDate = DateTime.UtcNow,
|
||||
});
|
||||
|
||||
// Delete cipher with pending security task
|
||||
await cipherRepository.DeleteAsync(cipher1);
|
||||
|
Reference in New Issue
Block a user