From 7ce2453ceb1445ff37a65f4e404677ee59ad06ef Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Sun, 23 Apr 2023 14:01:47 -0400 Subject: [PATCH] removed FollowingsSyncStatus --- .../BusinessUseCases/ProcessFollowUser.cs | 3 - .../BusinessUseCases/ProcessUnfollowUser.cs | 3 - .../Actions/RemoveTwitterAccountAction.cs | 3 - .../SubTasks/SaveProgressionTask.cs | 61 ----- .../DataAccessLayers/FollowersPostgresDal.cs | 22 +- .../Contracts/IFollowersDal.cs | 3 +- .../BirdsiteLive.DAL/Models/Follower.cs | 1 - .../FollowersPostgresDalTests.cs | 61 ++--- .../ProcessFollowUserTests.cs | 11 +- .../ProcessUnfollowUserTests.cs | 6 +- .../RemoveTwitterAccountActionTests.cs | 3 - .../SaveProgressionProcessorTests.cs | 227 ------------------ .../SubTasks/SendTweetsToInboxTaskTests.cs | 7 - .../SubTasks/SendTweetsToSharedInboxTests.cs | 21 -- 14 files changed, 30 insertions(+), 402 deletions(-) delete mode 100644 src/BirdsiteLive.Pipeline/Processors/SubTasks/SaveProgressionTask.cs delete mode 100644 src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SaveProgressionProcessorTests.cs diff --git a/src/BirdsiteLive.Domain/BusinessUseCases/ProcessFollowUser.cs b/src/BirdsiteLive.Domain/BusinessUseCases/ProcessFollowUser.cs index c6618d9..f8604ea 100644 --- a/src/BirdsiteLive.Domain/BusinessUseCases/ProcessFollowUser.cs +++ b/src/BirdsiteLive.Domain/BusinessUseCases/ProcessFollowUser.cs @@ -42,9 +42,6 @@ namespace BirdsiteLive.Domain.BusinessUseCases var twitterUserId = twitterUser.Id; if(!follower.Followings.Contains(twitterUserId)) follower.Followings.Add(twitterUserId); - - if(!follower.FollowingsSyncStatus.ContainsKey(twitterUserId)) - follower.FollowingsSyncStatus.Add(twitterUserId, -1); // Save Follower await _followerDal.UpdateFollowerAsync(follower); diff --git a/src/BirdsiteLive.Domain/BusinessUseCases/ProcessUnfollowUser.cs b/src/BirdsiteLive.Domain/BusinessUseCases/ProcessUnfollowUser.cs index a8a53b4..652e2be 100644 --- a/src/BirdsiteLive.Domain/BusinessUseCases/ProcessUnfollowUser.cs +++ b/src/BirdsiteLive.Domain/BusinessUseCases/ProcessUnfollowUser.cs @@ -36,9 +36,6 @@ namespace BirdsiteLive.Domain.BusinessUseCases if (follower.Followings.Contains(twitterUserId)) follower.Followings.Remove(twitterUserId); - if (follower.FollowingsSyncStatus.ContainsKey(twitterUserId)) - follower.FollowingsSyncStatus.Remove(twitterUserId); - // Save or delete Follower if (follower.Followings.Any()) await _followerDal.UpdateFollowerAsync(follower); diff --git a/src/BirdsiteLive.Moderation/Actions/RemoveTwitterAccountAction.cs b/src/BirdsiteLive.Moderation/Actions/RemoveTwitterAccountAction.cs index 714cca6..629750d 100644 --- a/src/BirdsiteLive.Moderation/Actions/RemoveTwitterAccountAction.cs +++ b/src/BirdsiteLive.Moderation/Actions/RemoveTwitterAccountAction.cs @@ -41,9 +41,6 @@ namespace BirdsiteLive.Moderation.Actions if (follower.Followings.Contains(twitterUserId)) follower.Followings.Remove(twitterUserId); - if (follower.FollowingsSyncStatus.ContainsKey(twitterUserId)) - follower.FollowingsSyncStatus.Remove(twitterUserId); - if (follower.Followings.Any()) await _followersDal.UpdateFollowerAsync(follower); else diff --git a/src/BirdsiteLive.Pipeline/Processors/SubTasks/SaveProgressionTask.cs b/src/BirdsiteLive.Pipeline/Processors/SubTasks/SaveProgressionTask.cs deleted file mode 100644 index 583ea93..0000000 --- a/src/BirdsiteLive.Pipeline/Processors/SubTasks/SaveProgressionTask.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using BirdsiteLive.DAL.Contracts; -using BirdsiteLive.Pipeline.Contracts; -using BirdsiteLive.Pipeline.Models; -using Microsoft.Extensions.Logging; - -namespace BirdsiteLive.Pipeline.Processors.SubTasks -{ - public class SaveProgressionTask : ISaveProgressionTask - { - private readonly ITwitterUserDal _twitterUserDal; - private readonly ILogger _logger; - - #region Ctor - public SaveProgressionTask(ITwitterUserDal twitterUserDal, ILogger logger) - { - _twitterUserDal = twitterUserDal; - _logger = logger; - } - #endregion - - public async Task ProcessAsync(UserWithDataToSync userWithTweetsToSync, CancellationToken ct) - { - try - { - if (userWithTweetsToSync.Tweets.Length == 0) - { - _logger.LogWarning("No tweets synchronized"); - return; - } - if(userWithTweetsToSync.Followers.Length == 0) - { - _logger.LogWarning("No Followers found for {User}", userWithTweetsToSync.User.Acct); - return; - } - - var userId = userWithTweetsToSync.User.Id; - var followingSyncStatuses = userWithTweetsToSync.Followers.Select(x => x.FollowingsSyncStatus[userId]).ToList(); - - if (followingSyncStatuses.Count == 0) - { - _logger.LogWarning("No Followers sync found for {User}, Id: {UserId}", userWithTweetsToSync.User.Acct, userId); - return; - } - - var lastPostedTweet = userWithTweetsToSync.Tweets.Select(x => x.Id).Max(); - var minimumSync = followingSyncStatuses.Min(); - var now = DateTime.UtcNow; - await _twitterUserDal.UpdateTwitterUserAsync(userId, lastPostedTweet, minimumSync, userWithTweetsToSync.User.FetchingErrorCount, now); - } - catch (Exception e) - { - _logger.LogError(e, "SaveProgressionProcessor.ProcessAsync() Exception"); - throw; - } - } - } -} \ No newline at end of file diff --git a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs index 9bb99db..8710366 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/FollowersPostgresDal.cs @@ -21,12 +21,9 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers } #endregion - public async Task CreateFollowerAsync(string acct, string host, string inboxRoute, string sharedInboxRoute, string actorId, int[] followings = null, Dictionary followingSyncStatus = null) + public async Task CreateFollowerAsync(string acct, string host, string inboxRoute, string sharedInboxRoute, string actorId, int[] followings = null) { if(followings == null) followings = new int[0]; - if(followingSyncStatus == null) followingSyncStatus = new Dictionary(); - - var serializedDic = JsonSerializer.Serialize(followingSyncStatus); acct = acct.ToLowerInvariant(); host = host.ToLowerInvariant(); @@ -34,8 +31,8 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers using (var dbConnection = Connection) { await dbConnection.ExecuteAsync( - $"INSERT INTO {_settings.FollowersTableName} (acct,host,inboxRoute,sharedInboxRoute,followings,followingsSyncStatus,actorId) VALUES(@acct,@host,@inboxRoute,@sharedInboxRoute,@followings,CAST(@followingsSyncStatus as json),@actorId)", - new { acct, host, inboxRoute, sharedInboxRoute, followings, followingsSyncStatus = serializedDic, actorId }); + $"INSERT INTO {_settings.FollowersTableName} (acct,host,inboxRoute,sharedInboxRoute,followings,actorId) VALUES(@acct,@host,@inboxRoute,@sharedInboxRoute,@followings,@actorId)", + new { acct, host, inboxRoute, sharedInboxRoute, followings, actorId }); } } @@ -78,13 +75,10 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers if (!await reader.ReadAsync()) return null; - string syncStatusString = reader["followingsSyncStatus"] as string; - var syncStatus = System.Text.Json.JsonSerializer.Deserialize>(syncStatusString); return new Follower { Id = reader["id"] as int? ?? default, Followings = (reader["followings"] as int[] ?? new int[0]).ToList(), - FollowingsSyncStatus = syncStatus, ActorId = reader["actorId"] as string, Acct = reader["acct"] as string, Host = reader["host"] as string, @@ -112,12 +106,10 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers while (await reader.ReadAsync()) { string syncStatusString = reader["followingsSyncStatus"] as string; - var syncStatus = System.Text.Json.JsonSerializer.Deserialize>(syncStatusString); followers.Add(new Follower { Id = reader["id"] as int? ?? default, Followings = (reader["followings"] as int[] ?? new int[0]).ToList(), - FollowingsSyncStatus = syncStatus, ActorId = reader["actorId"] as string, Acct = reader["acct"] as string, Host = reader["host"] as string, @@ -147,14 +139,12 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers if (follower == default) throw new ArgumentException("follower"); if (follower.Id == default) throw new ArgumentException("id"); - var serializedDic = System.Text.Json.JsonSerializer.Serialize(follower.FollowingsSyncStatus); - var query = $"UPDATE {_settings.FollowersTableName} SET followings = $1, followingsSyncStatus = CAST($2 as json), postingErrorCount = $3 WHERE id = $4"; + var query = $"UPDATE {_settings.FollowersTableName} SET followings = $1, postingErrorCount = $2 WHERE id = $3"; await using var connection = DataSource.CreateConnection(); await connection.OpenAsync(); await using var command = new NpgsqlCommand(query, connection) { Parameters = { new() { Value = follower.Followings}, - new() { Value = serializedDic}, new() { Value = follower.PostingErrorCount}, new() { Value = follower.Id} } @@ -204,7 +194,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers ActorId = follower.ActorId, SharedInboxRoute = follower.SharedInboxRoute, Followings = follower.Followings.ToList(), - FollowingsSyncStatus = JsonSerializer.Deserialize>(follower.FollowingsSyncStatus), PostingErrorCount = follower.PostingErrorCount }; } @@ -212,10 +201,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers internal class SerializedFollower { public int Id { get; set; } - public int[] Followings { get; set; } - public string FollowingsSyncStatus { get; set; } - public string Acct { get; set; } public string Host { get; set; } public string InboxRoute { get; set; } diff --git a/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs index fe87b28..de191ac 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/IFollowersDal.cs @@ -7,8 +7,7 @@ namespace BirdsiteLive.DAL.Contracts public interface IFollowersDal { Task GetFollowerAsync(string acct, string host); - Task CreateFollowerAsync(string acct, string host, string inboxRoute, string sharedInboxRoute, string actorId, int[] followings = null, - Dictionary followingSyncStatus = null); + Task CreateFollowerAsync(string acct, string host, string inboxRoute, string sharedInboxRoute, string actorId, int[] followings = null); Task GetFollowersAsync(int followedUserId); Task GetAllFollowersAsync(); Task UpdateFollowerAsync(Follower follower); diff --git a/src/DataAccessLayers/BirdsiteLive.DAL/Models/Follower.cs b/src/DataAccessLayers/BirdsiteLive.DAL/Models/Follower.cs index 357e32e..9ac5bab 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL/Models/Follower.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL/Models/Follower.cs @@ -7,7 +7,6 @@ namespace BirdsiteLive.DAL.Models public int Id { get; set; } public List Followings { get; set; } - public Dictionary FollowingsSyncStatus { get; set; } public string ActorId { get; set; } public string Acct { get; set; } diff --git a/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/FollowersPostgresDalTests.cs b/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/FollowersPostgresDalTests.cs index 3927f13..cd85e71 100644 --- a/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/FollowersPostgresDalTests.cs +++ b/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/FollowersPostgresDalTests.cs @@ -44,7 +44,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var actorId = $"https://{host}/{acct}"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); var result = await dal.GetFollowerAsync(acct, host); @@ -57,9 +57,6 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers Assert.AreEqual(0, result.PostingErrorCount); Assert.AreEqual(following.Length, result.Followings.Count); Assert.AreEqual(following[0], result.Followings[0]); - Assert.AreEqual(followingSync.Count, result.FollowingsSyncStatus.Count); - Assert.AreEqual(followingSync.First().Key, result.FollowingsSyncStatus.First().Key); - Assert.AreEqual(followingSync.First().Value, result.FollowingsSyncStatus.First().Value); } [TestMethod] @@ -72,7 +69,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var actorId = $"https://{host}/{acct}"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, null, null); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, null); var result = await dal.GetFollowerAsync(acct, host); @@ -83,7 +80,6 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers Assert.AreEqual(inboxRoute, result.InboxRoute); Assert.AreEqual(sharedInboxRoute, result.SharedInboxRoute); Assert.AreEqual(0, result.Followings.Count); - Assert.AreEqual(0, result.FollowingsSyncStatus.Count); Assert.AreEqual(0, result.PostingErrorCount); } @@ -112,7 +108,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var actorId = $"https://{host}/{acct}"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); var result = await dal.GetFollowerAsync(acct, host); @@ -124,9 +120,6 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers Assert.AreEqual(sharedInboxRoute, result.SharedInboxRoute); Assert.AreEqual(following.Length, result.Followings.Count); Assert.AreEqual(following[0], result.Followings[0]); - Assert.AreEqual(followingSync.Count, result.FollowingsSyncStatus.Count); - Assert.AreEqual(followingSync.First().Key, result.FollowingsSyncStatus.First().Key); - Assert.AreEqual(followingSync.First().Value, result.FollowingsSyncStatus.First().Value); Assert.AreEqual(0, result.PostingErrorCount); } @@ -143,7 +136,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var inboxRoute = "/myhandle1/inbox"; var sharedInboxRoute = "/inbox"; var actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); //User 2 acct = "myhandle2"; @@ -152,7 +145,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers inboxRoute = "/myhandle2/inbox"; sharedInboxRoute = "/inbox2"; actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); //User 2 acct = "myhandle3"; @@ -161,7 +154,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers inboxRoute = "/myhandle3/inbox"; sharedInboxRoute = "/inbox3"; actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); var result = await dal.GetFollowersAsync(2); Assert.AreEqual(2, result.Length); @@ -186,7 +179,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var inboxRoute = "/myhandle1/inbox"; var sharedInboxRoute = "/inbox"; var actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); //User 2 acct = "myhandle2"; @@ -195,7 +188,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers inboxRoute = "/myhandle2/inbox"; sharedInboxRoute = "/inbox2"; actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); //User 2 acct = "myhandle3"; @@ -204,7 +197,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers inboxRoute = "/myhandle3/inbox"; sharedInboxRoute = "/inbox3"; actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); var result = await dal.GetAllFollowersAsync(); Assert.AreEqual(3, result.Length); @@ -226,7 +219,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var inboxRoute = "/myhandle1/inbox"; var sharedInboxRoute = "/inbox"; var actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); //User 2 acct = "myhandle2"; @@ -235,7 +228,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers inboxRoute = "/myhandle2/inbox"; sharedInboxRoute = "/inbox2"; actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); //User 3 acct = "myhandle3"; @@ -244,7 +237,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers inboxRoute = "/myhandle3/inbox"; sharedInboxRoute = "/inbox3"; actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); result = await dal.GetFollowersCountAsync(); Assert.AreEqual(3, result); @@ -266,7 +259,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var inboxRoute = "/myhandle1/inbox"; var sharedInboxRoute = "/inbox"; var actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); //User 2 acct = "myhandle2"; @@ -275,7 +268,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers inboxRoute = "/myhandle2/inbox"; sharedInboxRoute = "/inbox2"; actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); var follower = await dal.GetFollowerAsync(acct, host); follower.PostingErrorCount = 1; @@ -288,7 +281,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers inboxRoute = "/myhandle3/inbox"; sharedInboxRoute = "/inbox3"; actorId = $"https://{host}/{acct}"; - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); follower = await dal.GetFollowerAsync(acct, host); follower.PostingErrorCount = 50; @@ -315,7 +308,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var actorId = $"https://{host}/{acct}"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); var result = await dal.GetFollowerAsync(acct, host); var updatedFollowing = new List { 12, 19, 23, 24 }; @@ -326,7 +319,6 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers {24, 173L} }; result.Followings = updatedFollowing.ToList(); - result.FollowingsSyncStatus = updatedFollowingSync; result.PostingErrorCount = 10; await dal.UpdateFollowerAsync(result); @@ -334,9 +326,6 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers Assert.AreEqual(updatedFollowing.Count, result.Followings.Count); Assert.AreEqual(updatedFollowing[0], result.Followings[0]); - Assert.AreEqual(updatedFollowingSync.Count, result.FollowingsSyncStatus.Count); - Assert.AreEqual(updatedFollowingSync.First().Key, result.FollowingsSyncStatus.First().Key); - Assert.AreEqual(updatedFollowingSync.First().Value, result.FollowingsSyncStatus.First().Value); Assert.AreEqual(10, result.PostingErrorCount); } @@ -357,7 +346,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var actorId = $"https://{host}/{acct}"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); var result = await dal.GetFollowerAsync(acct, host); var updatedFollowing = new List { 12, 19, 23, 24 }; @@ -368,7 +357,6 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers {24, 173L} }; result.Followings = updatedFollowing.ToList(); - result.FollowingsSyncStatus = updatedFollowingSync; result.PostingErrorCount = 32768; await dal.UpdateFollowerAsync(result); @@ -376,9 +364,6 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers Assert.AreEqual(updatedFollowing.Count, result.Followings.Count); Assert.AreEqual(updatedFollowing[0], result.Followings[0]); - Assert.AreEqual(updatedFollowingSync.Count, result.FollowingsSyncStatus.Count); - Assert.AreEqual(updatedFollowingSync.First().Key, result.FollowingsSyncStatus.First().Key); - Assert.AreEqual(updatedFollowingSync.First().Value, result.FollowingsSyncStatus.First().Value); Assert.AreEqual(32768, result.PostingErrorCount); } @@ -399,7 +384,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var actorId = $"https://{host}/{acct}"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); var result = await dal.GetFollowerAsync(acct, host); var updatedFollowing = new[] { 12, 19 }; @@ -409,7 +394,6 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers {19, 171L} }; result.Followings = updatedFollowing.ToList(); - result.FollowingsSyncStatus = updatedFollowingSync; result.PostingErrorCount = 5; await dal.UpdateFollowerAsync(result); @@ -417,9 +401,6 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers Assert.AreEqual(updatedFollowing.Length, result.Followings.Count); Assert.AreEqual(updatedFollowing[0], result.Followings[0]); - Assert.AreEqual(updatedFollowingSync.Count, result.FollowingsSyncStatus.Count); - Assert.AreEqual(updatedFollowingSync.First().Key, result.FollowingsSyncStatus.First().Key); - Assert.AreEqual(updatedFollowingSync.First().Value, result.FollowingsSyncStatus.First().Value); Assert.AreEqual(5, result.PostingErrorCount); } @@ -440,7 +421,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var actorId = $"https://{host}/{acct}"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); var result = await dal.GetFollowerAsync(acct, host); Assert.AreEqual(0, result.PostingErrorCount); @@ -495,7 +476,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var actorId = $"https://{host}/{acct}"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); var result = await dal.GetFollowerAsync(acct, host); Assert.IsNotNull(result); @@ -522,7 +503,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var actorId = $"https://{host}/{acct}"; var dal = new FollowersPostgresDal(_settings); - await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync); + await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following); var result = await dal.GetFollowerAsync(acct, host); Assert.IsNotNull(result); diff --git a/src/Tests/BirdsiteLive.Domain.Tests/BusinessUseCases/ProcessFollowUserTests.cs b/src/Tests/BirdsiteLive.Domain.Tests/BusinessUseCases/ProcessFollowUserTests.cs index 17c4fec..1b22956 100644 --- a/src/Tests/BirdsiteLive.Domain.Tests/BusinessUseCases/ProcessFollowUserTests.cs +++ b/src/Tests/BirdsiteLive.Domain.Tests/BusinessUseCases/ProcessFollowUserTests.cs @@ -30,7 +30,6 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases SharedInboxRoute = followerInbox, InboxRoute = inbox, Followings = new List(), - FollowingsSyncStatus = new Dictionary() }; var twitterUser = new SyncTwitterUser @@ -56,14 +55,12 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases It.Is(y => y == followerInbox), It.Is(y => y == inbox), It.Is(y => y == actorId), - null, - null)) + null )) .Returns(Task.CompletedTask); followersDalMock .Setup(x => x.UpdateFollowerAsync( - It.Is(y => y.Followings.Contains(twitterUser.Id) - && y.FollowingsSyncStatus[twitterUser.Id] == -1) + It.Is(y => y.Followings.Contains(twitterUser.Id)) )) .Returns(Task.CompletedTask); @@ -108,7 +105,6 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases SharedInboxRoute = followerInbox, InboxRoute = inbox, Followings = new List(), - FollowingsSyncStatus = new Dictionary() }; var twitterUser = new SyncTwitterUser @@ -128,8 +124,7 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases followersDalMock .Setup(x => x.UpdateFollowerAsync( - It.Is(y => y.Followings.Contains(twitterUser.Id) - && y.FollowingsSyncStatus[twitterUser.Id] == -1) + It.Is(y => y.Followings.Contains(twitterUser.Id) ) )) .Returns(Task.CompletedTask); diff --git a/src/Tests/BirdsiteLive.Domain.Tests/BusinessUseCases/ProcessUnfollowUserTests.cs b/src/Tests/BirdsiteLive.Domain.Tests/BusinessUseCases/ProcessUnfollowUserTests.cs index 9bd83e3..84d644b 100644 --- a/src/Tests/BirdsiteLive.Domain.Tests/BusinessUseCases/ProcessUnfollowUserTests.cs +++ b/src/Tests/BirdsiteLive.Domain.Tests/BusinessUseCases/ProcessUnfollowUserTests.cs @@ -52,7 +52,6 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases Acct = username, Host = domain, Followings = new List(), - FollowingsSyncStatus = new Dictionary() }; #endregion @@ -91,7 +90,6 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases Acct = username, Host = domain, Followings = new List { 2, 3 }, - FollowingsSyncStatus = new Dictionary { { 2, 460 }, { 3, 563} } }; var twitterUser = new SyncTwitterUser @@ -117,8 +115,7 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases followersDalMock .Setup(x => x.UpdateFollowerAsync( - It.Is(y => !y.Followings.Contains(twitterUser.Id) - && !y.FollowingsSyncStatus.ContainsKey(twitterUser.Id)) + It.Is(y => !y.Followings.Contains(twitterUser.Id) ) )) .Returns(Task.CompletedTask); @@ -155,7 +152,6 @@ namespace BirdsiteLive.Domain.Tests.BusinessUseCases Acct = username, Host = domain, Followings = new List { 2 }, - FollowingsSyncStatus = new Dictionary { { 2, 460 } } }; var twitterUser = new SyncTwitterUser diff --git a/src/Tests/BirdsiteLive.Moderation.Tests/Actions/RemoveTwitterAccountActionTests.cs b/src/Tests/BirdsiteLive.Moderation.Tests/Actions/RemoveTwitterAccountActionTests.cs index c0f5920..67c7e94 100644 --- a/src/Tests/BirdsiteLive.Moderation.Tests/Actions/RemoveTwitterAccountActionTests.cs +++ b/src/Tests/BirdsiteLive.Moderation.Tests/Actions/RemoveTwitterAccountActionTests.cs @@ -27,7 +27,6 @@ namespace BirdsiteLive.Moderation.Tests.Actions { Id = 48, Followings = new List{ 24 }, - FollowingsSyncStatus = new Dictionary { { 24, 1024 } } } }; #endregion @@ -84,7 +83,6 @@ namespace BirdsiteLive.Moderation.Tests.Actions { Id = 48, Followings = new List{ 24, 36 }, - FollowingsSyncStatus = new Dictionary { { 24, 1024 }, { 36, 24 } } } }; #endregion @@ -100,7 +98,6 @@ namespace BirdsiteLive.Moderation.Tests.Actions .Setup(x => x.UpdateFollowerAsync( It.Is(y => y.Id == 48 && y.Followings.Count == 1 - && y.FollowingsSyncStatus.Count == 1 ))) .Returns(Task.CompletedTask); diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SaveProgressionProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SaveProgressionProcessorTests.cs deleted file mode 100644 index 3f8b06a..0000000 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SaveProgressionProcessorTests.cs +++ /dev/null @@ -1,227 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using BirdsiteLive.DAL.Contracts; -using BirdsiteLive.DAL.Models; -using BirdsiteLive.Pipeline.Models; -using BirdsiteLive.Pipeline.Processors.SubTasks; -using BirdsiteLive.Twitter.Models; -using Castle.DynamicProxy.Contributors; -using Microsoft.Extensions.Logging; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace BirdsiteLive.Pipeline.Tests.Processors -{ - [TestClass] - public class SaveProgressionProcessorTests - { - [TestMethod] - public async Task ProcessAsync_Test() - { - #region Stubs - var user = new SyncTwitterUser - { - Id = 1 - }; - var tweet1 = new ExtractedTweet - { - Id = 36 - }; - var tweet2 = new ExtractedTweet - { - Id = 37 - }; - var follower1 = new Follower - { - FollowingsSyncStatus = new Dictionary - { - {1, 37} - } - }; - - var usersWithTweets = new UserWithDataToSync - { - Tweets = new [] - { - tweet1, - tweet2 - }, - Followers = new [] - { - follower1 - }, - User = user - }; - - var loggerMock = new Mock>(); - #endregion - - #region Mocks - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.UpdateTwitterUserAsync( - It.Is(y => y == user.Id), - It.Is(y => y == tweet2.Id), - It.Is(y => y == tweet2.Id), - It.Is(y => y == 0), - It.IsAny() - )) - .Returns(Task.CompletedTask); - #endregion - - var processor = new SaveProgressionTask(twitterUserDalMock.Object, loggerMock.Object); - await processor.ProcessAsync(usersWithTweets, CancellationToken.None); - - #region Validations - twitterUserDalMock.VerifyAll(); - loggerMock.VerifyAll(); - #endregion - } - - [TestMethod] - public async Task ProcessAsync_PartiallySynchronized_Test() - { - #region Stubs - var user = new SyncTwitterUser - { - Id = 1 - }; - var tweet1 = new ExtractedTweet - { - Id = 36 - }; - var tweet2 = new ExtractedTweet - { - Id = 37 - }; - var tweet3 = new ExtractedTweet - { - Id = 38 - }; - var follower1 = new Follower - { - FollowingsSyncStatus = new Dictionary - { - {1, 37} - } - }; - - var usersWithTweets = new UserWithDataToSync - { - Tweets = new[] - { - tweet1, - tweet2, - tweet3 - }, - Followers = new[] - { - follower1 - }, - User = user - }; - #endregion - - #region Mocks - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.UpdateTwitterUserAsync( - It.Is(y => y == user.Id), - It.Is(y => y == tweet3.Id), - It.Is(y => y == tweet2.Id), - It.Is(y => y == 0), - It.IsAny() - )) - .Returns(Task.CompletedTask); - - var loggerMock = new Mock>(); - #endregion - - var processor = new SaveProgressionTask(twitterUserDalMock.Object, loggerMock.Object); - await processor.ProcessAsync(usersWithTweets, CancellationToken.None); - - #region Validations - twitterUserDalMock.VerifyAll(); - loggerMock.VerifyAll(); - #endregion - } - - [TestMethod] - public async Task ProcessAsync_PartiallySynchronized_MultiUsers_Test() - { - #region Stubs - var user = new SyncTwitterUser - { - Id = 1 - }; - var tweet1 = new ExtractedTweet - { - Id = 36 - }; - var tweet2 = new ExtractedTweet - { - Id = 37 - }; - var tweet3 = new ExtractedTweet - { - Id = 38 - }; - var follower1 = new Follower - { - FollowingsSyncStatus = new Dictionary - { - {1, 37} - } - }; - var follower2 = new Follower - { - FollowingsSyncStatus = new Dictionary - { - {1, 38} - } - }; - - var usersWithTweets = new UserWithDataToSync - { - Tweets = new[] - { - tweet1, - tweet2, - tweet3 - }, - Followers = new[] - { - follower1, - follower2 - }, - User = user - }; - #endregion - - #region Mocks - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.UpdateTwitterUserAsync( - It.Is(y => y == user.Id), - It.Is(y => y == tweet3.Id), - It.Is(y => y == tweet2.Id), - It.Is(y => y == 0), - It.IsAny() - )) - .Returns(Task.CompletedTask); - - var loggerMock = new Mock>(); - #endregion - - var processor = new SaveProgressionTask(twitterUserDalMock.Object, loggerMock.Object); - await processor.ProcessAsync(usersWithTweets, CancellationToken.None); - - #region Validations - twitterUserDalMock.VerifyAll(); - loggerMock.VerifyAll(); - #endregion - } - } -} \ No newline at end of file diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToInboxTaskTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToInboxTaskTests.cs index da1cfb7..a7013c1 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToInboxTaskTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToInboxTaskTests.cs @@ -57,7 +57,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, InboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 9 } } }; var settings = new InstanceSettings @@ -139,7 +138,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, InboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 9 } } }; var settings = new InstanceSettings { }; @@ -218,7 +216,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, InboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 9 } } }; var settings = new InstanceSettings @@ -301,7 +298,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, InboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 9 } } }; var settings = new InstanceSettings @@ -375,7 +371,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, InboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 10 } } }; var settings = new InstanceSettings @@ -456,7 +451,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, InboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 10 } } }; var settings = new InstanceSettings @@ -560,7 +554,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, InboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 9 } } }; var settings = new InstanceSettings diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToSharedInboxTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToSharedInboxTests.cs index 4846de1..db99872 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToSharedInboxTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToSharedInboxTests.cs @@ -61,21 +61,18 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 9 } } }, new Follower { Id = 2, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 8 } } }, new Follower { Id = 3, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 7 } } } }; @@ -161,21 +158,18 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 9 } } }, new Follower { Id = 2, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 8 } } }, new Follower { Id = 3, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 7 } } } }; @@ -262,21 +256,18 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 9 } } }, new Follower { Id = 2, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 8 } } }, new Follower { Id = 3, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 7 } } } }; @@ -350,21 +341,18 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary {{twitterUserId, 10}} }, new Follower { Id = 2, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary {{twitterUserId, 8}} }, new Follower { Id = 3, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary {{twitterUserId, 7}} } }; @@ -447,21 +435,18 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary {{twitterUserId, 10}} }, new Follower { Id = 2, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary {{twitterUserId, 8}} }, new Follower { Id = 3, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary {{twitterUserId, 7}} } }; @@ -568,21 +553,18 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 9 } } }, new Follower { Id = 2, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 8 } } }, new Follower { Id = 3, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 7 } } } }; @@ -648,21 +630,18 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks Id = 1, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 9 } } }, new Follower { Id = 2, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 8 } } }, new Follower { Id = 3, Host = host, SharedInboxRoute = inbox, - FollowingsSyncStatus = new Dictionary { { twitterUserId, 7 } } } };