mirror of
https://github.com/bitwarden/server
synced 2025-12-18 09:13:19 +00:00
update tests. cleanup
This commit is contained in:
@@ -20,7 +20,7 @@ BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
EXEC [dbo].[Cipher_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
|
||||
@Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key, @ArchivedDate
|
||||
@Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key, @ArchivedDate, @Archives
|
||||
|
||||
DECLARE @UpdateCollectionsSuccess INT
|
||||
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
@DeletedDate DATETIME2(7),
|
||||
@Reprompt TINYINT,
|
||||
@Key VARCHAR(MAX) = NULL,
|
||||
@ArchivedDate DATETIME2(7) = NULL
|
||||
@ArchivedDate DATETIME2(7) = NULL,
|
||||
@Archives NVARCHAR(MAX) = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@@ -32,7 +33,8 @@ BEGIN
|
||||
[DeletedDate] = @DeletedDate,
|
||||
[Reprompt] = @Reprompt,
|
||||
[Key] = @Key,
|
||||
[ArchivedDate] = @ArchivedDate
|
||||
[ArchivedDate] = @ArchivedDate,
|
||||
[Archives] = @Archives
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
|
||||
@@ -46,4 +46,36 @@ public class ArchiveCiphersCommandTest
|
||||
await sutProvider.GetDependency<IPushNotificationService>().Received(pushNotificationsCalls)
|
||||
.PushSyncCiphersAsync(user.Id);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task ArchiveAsync_SetsArchivedDateOnReturnedCiphers(
|
||||
SutProvider<ArchiveCiphersCommand> sutProvider,
|
||||
CipherDetails cipher,
|
||||
User user)
|
||||
{
|
||||
// Arrange: make it archivable
|
||||
cipher.Edit = true;
|
||||
cipher.OrganizationId = null;
|
||||
cipher.ArchivedDate = null;
|
||||
|
||||
sutProvider.GetDependency<ICipherRepository>()
|
||||
.GetManyByUserIdAsync(user.Id)
|
||||
.Returns(new List<CipherDetails> { cipher });
|
||||
|
||||
var repoRevisionDate = DateTime.UtcNow;
|
||||
|
||||
sutProvider.GetDependency<ICipherRepository>()
|
||||
.ArchiveAsync(Arg.Any<IEnumerable<Guid>>(), user.Id)
|
||||
.Returns(repoRevisionDate);
|
||||
|
||||
// Act
|
||||
var result = await sutProvider.Sut.ArchiveManyAsync(new[] { cipher.Id }, user.Id);
|
||||
|
||||
// Assert
|
||||
var archivedCipher = Assert.Single(result);
|
||||
Assert.Equal(repoRevisionDate, archivedCipher.RevisionDate);
|
||||
Assert.Equal(repoRevisionDate, archivedCipher.ArchivedDate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,4 +46,35 @@ public class UnarchiveCiphersCommandTest
|
||||
await sutProvider.GetDependency<IPushNotificationService>().Received(pushNotificationsCalls)
|
||||
.PushSyncCiphersAsync(user.Id);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task UnarchiveAsync_ClearsArchivedDateOnReturnedCiphers(
|
||||
SutProvider<UnarchiveCiphersCommand> sutProvider,
|
||||
CipherDetails cipher,
|
||||
User user)
|
||||
{
|
||||
// Arrange: make it unarchivable
|
||||
cipher.Edit = true;
|
||||
cipher.OrganizationId = null;
|
||||
cipher.ArchivedDate = DateTime.UtcNow;
|
||||
|
||||
sutProvider.GetDependency<ICipherRepository>()
|
||||
.GetManyByUserIdAsync(user.Id)
|
||||
.Returns(new List<CipherDetails> { cipher });
|
||||
|
||||
var repoRevisionDate = DateTime.UtcNow.AddMinutes(1);
|
||||
|
||||
sutProvider.GetDependency<ICipherRepository>()
|
||||
.UnarchiveAsync(Arg.Any<IEnumerable<Guid>>(), user.Id)
|
||||
.Returns(repoRevisionDate);
|
||||
|
||||
// Act
|
||||
var result = await sutProvider.Sut.UnarchiveManyAsync(new[] { cipher.Id }, user.Id);
|
||||
|
||||
// Assert
|
||||
var unarchivedCipher = Assert.Single(result);
|
||||
Assert.Equal(repoRevisionDate, unarchivedCipher.RevisionDate);
|
||||
Assert.Null(unarchivedCipher.ArchivedDate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
EXEC [dbo].[Cipher_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
|
||||
@Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key, @ArchivedDate
|
||||
@Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key, @ArchivedDate, @Archives
|
||||
|
||||
DECLARE @UpdateCollectionsSuccess INT
|
||||
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
|
||||
|
||||
Reference in New Issue
Block a user