Skip to content

Commit

Permalink
set LastSync in failing user retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasConstant committed Nov 20, 2021
1 parent 3a8a519 commit 5ef8af4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using BirdsiteLive.Common.Settings;
Expand Down Expand Up @@ -57,6 +58,7 @@ private async Task AnalyseFailingUserAsync(SyncTwitterUser user)
{
var dbUser = await _twitterUserDal.GetTwitterUserAsync(user.Acct);
dbUser.FetchingErrorCount++;
dbUser.LastSync = DateTime.UtcNow;

if (dbUser.FetchingErrorCount > _instanceSettings.FailingTwitterUserCleanUpThreshold)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,64 @@ public async Task ProcessAsync_Protected_Test()
removeTwitterAccountActionMock.VerifyAll();
#endregion
}

[TestMethod]
public async Task ProcessAsync_Unfound_NotInit_Test()
{
#region Stubs
var userId1 = 1;
var acct1 = "user1";

var users = new List<SyncTwitterUser>
{
new SyncTwitterUser
{
Id = userId1,
Acct = acct1,
LastSync = default,
LastTweetPostedId = -1,
LastTweetSynchronizedForAllFollowersId = -1
}
};

var settings = new InstanceSettings
{
FailingTwitterUserCleanUpThreshold = 300
};
#endregion

#region Mocks
var twitterUserServiceMock = new Mock<ICachedTwitterUserService>(MockBehavior.Strict);
twitterUserServiceMock
.Setup(x => x.GetUser(It.Is<string>(y => y == acct1)))
.Returns((TwitterUser)null);

twitterUserServiceMock
.Setup(x => x.PurgeUser(It.Is<string>(y => y == acct1)));

var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
twitterUserDalMock
.Setup(x => x.GetTwitterUserAsync(It.Is<string>(y => y == acct1)))
.ReturnsAsync(users.First());

twitterUserDalMock
.Setup(x => x.UpdateTwitterUserAsync(
It.Is<SyncTwitterUser>(y => y.Id == userId1 && y.FetchingErrorCount == 1 && y.LastSync != default)))
.Returns(Task.CompletedTask);

var removeTwitterAccountActionMock = new Mock<IRemoveTwitterAccountAction>(MockBehavior.Strict);
#endregion

var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings);
var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None);

#region Validations
Assert.AreEqual(0, result.Length);

twitterUserServiceMock.VerifyAll();
twitterUserDalMock.VerifyAll();
removeTwitterAccountActionMock.VerifyAll();
#endregion
}
}
}

0 comments on commit 5ef8af4

Please sign in to comment.