Skip to content

Commit dad7fa4

Browse files
committed
Adjust and add more pin migration tests
1 parent 7475427 commit dad7fa4

1 file changed

Lines changed: 118 additions & 2 deletions

File tree

RefreshTests.GameServer/Tests/Workers/PinMigrationTests.cs

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Refresh.Database.Models.Authentication;
22
using Refresh.Database.Models.Pins;
3+
using Refresh.Database.Models.Relations;
34
using Refresh.Database.Models.Users;
45
using Refresh.Database.Models.Workers;
56
using Refresh.Interfaces.Workers.Migrations;
@@ -46,7 +47,7 @@ public void WebsitePinMigrationDoesNotBreakPagination()
4647
CorrectWebsitePinProgressPlatformMigration job = new();
4748
context.Database.UpdateOrCreateJobState(typeof(CorrectWebsitePinProgressPlatformMigration).Name, new MigrationJobState()
4849
{
49-
Total = 100 // Since we already have to manually create the state
50+
Total = 50,
5051
}, WorkerClass.Refresh);
5152
context.Database.Refresh();
5253

@@ -68,6 +69,121 @@ public void WebsitePinMigrationDoesNotBreakPagination()
6869
Assert.That(jobState.Total, Is.EqualTo(50));
6970
Assert.That(jobState.Complete, Is.True);
7071

71-
Assert.That(context.Database.GetTotalPinProgresses(), Is.EqualTo(50));
72+
Assert.That(context.Database.GetTotalPinProgresses(), Is.EqualTo(50)); // Pins were deduplicated
73+
}
74+
75+
[Test]
76+
[TestCase(ServerPins.SignIntoWebsite)]
77+
[TestCase(ServerPins.HeartPlayerOnWebsite)]
78+
[TestCase(ServerPins.QueueLevelOnWebsite)]
79+
public void WebsitePinMigrationProperlyOverwritesPlatform(long pinId)
80+
{
81+
using TestContext context = this.GetServer();
82+
83+
GameUser user = context.CreateUser();
84+
context.Database.AddPinProgress(new()
85+
{
86+
PinId = pinId,
87+
Progress = 20,
88+
Publisher = user,
89+
FirstPublished = new(),
90+
LastUpdated = new(),
91+
IsBeta = false,
92+
Platform = TokenPlatform.RPCS3,
93+
}, true);
94+
95+
context.Database.AddPinProgress(new()
96+
{
97+
PinId = pinId,
98+
Progress = 30,
99+
Publisher = user,
100+
FirstPublished = new(),
101+
LastUpdated = new(),
102+
IsBeta = true,
103+
Platform = TokenPlatform.RPCS3,
104+
}, true);
105+
106+
Assert.That(context.Database.GetTotalPinProgresses(), Is.EqualTo(2));
107+
108+
// Prepare migration
109+
CorrectWebsitePinProgressPlatformMigration job = new();
110+
context.Database.UpdateOrCreateJobState(typeof(CorrectWebsitePinProgressPlatformMigration).Name, new MigrationJobState()
111+
{
112+
Total = 1
113+
}, WorkerClass.Refresh);
114+
context.Database.Refresh();
115+
116+
object? stateObject = context.Database.GetJobState(typeof(CorrectWebsitePinProgressPlatformMigration).Name, typeof(MigrationJobState), WorkerClass.Refresh);
117+
Assert.That(stateObject, Is.Not.Null);
118+
job.JobState = stateObject!;
119+
120+
// Migrate
121+
job.ExecuteJob(context.GetWorkContext());
122+
context.Database.Refresh();
123+
124+
List<PinProgressRelation> relations = context.Database.GetAllPinProgressesByUserAndId(user, pinId).ToList();
125+
Assert.That(relations.Count, Is.EqualTo(1));
126+
Assert.That(relations[0].Platform, Is.EqualTo(TokenPlatform.Website));
127+
Assert.That(relations[0].Progress, Is.EqualTo(30));
128+
}
129+
130+
[Test]
131+
[TestCase(ServerPins.SignIntoWebsite, ServerPins.CherryShooterLbp3ChallengeMedal)]
132+
[TestCase(ServerPins.HeartPlayerOnWebsite, ServerPins.TopFourthOfXCommunityLevelsWithOver50Scores)]
133+
[TestCase(ServerPins.QueueLevelOnWebsite, 420)]
134+
public void WebsitePinMigrationOnlyMigratesWebsitePins(long websitePinId, long otherPinId)
135+
{
136+
using TestContext context = this.GetServer();
137+
138+
GameUser user = context.CreateUser();
139+
context.Database.AddPinProgress(new()
140+
{
141+
PinId = websitePinId,
142+
Progress = 20,
143+
Publisher = user,
144+
FirstPublished = new(),
145+
LastUpdated = new(),
146+
IsBeta = false,
147+
Platform = TokenPlatform.RPCS3,
148+
}, true);
149+
150+
context.Database.AddPinProgress(new()
151+
{
152+
PinId = otherPinId,
153+
Progress = 30,
154+
Publisher = user,
155+
FirstPublished = new(),
156+
LastUpdated = new(),
157+
IsBeta = true,
158+
Platform = TokenPlatform.RPCS3,
159+
}, true);
160+
161+
Assert.That(context.Database.GetTotalPinProgresses(), Is.EqualTo(2));
162+
163+
// Prepare migration
164+
CorrectWebsitePinProgressPlatformMigration job = new();
165+
context.Database.UpdateOrCreateJobState(typeof(CorrectWebsitePinProgressPlatformMigration).Name, new MigrationJobState()
166+
{
167+
Total = 1
168+
}, WorkerClass.Refresh);
169+
context.Database.Refresh();
170+
171+
object? stateObject = context.Database.GetJobState(typeof(CorrectWebsitePinProgressPlatformMigration).Name, typeof(MigrationJobState), WorkerClass.Refresh);
172+
Assert.That(stateObject, Is.Not.Null);
173+
job.JobState = stateObject!;
174+
175+
// Migrate
176+
job.ExecuteJob(context.GetWorkContext());
177+
context.Database.Refresh();
178+
179+
List<PinProgressRelation> websitePins = context.Database.GetAllPinProgressesByUserAndId(user, websitePinId).ToList();
180+
Assert.That(websitePins.Count, Is.EqualTo(1));
181+
Assert.That(websitePins[0].Platform, Is.EqualTo(TokenPlatform.Website));
182+
Assert.That(websitePins[0].Progress, Is.EqualTo(20));
183+
184+
List<PinProgressRelation> otherPins = context.Database.GetAllPinProgressesByUserAndId(user, otherPinId).ToList();
185+
Assert.That(otherPins.Count, Is.EqualTo(1));
186+
Assert.That(otherPins[0].Platform, Is.EqualTo(TokenPlatform.RPCS3));
187+
Assert.That(otherPins[0].Progress, Is.EqualTo(30));
72188
}
73189
}

0 commit comments

Comments
 (0)